All Projects → itfinally → mybatis-helper

itfinally / mybatis-helper

Licence: MIT license
Mybatis plugins package

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to mybatis-helper

Mybatiscodehelper Pro
brucege.com
Stars: ✭ 1,565 (+11938.46%)
Mutual labels:  mybatis, mybatis-plugin
mybatis-typehandlers-postgis
MyBatis Type Handlers for PostGIS
Stars: ✭ 58 (+346.15%)
Mutual labels:  mybatis, mybatis3
Mapper
Mybatis Common Mapper - Easy to use
Stars: ✭ 6,680 (+51284.62%)
Mutual labels:  mybatis, mybatis-plugin
Mybatis Pagehelper
Mybatis通用分页插件
Stars: ✭ 10,844 (+83315.38%)
Mutual labels:  mybatis, mybatis-plugin
sqlt
SqlT golang实现的类似MyBaits的Sql 工具
Stars: ✭ 28 (+115.38%)
Mutual labels:  mybatis, mybatis3
anyangdp-frame
基于mybatis,springboot,tk.mybatis等框架二次开发,实现crud,controller,service,dao。
Stars: ✭ 16 (+23.08%)
Mutual labels:  mybatis, mybatis3
lightbatis
Lightbatis 增强 MyBatis 版Java 数据库持久层,更简洁并易用
Stars: ✭ 52 (+300%)
Mutual labels:  mybatis, mybatis3
mybatis-mapper
generate SQL statements from the MyBatis3 Mapper XML file in Node.js
Stars: ✭ 64 (+392.31%)
Mutual labels:  mybatis, mybatis3
RuoYi-fast
🎉 (RuoYi)官方仓库 基于SpringBoot的权限管理系统 易读易懂、界面简洁美观。 核心技术采用Spring、MyBatis、Shiro没有任何其它重度依赖。直接运行即可用
Stars: ✭ 117 (+800%)
Mutual labels:  mybatis
vm-engine
vm-engine为“微视频”网站的后端,java语言开发。涉及技术包括,springboot,springcloud,mybaties,docker,websocket,rabbitmq,redis等。
Stars: ✭ 57 (+338.46%)
Mutual labels:  mybatis
taotao-cloud-project
微服务开发脚手架,包括大数据模块、微服务模块、前端模块。基于Spring Cloud Alibaba的微服务架构。提供技术框架的基础能力的封装,减少开发工作,只关注业务,包含了工作以来的工作总结和技术沉淀
Stars: ✭ 76 (+484.62%)
Mutual labels:  mybatis
mybatis-plus-plugin
idea plugin
Stars: ✭ 115 (+784.62%)
Mutual labels:  mybatis
mybatis-generator
MyBatis code generator
Stars: ✭ 25 (+92.31%)
Mutual labels:  mybatis
badger
轻量级单表操作dao框架,支持分库分表
Stars: ✭ 13 (+0%)
Mutual labels:  mybatis
sinosteel
Spring Boot + React/Node.js based framework for web application development
Stars: ✭ 32 (+146.15%)
Mutual labels:  mybatis
java-toolkit
【Released】🛠Java常用的插件API整理以及基于JDK的一些方法封装库,能在不依赖大型框架下快速进行开发(亦可快速用于测试或者脚本类代码编写 - 含数据库相关)。
Stars: ✭ 13 (+0%)
Mutual labels:  mybatis
mybatis-kotlin-examples
Examples for Using MyBatis with Kotlin
Stars: ✭ 37 (+184.62%)
Mutual labels:  mybatis
shik
shik项目基于springcloud微服务搭建的分布式项目。搭建了shik-config云公共配置,通过shik-RA服务注册发现各个模块,通过shik-zuul路由转发与统一接口。并整合了包括mybatis,jpa,jedis,quartz,freemarker和layui等多个模块,支持spring-session二级域名共享session,使用了RESTful方式提供api接口
Stars: ✭ 89 (+584.62%)
Mutual labels:  mybatis
kite-mybatis-builder
web 形式的mybatis 生成器
Stars: ✭ 58 (+346.15%)
Mutual labels:  mybatis
itstack-naive-chat-server
💞 《服务端》| 服务端同样使用Netty4.x作为socket的通信框架,同时在服务端使用Layui作为管理后台的页面,并且我们的服务端采用偏向于DDD领域驱动设计的方式与Netty集合,以此来达到我们的框架结构整洁干净易于扩展。同时我们的通信协议也是在服务端进行定义的,并对外提供可引入的Jar包,这样来保证客户端与服务端共同协议下进行通信。
Stars: ✭ 21 (+61.54%)
Mutual labels:  mybatis

Mybatis-Helper

该项目是 Mybatis 插件包, 用于扩展 Mybatis 的特性, 其中包含 生成器( generator ) / 分页插件( paging ) / JPA ( 对象查询 ).

该项目基于 Java7, Mybatis3.4.6 开发, 并且使用 HikariCP-java7 作为连接池, log4j2 作为日志系统, 如若需要使用其他组件, 请自行定义 exclusion.

此处是各组件均使用的配置或操作, 组件详细的文档请查阅各自的文件夹.

多数据源配置

如果需要各组件支持多数据源, 首先需要自行定义多个 DataSource

@Bean( "masterDataSource" )
public DataSource() {
  // maybe master dataSource?
}

@Bean( "replicaDataSource" )
public DataSource() {
  // maybe replica dataSource?
}

然后初始化 DynamicDataSourceRouter, 这是动态数据源路由, 继承了 spring 提供的 AbstractRoutingDataSource, 而该类又间接实现了 DataSource, 因此该类可以直接作为数据源使用.

@Primary
@Bean( "dataSourceRouter" )
public DataSource( ApplicationContext context ) {
  DynamicDataSourceRouter dataSourceRouter = new DynamicDataSourceRouter( context );
  dataSourceRouter.setDefaultTargetDataSource( "dataSourceMaster" );
  
  Map<Object, Object> dataSourceMap = new HashMap<>();
  
  // key 是数据源的别名, 可以通过该别名动态转变使用的数据源
  // value 是真实数据源实例在 spring 的别名, 当然 value 也可以是 DataSource 实例
  dataSourceMap.put( "master", "dataSourceMaster" );
  dataSourceMap.put( "replica", "dataSourceReplica" );
  dataSourceRouter.setTargetDataSources( dataSourceMap );
  
  return dataSourceRouter;
}

首先注意这里是用了 @Primary 标记该数据源路由, 后续所有使用数据源均使用该路由, 而路由本身是通过抽象方法 determineCurrentLookupKey() 获取当前使用的数据源的 key, 也就是上面变量 dataSourceMap 所配置的 key.

当需要改变数据源时, 通过 DynamicDataSourceRouter.setDataSourceName( String name ) 给出数据源的别名, 即可改变后续操作使用的数据源.

当然这种做法虽然是最简单的, 但是可能无法在同一个函数作用域内使用不同的数据源. 除非使用 AOP 拦截 Mapper 并强制使用JDK代理, 但这样亦会导致无法在同一事务内操作, 因为各个 Mapper 的数据库连接都是不相同的.

因此对于主从分离这类场景, 最好还是使用诸如 sharding-jdbc 等第三方解决方案.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].