mybatis-generator-plus

轻度扩展mybatis-generator-core插件,兼容官方插件自动代码

License

License

Categories

Categories

MyBatis Data ORM
GroupId

GroupId

org.ihansen.mbp
ArtifactId

ArtifactId

mybatis-generator-plus
Last Version

Last Version

1.5
Release Date

Release Date

Type

Type

jar
Description

Description

mybatis-generator-plus
轻度扩展mybatis-generator-core插件,兼容官方插件自动代码
Project URL

Project URL

https://github.com/handosme/mybatis-generator-plus
Source Code Management

Source Code Management

https://github.com/handosme/mybatis-generator-plus.git

Download mybatis-generator-plus

How to add to project

<!-- https://jarcasting.com/artifacts/org.ihansen.mbp/mybatis-generator-plus/ -->
<dependency>
    <groupId>org.ihansen.mbp</groupId>
    <artifactId>mybatis-generator-plus</artifactId>
    <version>1.5</version>
</dependency>
// https://jarcasting.com/artifacts/org.ihansen.mbp/mybatis-generator-plus/
implementation 'org.ihansen.mbp:mybatis-generator-plus:1.5'
// https://jarcasting.com/artifacts/org.ihansen.mbp/mybatis-generator-plus/
implementation ("org.ihansen.mbp:mybatis-generator-plus:1.5")
'org.ihansen.mbp:mybatis-generator-plus:jar:1.5'
<dependency org="org.ihansen.mbp" name="mybatis-generator-plus" rev="1.5">
  <artifact name="mybatis-generator-plus" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.ihansen.mbp', module='mybatis-generator-plus', version='1.5')
)
libraryDependencies += "org.ihansen.mbp" % "mybatis-generator-plus" % "1.5"
[org.ihansen.mbp/mybatis-generator-plus "1.5"]

Dependencies

compile (5)

Group / Artifact Type Version
org.slf4j : slf4j-api Optional jar 1.7.21
log4j : log4j Optional jar 1.2.17
mysql : mysql-connector-java jar 5.1.37
com.hynnet » oracle-driver-ojdbc jar 12.1.0.2
com.hynnet : sqljdbc4-chs jar 4.0.2206.100

test (2)

Group / Artifact Type Version
junit : junit jar 4.9
org.mybatis : mybatis jar 3.1.1

Project Modules

There are no modules declared in this project.

MyBatis Generator Plus

License Build Status Maven Central

1.介绍:

MyBatis generator plus 基于mybatis-generator-core v.1.3.2 扩展,增加了以下特性:

  1. 生成支持Oracle、Mysql、Sqlserver分页查询的代码:
//分页查询demo
OperateLogExample relationshipsExample = new OperateLogExample();
relationshipsExample.setPagination(0L,10L);
List<OperateLog> operateLogList = operateLogMapper.selectByExample(relationshipsExample);
  1. 生成支持Oracle、Mysql、Sqlserver批量插入的代码:
//批量插入demo
List<OperateLog> operateLogList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
    OperateLog operateLog = new OperateLog.Builder()
        .action("insertBatch_test"+i)
        .build();
    operateLogList.add(operateLog);
}
operateLogMapper.insertBatch(operateLogList);
  1. Model类支持Builder模式创建,示例代码:
User user = new User.Builder()
    .userName("insert_test")
    .creatTime(new Date())
    .updateTime(new Date())
    .build();
  1. 支持Oracle使用SEQUENCE实现自增主键:
    需要建立表主键对应的SEQUENCE,并且SEQUENCE的名称作出了要求:格式为table_name_SEQUENCE

  2. 支持Mapper接口设置数据源schema,可用于分库业务;
    demo.mapper.ooc.UserVisitLogMapper.DATA_SOURCE_NAME

  3. 针对MySQL下分页大偏移量时慢查询优化List<Domain> selectByBigOffset(DomainExample example);

  4. 乐观锁支持int updateByOptimisticLock(Domain record);

2.使用方式

方式一: 配置maven插件生成代码【推荐】

pom里plugin配置如下:

<plugin>
  <groupId>org.ihansen.mbp</groupId>
  <artifactId>mybatis-generator-plus-maven-plugin</artifactId>
  <version>1.4</version>
  <configuration>
    <verbose>true</verbose>
    <overwrite>true</overwrite>
    <configurationFile>tool/mbp/MybatisGeneratorCfg.xml</configurationFile>
  </configuration>
</plugin>

供参考的MBP配置文件: MybatisGeneratorCfg.xml
终端运行如下命令,生成自动代码:

mvn org.ihansen.mbp:mybatis-generator-plus-maven-plugin:1.4:generate

方式二:运行可执行jar文件

包含运行依赖包的可独立执行jar文件:mybatis-generator-plus-jar-with-dependencies.jar
供参考的MBP配置文件: MybatisGeneratorCfg.xml
使用如下命令执行即可生成自动文件:

java -jar mybatis-generator-plus-jar-with-dependencies-1.4.jar -configfile MybatisGeneratorCfg.xml -overwrite

方式三:main方法运行

本工具的使用方式和原生的MyBatis generator使用方式一致,兼容原生版本。maven 坐标:

<dependency>
  <groupId>org.ihansen.mbp</groupId>
  <artifactId>mybatis-generator-plus</artifactId>
  <version>1.4</version>
  <scope>test</scope>
</dependency>

生成文件的示例入口: test/demo.MBPMain

3.MBP的用户:

ihansen.org 掌上110

Versions

Version
1.5
1.4
1.3
1.1