Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fd6c5bad7 | ||
|
|
8aad55aa4e | ||
|
|
4aab60800d | ||
|
|
9113d03b3a | ||
|
|
98daca6067 | ||
|
|
47bb6b49ac | ||
|
|
f1d1978ad9 | ||
|
|
4a8ab69ddb | ||
|
|
625800bf52 | ||
|
|
ec68043fb3 | ||
|
|
694298abe0 | ||
|
|
5126a75747 | ||
|
|
f74bc8a1d2 | ||
|
|
93b4598937 | ||
|
|
e1525667e4 | ||
|
|
37ded029d8 | ||
|
|
37e3be569c | ||
|
|
8870bcb2c7 | ||
|
|
1e86bcc6c4 | ||
|
|
680c63df39 | ||
|
|
b67fedf971 | ||
|
|
454565f7d6 | ||
|
|
5c1c543896 | ||
|
|
c2fe5274b5 | ||
|
|
f9f6bcdf8c | ||
|
|
6521059fe2 | ||
|
|
56e464e8e8 | ||
|
|
29884853e0 | ||
|
|
eafc116d8c | ||
|
|
b48c5c4195 | ||
|
|
0a94a3d811 | ||
|
|
7d266d192d | ||
|
|
b25c6806c7 | ||
|
|
72f254b018 | ||
|
|
0f5547a23d | ||
|
|
4031668d26 | ||
|
|
464959ef55 | ||
|
|
074576f60e | ||
|
|
abc2ef16b0 | ||
|
|
2878b98290 | ||
|
|
2b326a2fe3 | ||
|
|
87519edc0e | ||
|
|
e0614069be | ||
|
|
f29a30179e | ||
|
|
3e1c68a5b7 | ||
|
|
caa5144db0 | ||
|
|
8588c99189 | ||
|
|
6c832e4981 | ||
|
|
2c41fd735e |
@@ -16,13 +16,14 @@
|
||||
* [数据Model属性对应Column获取插件(ModelColumnPlugin)](#8-数据model属性对应column获取插件)
|
||||
* [存在即更新插件(UpsertPlugin)](#9-存在即更新插件)
|
||||
* [Selective选择插入更新增强插件(SelectiveEnhancedPlugin)](#10-selective选择插入更新增强插件)
|
||||
* [Table增加前缀插件(TablePrefixPlugin)](#11-table增加前缀插件)
|
||||
* [Table重命名插件(TableRenamePlugin)](#12-table重命名插件)
|
||||
* [~~Table增加前缀插件(TablePrefixPlugin)~~](#11-table增加前缀插件)
|
||||
* [~~Table重命名插件(TableRenamePlugin)~~](#12-table重命名插件)
|
||||
* [自定义注释插件(CommentPlugin)](#13-自定义注释插件)
|
||||
* [增量插件(IncrementsPlugin)](#14-增量插件)
|
||||
* [查询结果选择性返回插件(SelectSelectivePlugin)](#15-查询结果选择性返回插件)
|
||||
* [~~官方ConstructorBased配置BUG临时修正插件(ConstructorBasedBugFixPlugin)~~](#16-官方constructorbased配置bug临时修正插件)
|
||||
* [乐观锁插件(OptimisticLockerPlugin)](#17-乐观锁插件)
|
||||
* [表重命名配置插件(TableRenameConfigurationPlugin)](#18-表重命名配置插件)
|
||||
|
||||
---------------------------------------
|
||||
Maven引用:
|
||||
@@ -30,7 +31,7 @@ Maven引用:
|
||||
<dependency>
|
||||
<groupId>com.itfsw</groupId>
|
||||
<artifactId>mybatis-generator-plugin</artifactId>
|
||||
<version>1.2.5</version>
|
||||
<version>1.2.9</version>
|
||||
</dependency>
|
||||
```
|
||||
---------------------------------------
|
||||
@@ -96,6 +97,8 @@ public interface TbMapper {
|
||||
```
|
||||
### 2. MySQL分页插件
|
||||
对应表Example类增加了Mysql分页方法,limit(Integer rows)、limit(Integer offset, Integer rows)和page(Integer page, Integer pageSize)
|
||||
>warning:分页从0开始,目前网上流行的大多数前端框架分页都是从0开始,插件保持这种方式;
|
||||
|
||||
插件:
|
||||
```xml
|
||||
<!-- MySQL分页插件 -->
|
||||
@@ -223,7 +226,9 @@ public class Test {
|
||||
* Criteria的快速返回example()方法。
|
||||
* Criteria链式调用增强,以前如果有按条件增加的查询语句会打乱链式查询构建,现在有了andIf(boolean ifAdd, CriteriaAdd add)方法可一直使用链式调用下去。
|
||||
* Example增强了setOrderByClause方法,新增orderBy(String orderByClause)方法直接返回example,增强链式调用,可以一路.下去了。
|
||||
* 继续增强orderBy(String orderByClause)方法,增加orderBy(String ... orderByClauses)方法,配合数据Model属性对应Column获取插件(ModelColumnPlugin)使用效果更佳。
|
||||
* 继续增强orderBy(String orderByClause)方法,增加orderBy(String ... orderByClauses)方法,配合数据Model属性对应Column获取插件(ModelColumnPlugin)使用效果更佳。
|
||||
* 增加基于column的操作,当配置了[数据Model属性对应Column获取插件(ModelColumnPlugin)](#8-数据model属性对应column获取插件)插件时,提供column之间的比对操作。
|
||||
|
||||
插件:
|
||||
```xml
|
||||
<!-- Example Criteria 增强插件 -->
|
||||
@@ -297,6 +302,19 @@ public class Test {
|
||||
// 这个配合数据Model属性对应Column获取插件(ModelColumnPlugin)使用
|
||||
.orderBy(Tb.Column.field1.asc(), Tb.Column.field3.desc())
|
||||
);
|
||||
|
||||
// -----------------------------------column-----------------------------------
|
||||
this.tbMapper.selectByExample(
|
||||
new TbExample()
|
||||
.createCriteria()
|
||||
.andField1EqualToColumn(Tb.Column.field2) // where field1 = field2
|
||||
.andField1NotEqualToColumn(Tb.Column.field2) // where field1 <> field2
|
||||
.andField1GreaterThanColumn(Tb.Column.field2) // where field1 > field2
|
||||
.andField1GreaterThanOrEqualToColumn(Tb.Column.field2) // where field1 >= field2
|
||||
.andField1LessThanColumn(Tb.Column.field2) // where field1 < field2
|
||||
.andField1LessThanOrEqualToColumn(Tb.Column.field2) // where field1 <= field2
|
||||
.example()
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -330,7 +348,7 @@ public class Test {
|
||||
// 构建插入数据
|
||||
List<Tb> list = new ArrayList<>();
|
||||
list.add(
|
||||
new Tb.Builder()
|
||||
Tb.builder()
|
||||
.field1(0)
|
||||
.field2("xx0")
|
||||
.field3(0)
|
||||
@@ -338,7 +356,7 @@ public class Test {
|
||||
.build()
|
||||
);
|
||||
list.add(
|
||||
new Tb.Builder()
|
||||
Tb.builder()
|
||||
.field1(1)
|
||||
.field2("xx1")
|
||||
.field3(1)
|
||||
@@ -375,9 +393,9 @@ public class Test {
|
||||
<!-- 逻辑删除-未删除值 -->
|
||||
<property name="logicalUnDeleteValue" value="0"/>
|
||||
<!-- 逻辑删除常量名称,不配置默认为 IS_DELETED -->
|
||||
<property name="logicalDeleteValue" value="DEL"/>
|
||||
<property name="logicalDeleteConstName" value="IS_DELETED"/>
|
||||
<!-- 逻辑删除常量(未删除)名称,不配置默认为 NOT_DELETED -->
|
||||
<property name="logicalUnDeleteValue" value="UN_DEL"/>
|
||||
<property name="logicalUnDeleteConstName" value="NOT_DELETED"/>
|
||||
</plugin>
|
||||
|
||||
<table tableName="tb">
|
||||
@@ -416,7 +434,7 @@ public class Test {
|
||||
);
|
||||
|
||||
// 4. 逻辑删除和未删除常量
|
||||
Tb tb = new Tb.Builder()
|
||||
Tb tb = Tb.builder()
|
||||
.delFlag(Tb.IS_DELETED) // 删除
|
||||
.delFlag(Tb.NOT_DELETED) // 未删除
|
||||
.build()
|
||||
@@ -468,7 +486,7 @@ public class Test {
|
||||
// 3. 配合批量插入插件(BatchInsertPlugin)使用实现按需插入指定列
|
||||
List<Tb> list = new ArrayList<>();
|
||||
list.add(
|
||||
new Tb.Builder()
|
||||
Tb.builder()
|
||||
.field1(0)
|
||||
.field2("xx0")
|
||||
.field3(0)
|
||||
@@ -476,7 +494,7 @@ public class Test {
|
||||
.build()
|
||||
);
|
||||
list.add(
|
||||
new Tb.Builder()
|
||||
Tb.builder()
|
||||
.field1(1)
|
||||
.field2("xx1")
|
||||
.field3(1)
|
||||
@@ -518,7 +536,7 @@ public class Test {
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
// 1. 未入库数据入库,执行insert
|
||||
Tb tb = new Tb.Builder()
|
||||
Tb tb = Tb.builder()
|
||||
.field1(1)
|
||||
.field2("xx0")
|
||||
.delFlag(Tb.DEL_FLAG_ON)
|
||||
@@ -529,7 +547,7 @@ public class Test {
|
||||
int k1 = this.tbMapper.upsert(tb);
|
||||
|
||||
// 3. 类似insertSelective实现选择入库
|
||||
Tb tb1 = new Tb.Builder()
|
||||
Tb tb1 = Tb.builder()
|
||||
.field1(1)
|
||||
.field2("xx0")
|
||||
.build();
|
||||
@@ -537,8 +555,9 @@ public class Test {
|
||||
tb1.setField2("xx1");
|
||||
int k3 = this.tbMapper.upsertSelective(tb1);
|
||||
|
||||
// --------------------------------- allowMultiQueries=true ------------------------------
|
||||
// 4. 开启allowMultiQueries后增加upsertByExample,upsertByExampleSelective但强力建议不要使用(需保证团队没有使用statement提交sql,否则会存在sql注入风险)
|
||||
Tb tb2 = new Tb.Builder()
|
||||
Tb tb2 = Tb.builder()
|
||||
.field1(1)
|
||||
.field2("xx0")
|
||||
.field3(1003)
|
||||
@@ -562,12 +581,34 @@ public class Test {
|
||||
// upsertByExampleSelective 用法类似
|
||||
|
||||
// 当Model WithBLOBs 存在时上述方法增加对应的 WithBLOBs 方法,举例如下:
|
||||
TbWithBLOBs tb3 = new Tb.Builder()
|
||||
.field1(1)
|
||||
.field2("xx0")
|
||||
.delFlag(Tb.DEL_FLAG_ON)
|
||||
.build();
|
||||
TbWithBLOBs tb3 = Tb.builder()
|
||||
.field1(1)
|
||||
.field2("xx0")
|
||||
.delFlag(Tb.DEL_FLAG_ON)
|
||||
.build();
|
||||
int k6 = this.tbMapper.upsertWithBLOBs(tb);
|
||||
|
||||
// --------------------------------- allowBatchUpsert=true ------------------------------
|
||||
List<Tb> list = new ArrayList<>();
|
||||
list.add(
|
||||
Tb.builder()
|
||||
.field1(0)
|
||||
.field2("xx0")
|
||||
.field3(0)
|
||||
.field4(new Date())
|
||||
.build()
|
||||
);
|
||||
list.add(
|
||||
Tb.builder()
|
||||
.field1(1)
|
||||
.field2("xx1")
|
||||
.field3(1)
|
||||
.field4(new Date())
|
||||
.build()
|
||||
);
|
||||
this.tbMapper.batchUpsert(list); // 对于BLOBs 有batchUpsertWithBLOBs方法
|
||||
this.tbMapper.batchUpsertSelective(list, Tb.Column.field1, Tb.Column.field2, Tb.Column.field3, Tb.Column.createTime);
|
||||
this.tbMapper.batchUpsertSelective(list, Tb.Column.excludes(Tb.Column.id, Tb.Column.delFlag)); // 排除某些列
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -586,7 +627,7 @@ public class Test {
|
||||
public static void main(String[] args) {
|
||||
// ------------------------------ 新版本(SelectiveEnhancedPlugin)--------------------------------
|
||||
// 1. 指定插入或更新字段
|
||||
Tb tb = new Tb.Builder()
|
||||
Tb tb = Tb.builder()
|
||||
.field1(1)
|
||||
.field2("xx2")
|
||||
.field3(1)
|
||||
@@ -615,7 +656,7 @@ public class Test {
|
||||
|
||||
// 2. 更新某些字段为null
|
||||
this.tbMapper.updateByPrimaryKeySelective(
|
||||
new Tb.Builder()
|
||||
Tb.builder()
|
||||
.id(1l)
|
||||
.field1(null) // 方便展示,不用设也可以
|
||||
.build(),
|
||||
@@ -631,7 +672,12 @@ public class Test {
|
||||
项目中有时会遇到配置多数据源对应多业务的情况,这种情况下可能会出现不同数据源出现重复表名,造成异常冲突。
|
||||
该插件允许为表增加前缀,改变最终生成的Model、Mapper、Example类名以及xml名。
|
||||
>warning: 使用[Table重命名插件](12-table重命名插件)可以实现相同功能!
|
||||
|
||||
>warning: 官方最新版本中已提供domainObjectRenamingRule支持(可以配合[表重命名配置插件](#18-表重命名配置插件)进行全局配置)!
|
||||
```xml
|
||||
<table tableName="tb">
|
||||
<domainObjectRenamingRule searchString="^" replaceString="DB1" />
|
||||
</table>
|
||||
```
|
||||
插件:
|
||||
```xml
|
||||
<xml>
|
||||
@@ -675,6 +721,12 @@ public class Test {
|
||||
<property name="searchString" value="^"/>
|
||||
<property name="replaceString" value="DB1"/>
|
||||
```
|
||||
>warning: 官方最新版本中已提供domainObjectRenamingRule支持(可以配合[表重命名配置插件](#18-表重命名配置插件)进行全局配置)!
|
||||
```xml
|
||||
<table tableName="tb">
|
||||
<domainObjectRenamingRule searchString="^T" replaceString="" />
|
||||
</table>
|
||||
```
|
||||
|
||||
插件:
|
||||
```xml
|
||||
@@ -1052,7 +1104,7 @@ Mybatis Generator是原生支持自定义注释的(commentGenerator配置type
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
// 在构建更新对象时,配置了增量支持的字段会增加传入增量枚举的方法
|
||||
Tb tb = new Tb.Builder()
|
||||
Tb tb = Tb.builder()
|
||||
.id(102)
|
||||
.field1(1, Tb.Builder.Inc.INC) // 字段1 统计增加1
|
||||
.field2(2, Tb.Builder.Inc.DEC) // 字段2 统计减去2
|
||||
@@ -1125,13 +1177,13 @@ public class Test {
|
||||
<xml>
|
||||
<!-- 乐观锁插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.OptimisticLockerPlugin">
|
||||
<!-- 是否启用自定义nextVersion, 默认不启用使用(使用sql的 set column = column + 1) -->
|
||||
<property name="customizedNextVersion" value="true"/>
|
||||
<!-- 是否启用自定义nextVersion,默认不启用(插件会默认使用sql的 set column = column + 1) -->
|
||||
<property name="customizedNextVersion" value="false"/>
|
||||
</plugin>
|
||||
|
||||
<table tableName="tb">
|
||||
<!-- 这里可以单独表配置,覆盖全局配置 -->
|
||||
<property name="customizedNextVersion" value="false"/>
|
||||
<property name="customizedNextVersion" value="true"/>
|
||||
<!-- 指定版本列 -->
|
||||
<property name="versionColumn" value="version"/>
|
||||
</table>
|
||||
@@ -1162,23 +1214,82 @@ public class Test {
|
||||
// ============================= 使用默认版本号生成策略 ===========================
|
||||
this.tbMapper.updateWithVersionByPrimaryKey(
|
||||
100, // 版本号
|
||||
new Tb.Builder()
|
||||
.id(102)
|
||||
.field1("ts1")
|
||||
.build()
|
||||
Tb.builder()
|
||||
.id(102)
|
||||
.field1("ts1")
|
||||
.build()
|
||||
);
|
||||
// 对应生成的Sql: update tb set version = version + 1, field1 = 'ts1' where version = 100 and id = 102
|
||||
|
||||
// ============================= 使用自定义版本号生成策略 ===========================
|
||||
this.tbMapper.updateWithVersionByPrimaryKey(
|
||||
100, // 版本号
|
||||
new Tb.Builder()
|
||||
.id(102)
|
||||
.field1("ts1")
|
||||
.nextVersion(System.currentTimeMillis()) // 传入nextVersion
|
||||
.build()
|
||||
Tb.builder()
|
||||
.id(102)
|
||||
.field1("ts1")
|
||||
.nextVersion(System.currentTimeMillis()) // 传入nextVersion
|
||||
.build()
|
||||
);
|
||||
// 对应生成的Sql: update tb set version = 1525773888559, field1 = 'ts1' where version = 100 and id = 102
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
### 18. 表重命名配置插件
|
||||
官方提供了domainObjectRenamingRule(官方最新版本已提供)、columnRenamingRule分别进行生成的表名称和对应表字段的重命名支持,但是它需要每个表单独进行配置,对于常用的如表附带前缀“t_”、字段前缀“f_”这种全局性替换会比较麻烦。
|
||||
该插件提供了一种全局替换机制,当表没有单独指定domainObjectRenamingRule、columnRenamingRule时采用全局性配置。同时该插件会修复官方domainObjectRenamingRule的bug(没有进行正确的首字母大写)。
|
||||
同时插件提供clientSuffix、exampleSuffix、modelSuffix来修改对应生成的类和文件的结尾(之前issue中有用户希望能把Mapper替换成Dao)。
|
||||
- 全局domainObjectRenamingRule
|
||||
```xml
|
||||
<xml>
|
||||
<!-- 表重命名配置插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<property name="domainObjectRenamingRule.searchString" value="^T"/>
|
||||
<property name="domainObjectRenamingRule.replaceString" value=""/>
|
||||
</plugin>
|
||||
|
||||
<table tableName="tb">
|
||||
<!-- 这里可以禁用全局domainObjectRenamingRule配置 -->
|
||||
<property name="domainObjectRenamingRule.disable" value="true"/>
|
||||
</table>
|
||||
|
||||
<table tableName="tb_ts1">
|
||||
<!-- 当然你也可以使用官方domainObjectRenamingRule的配置来覆盖全局配置 -->
|
||||
<domainObjectRenamingRule searchString="^Tb" replaceString="B"/>
|
||||
</table>
|
||||
</xml>
|
||||
```
|
||||
- 全局columnRenamingRule
|
||||
```xml
|
||||
<xml>
|
||||
<!-- 表重命名配置插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<!-- 需要注意,这里的正则和官方一样是比对替换都是原始表的column名称 -->
|
||||
<property name="columnRenamingRule.searchString" value="^f_"/>
|
||||
<property name="columnRenamingRule.replaceString" value="_"/>
|
||||
</plugin>
|
||||
|
||||
<table tableName="tb">
|
||||
<!-- 这里可以禁用全局columnRenamingRule配置 -->
|
||||
<property name="columnRenamingRule.disable" value="true"/>
|
||||
</table>
|
||||
|
||||
<table tableName="tb_ts1">
|
||||
<!-- 当然你也可以使用官方domainObjectRenamingRule的配置来覆盖全局配置 -->
|
||||
<columnRenamingRule searchString="^f_" replaceString="_"/>
|
||||
</table>
|
||||
</xml>
|
||||
```
|
||||
- clientSuffix、exampleSuffix、modelSuffix
|
||||
```xml
|
||||
<xml>
|
||||
<!-- 表重命名配置插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<!-- TbMapper -> TbDao, TbMapper.xml -> TbDao.xml -->
|
||||
<property name="clientSuffix" value="Dao"/>
|
||||
<!-- TbExmaple -> TbQuery -->
|
||||
<property name="exampleSuffix" value="Query"/>
|
||||
<!-- Tb -> TbEntity -->
|
||||
<property name="modelSuffix" value="Entity"/>
|
||||
</plugin>
|
||||
</xml>
|
||||
```
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<groupId>com.itfsw</groupId>
|
||||
<artifactId>mybatis-generator-plugin</artifactId>
|
||||
<version>1.2.5</version>
|
||||
<version>1.2.10</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.groupId}:${project.artifactId}</name>
|
||||
@@ -217,7 +217,7 @@
|
||||
<connection>scm:git:https://github.com/itfsw/mybatis-generator-plugin.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/itfsw/mybatis-generator-plugin.git</developerConnection>
|
||||
<url>https://github.com/itfsw/mybatis-generator-plugin</url>
|
||||
<tag>V1.2.5</tag>
|
||||
<tag>V1.2.10</tag>
|
||||
</scm>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++distribution++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
@@ -52,7 +52,8 @@ public class BatchInsertPlugin extends BasePlugin {
|
||||
// 插件使用前提是数据库为MySQL或者SQLserver,因为返回主键使用了JDBC的getGenereatedKeys方法获取主键
|
||||
if ("com.mysql.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false
|
||||
&& "com.microsoft.jdbc.sqlserver.SQLServer".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false
|
||||
&& "com.microsoft.sqlserver.jdbc.SQLServerDriver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false) {
|
||||
&& "com.microsoft.sqlserver.jdbc.SQLServerDriver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false
|
||||
&& "com.mysql.cj.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false) {
|
||||
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件使用前提是数据库为MySQL或者SQLserver,因为返回主键使用了JDBC的getGenereatedKeys方法获取主键!");
|
||||
return false;
|
||||
}
|
||||
@@ -231,7 +232,7 @@ public class BatchInsertPlugin extends BasePlugin {
|
||||
foreachInsertColumns.addAttribute(new Attribute("collection", "selective"));
|
||||
foreachInsertColumns.addAttribute(new Attribute("item", "column"));
|
||||
foreachInsertColumns.addAttribute(new Attribute("separator", ","));
|
||||
foreachInsertColumns.addElement(new TextElement("${column.value}"));
|
||||
foreachInsertColumns.addElement(new TextElement("${column.escapedColumnName}"));
|
||||
|
||||
eles.add(foreachInsertColumns);
|
||||
|
||||
@@ -260,7 +261,7 @@ public class BatchInsertPlugin extends BasePlugin {
|
||||
for (int i = 0; i < columns1.size(); i++) {
|
||||
IntrospectedColumn introspectedColumn = columns.get(i);
|
||||
XmlElement check = new XmlElement("if");
|
||||
check.addAttribute(new Attribute("test", "'" + introspectedColumn.getActualColumnName() + "' == column.value"));
|
||||
check.addAttribute(new Attribute("test", "'" + introspectedColumn.getActualColumnName() + "'.toString() == column.value"));
|
||||
check.addElement(new TextElement(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.")));
|
||||
|
||||
foreachInsertColumnsCheck.addElement(check);
|
||||
|
||||
@@ -3,10 +3,13 @@ package com.itfsw.mybatis.generator.plugins;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.BasePlugin;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.FormatTools;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.PluginTools;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.enhanced.InnerInterface;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.enhanced.InnerInterfaceWrapperToInnerClass;
|
||||
import org.mybatis.generator.api.IntrospectedColumn;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.api.dom.java.*;
|
||||
import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,6 +22,17 @@ import java.util.List;
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class ExampleEnhancedPlugin extends BasePlugin {
|
||||
private boolean enableColumnOperate = false; // 是否启用column的操作
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @param introspectedTable
|
||||
*/
|
||||
@Override
|
||||
public void initialized(IntrospectedTable introspectedTable) {
|
||||
super.initialized(introspectedTable);
|
||||
this.enableColumnOperate = PluginTools.checkDependencyPlugin(context, ModelColumnPlugin.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* ModelExample Methods 生成
|
||||
@@ -36,6 +50,11 @@ public class ExampleEnhancedPlugin extends BasePlugin {
|
||||
addFactoryMethodToCriteria(topLevelClass, innerClass, introspectedTable);
|
||||
// andIf
|
||||
addAndIfMethodToCriteria(topLevelClass, innerClass, introspectedTable);
|
||||
} else if ("GeneratedCriteria".equals(innerClass.getType().getShortName())) {
|
||||
// column 方法
|
||||
if (this.enableColumnOperate) {
|
||||
addColumnMethodToCriteria(topLevelClass, innerClass, introspectedTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +72,81 @@ public class ExampleEnhancedPlugin extends BasePlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加列操作方法
|
||||
* @param topLevelClass
|
||||
* @param innerClass
|
||||
* @param introspectedTable
|
||||
*/
|
||||
private void addColumnMethodToCriteria(TopLevelClass topLevelClass, InnerClass innerClass, IntrospectedTable introspectedTable) {
|
||||
// !!!!! Column import比较特殊引入的是外部类
|
||||
topLevelClass.addImportedType(introspectedTable.getRules().calculateAllFieldsClass());
|
||||
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
|
||||
topLevelClass.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
|
||||
// EqualTo
|
||||
FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "EqualTo", "="));
|
||||
// NotEqualTo
|
||||
FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "NotEqualTo", "<>"));
|
||||
// GreaterThan
|
||||
FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "GreaterThan", ">"));
|
||||
// GreaterThanOrEqualTo
|
||||
FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "GreaterThanOrEqualTo", ">="));
|
||||
// LessThan
|
||||
FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "LessThan", "<"));
|
||||
// LessThanOrEqualTo
|
||||
FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "LessThanOrEqualTo", "<="));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成column操作的具体方法
|
||||
* @param introspectedTable
|
||||
* @param introspectedColumn
|
||||
* @param nameFragment
|
||||
* @param operator
|
||||
* @return
|
||||
*/
|
||||
private Method generateSingleValueMethod(IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, String nameFragment, String operator) {
|
||||
// 方法名
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(introspectedColumn.getJavaProperty());
|
||||
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
|
||||
sb.insert(0, "and");
|
||||
sb.append(nameFragment);
|
||||
sb.append("Column");
|
||||
|
||||
Method method = JavaElementGeneratorTools.generateMethod(
|
||||
sb.toString(),
|
||||
JavaVisibility.PUBLIC,
|
||||
FullyQualifiedJavaType.getCriteriaInstance(),
|
||||
new Parameter(
|
||||
new FullyQualifiedJavaType(introspectedTable.getRules().calculateAllFieldsClass().getShortName() + "." + ModelColumnPlugin.ENUM_NAME),
|
||||
"column"
|
||||
)
|
||||
);
|
||||
commentGenerator.addGeneralMethodComment(method, introspectedTable);
|
||||
|
||||
// 方法体
|
||||
sb.setLength(0);
|
||||
sb.append("addCriterion(");
|
||||
sb.append("new StringBuilder(\"");
|
||||
sb.append(MyBatis3FormattingUtilities.getAliasedActualColumnName(introspectedColumn));
|
||||
sb.append(" ");
|
||||
sb.append(operator);
|
||||
sb.append(" \").append(");
|
||||
sb.append("column.");
|
||||
sb.append(ModelColumnPlugin.METHOD_GET_ESCAPED_COLUMN_NAME);
|
||||
sb.append("()).toString());");
|
||||
|
||||
JavaElementGeneratorTools.generateMethodBody(
|
||||
method,
|
||||
sb.toString(),
|
||||
"return (Criteria) this;"
|
||||
);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加工厂方法
|
||||
* @param topLevelClass
|
||||
|
||||
@@ -61,6 +61,7 @@ public class ExampleTargetPlugin extends BasePlugin {
|
||||
*/
|
||||
@Override
|
||||
public void initialized(IntrospectedTable introspectedTable) {
|
||||
super.initialized(introspectedTable);
|
||||
String exampleType = introspectedTable.getExampleType();
|
||||
// 修改包名
|
||||
Context context = getContext();
|
||||
|
||||
@@ -329,7 +329,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
|
||||
sb.append("column.value");
|
||||
|
||||
when.addAttribute(new Attribute("test", sb.toString()));
|
||||
when.addElement(new TextElement("${column.value} = ${column.value} ${record." + FIELD_INC_MAP + "."
|
||||
when.addElement(new TextElement("${column.escapedColumnName} = ${column.escapedColumnName} ${record." + FIELD_INC_MAP + "."
|
||||
+ introspectedColumn.getActualColumnName()
|
||||
+ ".value} #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
choose.addElement(when);
|
||||
@@ -338,13 +338,13 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
|
||||
|
||||
if (versionColumn == null) {
|
||||
XmlElement otherwise = new XmlElement("otherwise");
|
||||
otherwise.addElement(new TextElement("${column.value} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
otherwise.addElement(new TextElement("${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
choose.addElement(otherwise);
|
||||
} else {
|
||||
XmlElement when = new XmlElement("when");
|
||||
when.addAttribute(new Attribute("test", "column.value != '" + versionColumn.getActualColumnName() + "'.toString()"));
|
||||
|
||||
when.addElement(new TextElement("${column.value} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
when.addElement(new TextElement("${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
|
||||
choose.addElement(when);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@ public class LimitPlugin extends BasePlugin {
|
||||
@Override
|
||||
public boolean validate(List<String> warnings) {
|
||||
// 该插件只支持MYSQL
|
||||
if ("com.mysql.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false) {
|
||||
if ("com.mysql.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false
|
||||
&& "com.mysql.cj.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false) {
|
||||
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "只支持MySQL数据库!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ public class LogicalDeletePlugin extends BasePlugin {
|
||||
*/
|
||||
@Override
|
||||
public void initialized(IntrospectedTable introspectedTable) {
|
||||
super.initialized(introspectedTable);
|
||||
// 1. 首先获取全局配置
|
||||
Properties properties = getProperties();
|
||||
String logicalDeleteColumn = properties.getProperty(PRO_LOGICAL_DELETE_COLUMN);
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.mybatis.generator.api.IntrospectedColumn;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.api.dom.java.*;
|
||||
import org.mybatis.generator.internal.util.JavaBeansUtil;
|
||||
import org.mybatis.generator.internal.util.StringUtility;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
@@ -35,6 +36,10 @@ import org.mybatis.generator.internal.util.JavaBeansUtil;
|
||||
public class ModelColumnPlugin extends BasePlugin {
|
||||
public static final String ENUM_NAME = "Column"; // 内部Enum名
|
||||
public static final String METHOD_EXCLUDES = "excludes"; // 方法名
|
||||
public static final String METHOD_GET_ESCAPED_COLUMN_NAME = "getEscapedColumnName"; // 方法名
|
||||
|
||||
public static final String CONST_BEGINNING_DELIMITER = "BEGINNING_DELIMITER"; // const
|
||||
public static final String CONST_ENDING_DELIMITER = "ENDING_DELIMITER"; // const
|
||||
|
||||
/**
|
||||
* Model Methods 生成
|
||||
@@ -88,6 +93,29 @@ public class ModelColumnPlugin extends BasePlugin {
|
||||
commentGenerator.addEnumComment(innerEnum, introspectedTable);
|
||||
logger.debug("itfsw(数据Model属性对应Column获取插件):" + topLevelClass.getType().getShortName() + "增加内部Builder类。");
|
||||
|
||||
// 生成常量
|
||||
Field beginningDelimiterField = JavaElementGeneratorTools.generateField(
|
||||
CONST_BEGINNING_DELIMITER,
|
||||
JavaVisibility.PRIVATE,
|
||||
FullyQualifiedJavaType.getStringInstance(),
|
||||
"\"" + StringUtility.escapeStringForJava(context.getBeginningDelimiter()) + "\""
|
||||
);
|
||||
beginningDelimiterField.setStatic(true);
|
||||
beginningDelimiterField.setFinal(true);
|
||||
commentGenerator.addFieldComment(beginningDelimiterField, introspectedTable);
|
||||
innerEnum.addField(beginningDelimiterField);
|
||||
|
||||
Field endingDelimiterField = JavaElementGeneratorTools.generateField(
|
||||
CONST_ENDING_DELIMITER,
|
||||
JavaVisibility.PRIVATE,
|
||||
FullyQualifiedJavaType.getStringInstance(),
|
||||
"\"" + StringUtility.escapeStringForJava(context.getEndingDelimiter()) + "\""
|
||||
);
|
||||
endingDelimiterField.setStatic(true);
|
||||
endingDelimiterField.setFinal(true);
|
||||
commentGenerator.addFieldComment(endingDelimiterField, introspectedTable);
|
||||
innerEnum.addField(endingDelimiterField);
|
||||
|
||||
// 生成属性和构造函数
|
||||
Field columnField = new Field("column", FullyQualifiedJavaType.getStringInstance());
|
||||
columnField.setVisibility(JavaVisibility.PRIVATE);
|
||||
@@ -95,6 +123,12 @@ public class ModelColumnPlugin extends BasePlugin {
|
||||
commentGenerator.addFieldComment(columnField, introspectedTable);
|
||||
innerEnum.addField(columnField);
|
||||
|
||||
Field isColumnNameDelimitedField = new Field("isColumnNameDelimited", FullyQualifiedJavaType.getBooleanPrimitiveInstance());
|
||||
isColumnNameDelimitedField.setVisibility(JavaVisibility.PRIVATE);
|
||||
isColumnNameDelimitedField.setFinal(true);
|
||||
commentGenerator.addFieldComment(isColumnNameDelimitedField, introspectedTable);
|
||||
innerEnum.addField(isColumnNameDelimitedField);
|
||||
|
||||
Field javaPropertyField = new Field("javaProperty", FullyQualifiedJavaType.getStringInstance());
|
||||
javaPropertyField.setVisibility(JavaVisibility.PRIVATE);
|
||||
javaPropertyField.setFinal(true);
|
||||
@@ -134,9 +168,11 @@ public class ModelColumnPlugin extends BasePlugin {
|
||||
constructor.addBodyLine("this.column = column;");
|
||||
constructor.addBodyLine("this.javaProperty = javaProperty;");
|
||||
constructor.addBodyLine("this.jdbcType = jdbcType;");
|
||||
constructor.addBodyLine("this.isColumnNameDelimited = isColumnNameDelimited;");
|
||||
constructor.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "column"));
|
||||
constructor.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "javaProperty"));
|
||||
constructor.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "jdbcType"));
|
||||
constructor.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "isColumnNameDelimited"));
|
||||
commentGenerator.addGeneralMethodComment(constructor, introspectedTable);
|
||||
FormatTools.addMethodWithBestPosition(innerEnum, constructor);
|
||||
logger.debug("itfsw(数据Model属性对应Column获取插件):" + topLevelClass.getType().getShortName() + ".Column增加构造方法和column属性。");
|
||||
@@ -153,7 +189,9 @@ public class ModelColumnPlugin extends BasePlugin {
|
||||
sb.append(introspectedColumn.getJavaProperty());
|
||||
sb.append("\", \"");
|
||||
sb.append(introspectedColumn.getJdbcTypeName());
|
||||
sb.append("\")");
|
||||
sb.append("\", ");
|
||||
sb.append(introspectedColumn.isColumnNameDelimited());
|
||||
sb.append(")");
|
||||
|
||||
innerEnum.addEnumConstant(sb.toString());
|
||||
logger.debug("itfsw(数据Model属性对应Column获取插件):" + topLevelClass.getType().getShortName() + ".Column增加" + field.getName() + "枚举。");
|
||||
@@ -163,14 +201,14 @@ public class ModelColumnPlugin extends BasePlugin {
|
||||
Method desc = new Method("desc");
|
||||
desc.setVisibility(JavaVisibility.PUBLIC);
|
||||
desc.setReturnType(FullyQualifiedJavaType.getStringInstance());
|
||||
desc.addBodyLine("return this.column + \" DESC\";");
|
||||
desc.addBodyLine("return this." + METHOD_GET_ESCAPED_COLUMN_NAME + "() + \" DESC\";");
|
||||
commentGenerator.addGeneralMethodComment(desc, introspectedTable);
|
||||
FormatTools.addMethodWithBestPosition(innerEnum, desc);
|
||||
|
||||
Method asc = new Method("asc");
|
||||
asc.setVisibility(JavaVisibility.PUBLIC);
|
||||
asc.setReturnType(FullyQualifiedJavaType.getStringInstance());
|
||||
asc.addBodyLine("return this.column + \" ASC\";");
|
||||
asc.addBodyLine("return this." + METHOD_GET_ESCAPED_COLUMN_NAME + "() + \" ASC\";");
|
||||
commentGenerator.addGeneralMethodComment(asc, introspectedTable);
|
||||
FormatTools.addMethodWithBestPosition(innerEnum, asc);
|
||||
logger.debug("itfsw(数据Model属性对应Column获取插件):" + topLevelClass.getType().getShortName() + ".Column增加asc()和desc()方法。");
|
||||
@@ -197,6 +235,24 @@ public class ModelColumnPlugin extends BasePlugin {
|
||||
FormatTools.addMethodWithBestPosition(innerEnum, mExcludes);
|
||||
logger.debug("itfsw(数据Model属性对应Column获取插件):" + topLevelClass.getType().getShortName() + ".Column增加excludes方法。");
|
||||
|
||||
// getEscapedColumnName
|
||||
Method mGetEscapedColumnName = JavaElementGeneratorTools.generateMethod(
|
||||
METHOD_GET_ESCAPED_COLUMN_NAME,
|
||||
JavaVisibility.PUBLIC,
|
||||
FullyQualifiedJavaType.getStringInstance()
|
||||
);
|
||||
commentGenerator.addGeneralMethodComment(mGetEscapedColumnName, introspectedTable);
|
||||
JavaElementGeneratorTools.generateMethodBody(
|
||||
mGetEscapedColumnName,
|
||||
"if (this.isColumnNameDelimited) {",
|
||||
"return new StringBuilder().append(" + CONST_BEGINNING_DELIMITER + ").append(this.column).append(" + CONST_ENDING_DELIMITER + ").toString();",
|
||||
"} else {",
|
||||
"return this.column;",
|
||||
"}"
|
||||
);
|
||||
FormatTools.addMethodWithBestPosition(innerEnum, mGetEscapedColumnName);
|
||||
logger.debug("itfsw(数据Model属性对应Column获取插件):" + topLevelClass.getType().getShortName() + ".Column增加getEscapedColumnName方法。");
|
||||
|
||||
return innerEnum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public class OptimisticLockerPlugin extends BasePlugin implements IModelBuilderP
|
||||
|
||||
@Override
|
||||
public void initialized(IntrospectedTable introspectedTable) {
|
||||
super.initialized(introspectedTable);
|
||||
sqlMaps.put(introspectedTable, new ArrayList<>());
|
||||
|
||||
// 读取并验证版本列
|
||||
@@ -68,6 +69,8 @@ public class OptimisticLockerPlugin extends BasePlugin implements IModelBuilderP
|
||||
if (this.versionColumn == null) {
|
||||
warnings.add("itfsw(乐观锁插件):表" + introspectedTable.getFullyQualifiedTable() + "配置的版本列(" + introspectedTable.getTableConfigurationProperty(PRO_VERSION_COLUMN) + ")没有找到!");
|
||||
}
|
||||
} else {
|
||||
this.versionColumn = null;
|
||||
}
|
||||
|
||||
// 自定义nextVersion
|
||||
|
||||
@@ -336,7 +336,7 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
|
||||
keysEle.addAttribute(new Attribute("collection", "selective"));
|
||||
keysEle.addAttribute(new Attribute("item", "column"));
|
||||
keysEle.addAttribute(new Attribute("separator", ","));
|
||||
keysEle.addElement(new TextElement("${column.value}"));
|
||||
keysEle.addElement(new TextElement("${column.escapedColumnName}"));
|
||||
|
||||
XmlElement otherwiseEle = new XmlElement("otherwise");
|
||||
chooseEle.addElement(otherwiseEle);
|
||||
|
||||
@@ -169,11 +169,9 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
|
||||
// warning has already been reported
|
||||
if (introspectedColumn != null) {
|
||||
if (gk.isJdbcStandard()) {
|
||||
answer.addAttribute(new Attribute("useGeneratedKeys", "true"));
|
||||
answer.addAttribute(new Attribute("keyProperty", introspectedColumn.getJavaProperty()));
|
||||
answer.addAttribute(new Attribute("keyColumn", introspectedColumn.getActualColumnName()));
|
||||
XmlElementGeneratorTools.useGeneratedKeys(answer, introspectedTable, "record.");
|
||||
} else {
|
||||
answer.addElement(XmlElementGeneratorTools.getSelectKey(introspectedColumn, gk));
|
||||
answer.addElement(XmlElementGeneratorTools.getSelectKey(introspectedColumn, gk, "record."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -397,7 +395,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
|
||||
insertForeachEle.addAttribute(new Attribute("open", "("));
|
||||
insertForeachEle.addAttribute(new Attribute("separator", ","));
|
||||
insertForeachEle.addAttribute(new Attribute("close", ")"));
|
||||
insertForeachEle.addElement(new TextElement("${column.value}"));
|
||||
insertForeachEle.addElement(new TextElement("${column.escapedColumnName}"));
|
||||
insertWhenEle.addElement(insertForeachEle);
|
||||
|
||||
XmlElement insertOtherwiseEle = new XmlElement("otherwise");
|
||||
@@ -483,13 +481,13 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
|
||||
Element incrementEle = PluginTools.getHook(IIncrementsPluginHook.class).incrementSetsWithSelectiveEnhancedPluginElementGenerated(versionColumn);
|
||||
// 普通情况
|
||||
if (incrementEle == null && versionColumn == null) {
|
||||
setForeachEle.addElement(new TextElement("${column.value} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
setForeachEle.addElement(new TextElement("${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
} else if (incrementEle != null) {
|
||||
setForeachEle.addElement(incrementEle);
|
||||
} else if (versionColumn != null) {
|
||||
XmlElement ifEle = new XmlElement("if");
|
||||
ifEle.addAttribute(new Attribute("test", "column.value != '" + versionColumn.getActualColumnName() + "'.toString()"));
|
||||
ifEle.addElement(new TextElement("${column.value} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
ifEle.addElement(new TextElement("${column.escapedColumnName} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"));
|
||||
|
||||
setForeachEle.addElement(ifEle);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.List;
|
||||
* @time:2017/5/18 13:54
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
@Deprecated
|
||||
public class TablePrefixPlugin extends BasePlugin {
|
||||
|
||||
public static final String PRO_PREFIX = "prefix"; // 前缀 property
|
||||
@@ -78,5 +79,6 @@ public class TablePrefixPlugin extends BasePlugin {
|
||||
logger.error("itfsw:插件" + this.getClass().getTypeName() + "使用prefix替换时异常!", e);
|
||||
}
|
||||
}
|
||||
super.initialized(introspectedTable);
|
||||
}
|
||||
}
|
||||
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* Copyright (c) 2018.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins;
|
||||
|
||||
import com.itfsw.mybatis.generator.plugins.utils.BasePlugin;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.BeanUtils;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.hook.ITableConfigurationHook;
|
||||
import org.mybatis.generator.api.FullyQualifiedTable;
|
||||
import org.mybatis.generator.api.IntrospectedColumn;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.config.ColumnRenamingRule;
|
||||
import org.mybatis.generator.config.DomainObjectRenamingRule;
|
||||
import org.mybatis.generator.config.PropertyRegistry;
|
||||
import org.mybatis.generator.config.TableConfiguration;
|
||||
import org.mybatis.generator.internal.util.StringUtility;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.mybatis.generator.internal.util.JavaBeansUtil.getCamelCaseString;
|
||||
import static org.mybatis.generator.internal.util.JavaBeansUtil.getValidPropertyName;
|
||||
import static org.mybatis.generator.internal.util.StringUtility.isTrue;
|
||||
import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
*
|
||||
* ---------------------------------------------------------------------------
|
||||
* @author: hewei
|
||||
* @time:2018/5/21 11:23
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class TableRenameConfigurationPlugin extends BasePlugin implements ITableConfigurationHook {
|
||||
public static final String PRO_TABLE_SEARCH_STRING = "domainObjectRenamingRule.searchString"; // 查找 property
|
||||
public static final String PRO_TABLE_REPLACE_STRING = "domainObjectRenamingRule.replaceString"; // 替换 property
|
||||
public static final String PRO_TABLE_REPLACE_DISABLE = "domainObjectRenamingRule.disable"; // 替换 property
|
||||
public static final String PRO_COLUMN_SEARCH_STRING = "columnRenamingRule.searchString"; // 查找 property
|
||||
public static final String PRO_COLUMN_REPLACE_STRING = "columnRenamingRule.replaceString"; // 替换 property
|
||||
public static final String PRO_COLUMN_REPLACE_DISABLE = "columnRenamingRule.disable"; // 替换 property
|
||||
|
||||
public static final String PRO_CLIENT_SUFFIX = "clientSuffix"; // client 结尾
|
||||
public static final String PRO_EXAMPLE_SUFFIX = "exampleSuffix"; // example 结尾
|
||||
public static final String PRO_MODEL_SUFFIX = "modelSuffix"; // model 结尾
|
||||
|
||||
private String tableSearchString;
|
||||
private String tableReplaceString;
|
||||
private boolean tableReplaceDisable;
|
||||
private String columnSearchString;
|
||||
private String columnReplaceString;
|
||||
private boolean columnReplaceDisable;
|
||||
|
||||
|
||||
private String clientSuffix; // client 结尾
|
||||
private String exampleSuffix; // example 结尾
|
||||
private String modelSuffix; // model 结尾
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @param warnings
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean validate(List<String> warnings) {
|
||||
Properties properties = this.getProperties();
|
||||
|
||||
this.tableSearchString = properties.getProperty(PRO_TABLE_SEARCH_STRING);
|
||||
this.tableReplaceString = properties.getProperty(PRO_TABLE_REPLACE_STRING);
|
||||
this.columnSearchString = properties.getProperty(PRO_COLUMN_SEARCH_STRING);
|
||||
this.columnReplaceString = properties.getProperty(PRO_COLUMN_REPLACE_STRING); // 和官方行为保持一致
|
||||
|
||||
this.exampleSuffix = properties.getProperty(PRO_EXAMPLE_SUFFIX);
|
||||
this.clientSuffix = properties.getProperty(PRO_CLIENT_SUFFIX);
|
||||
this.modelSuffix = properties.getProperty(PRO_MODEL_SUFFIX);
|
||||
|
||||
return super.validate(warnings);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表配置
|
||||
* @param introspectedTable
|
||||
*/
|
||||
@Override
|
||||
public void tableConfiguration(IntrospectedTable introspectedTable) {
|
||||
try {
|
||||
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||
FullyQualifiedTable fullyQualifiedTable = introspectedTable.getFullyQualifiedTable();
|
||||
|
||||
String tableReplaceDisable = tableConfiguration.getProperty(PRO_TABLE_REPLACE_DISABLE);
|
||||
this.tableReplaceDisable = tableReplaceDisable == null ? false : StringUtility.isTrue(tableReplaceDisable);
|
||||
String columnReplaceDisable = tableConfiguration.getProperty(PRO_COLUMN_REPLACE_DISABLE);
|
||||
this.columnReplaceDisable = columnReplaceDisable == null ? false : StringUtility.isTrue(columnReplaceDisable);
|
||||
|
||||
String javaClientInterfacePackage = (String) BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateJavaClientInterfacePackage");
|
||||
String sqlMapPackage = (String) BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateSqlMapPackage");
|
||||
String javaModelPackage = (String) BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateJavaModelPackage");
|
||||
// --------------------- table 重命名 ----------------------------
|
||||
if (tableConfiguration.getDomainObjectRenamingRule() == null
|
||||
&& this.tableSearchString != null && !this.tableReplaceDisable) {
|
||||
DomainObjectRenamingRule rule = new DomainObjectRenamingRule();
|
||||
rule.setSearchString(this.tableSearchString);
|
||||
rule.setReplaceString(this.tableReplaceString);
|
||||
tableConfiguration.setDomainObjectRenamingRule(rule);
|
||||
BeanUtils.setProperty(introspectedTable.getFullyQualifiedTable(), "domainObjectRenamingRule", rule);
|
||||
|
||||
// 重新初始化一下属性
|
||||
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateJavaClientAttributes");
|
||||
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateModelAttributes");
|
||||
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateXmlAttributes");
|
||||
}
|
||||
// TODO 官方bug临时修复
|
||||
if (tableConfiguration.getDomainObjectRenamingRule() != null) {
|
||||
String domainObjectName = fullyQualifiedTable.getDomainObjectName();
|
||||
// 首字母大写
|
||||
BeanUtils.setProperty(fullyQualifiedTable, "domainObjectName", getCamelCaseString(domainObjectName, true));
|
||||
|
||||
// 重新初始化一下属性
|
||||
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateJavaClientAttributes");
|
||||
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateModelAttributes");
|
||||
BeanUtils.invoke(introspectedTable, IntrospectedTable.class, "calculateXmlAttributes");
|
||||
}
|
||||
// --------------------- column 重命名 ---------------------------
|
||||
if (tableConfiguration.getColumnRenamingRule() == null
|
||||
&& this.columnSearchString != null && !this.columnReplaceDisable) {
|
||||
ColumnRenamingRule rule = new ColumnRenamingRule();
|
||||
rule.setSearchString(this.columnSearchString);
|
||||
rule.setReplaceString(this.columnReplaceString);
|
||||
tableConfiguration.setColumnRenamingRule(rule);
|
||||
|
||||
// introspectedTable 使用到的所有column过滤并替换
|
||||
this.renameColumns(introspectedTable.getAllColumns(), rule, tableConfiguration);
|
||||
}
|
||||
|
||||
// ---------------------- 后缀修正 -------------------------------
|
||||
// 1. client
|
||||
if (this.clientSuffix != null) {
|
||||
// mapper
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(javaClientInterfacePackage);
|
||||
sb.append('.');
|
||||
if (stringHasValue(tableConfiguration.getMapperName())) {
|
||||
sb.append(tableConfiguration.getMapperName());
|
||||
} else {
|
||||
if (stringHasValue(fullyQualifiedTable.getDomainObjectSubPackage())) {
|
||||
sb.append(fullyQualifiedTable.getDomainObjectSubPackage());
|
||||
sb.append('.');
|
||||
}
|
||||
sb.append(fullyQualifiedTable.getDomainObjectName());
|
||||
sb.append(this.clientSuffix);
|
||||
}
|
||||
introspectedTable.setMyBatis3JavaMapperType(sb.toString());
|
||||
// xml mapper namespace
|
||||
sb.setLength(0);
|
||||
sb.append(sqlMapPackage);
|
||||
sb.append('.');
|
||||
if (stringHasValue(tableConfiguration.getMapperName())) {
|
||||
sb.append(tableConfiguration.getMapperName());
|
||||
} else {
|
||||
sb.append(fullyQualifiedTable.getDomainObjectName());
|
||||
sb.append(this.clientSuffix);
|
||||
}
|
||||
introspectedTable.setMyBatis3FallbackSqlMapNamespace(sb.toString());
|
||||
// xml file
|
||||
sb.setLength(0);
|
||||
sb.append(fullyQualifiedTable.getDomainObjectName());
|
||||
sb.append(this.clientSuffix);
|
||||
sb.append(".xml");
|
||||
|
||||
introspectedTable.setMyBatis3XmlMapperFileName(sb.toString());
|
||||
}
|
||||
// 2. example
|
||||
if (this.exampleSuffix != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(javaModelPackage);
|
||||
sb.append('.');
|
||||
sb.append(fullyQualifiedTable.getDomainObjectName());
|
||||
sb.append(this.exampleSuffix);
|
||||
introspectedTable.setExampleType(sb.toString());
|
||||
}
|
||||
// 3. model
|
||||
if (this.modelSuffix != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(javaModelPackage);
|
||||
sb.append('.');
|
||||
sb.append(fullyQualifiedTable.getDomainObjectName());
|
||||
sb.append("Key");
|
||||
sb.append(this.modelSuffix);
|
||||
introspectedTable.setPrimaryKeyType(sb.toString());
|
||||
|
||||
sb.setLength(0);
|
||||
sb.append(javaModelPackage);
|
||||
sb.append('.');
|
||||
sb.append(fullyQualifiedTable.getDomainObjectName());
|
||||
sb.append(this.modelSuffix);
|
||||
introspectedTable.setBaseRecordType(sb.toString());
|
||||
|
||||
sb.setLength(0);
|
||||
sb.append(javaModelPackage);
|
||||
sb.append('.');
|
||||
sb.append(fullyQualifiedTable.getDomainObjectName());
|
||||
sb.append("WithBLOBs");
|
||||
sb.append(this.modelSuffix);
|
||||
introspectedTable.setRecordWithBLOBsType(sb.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* column rename
|
||||
* @param columns
|
||||
* @param rule
|
||||
* @param tc
|
||||
*/
|
||||
private void renameColumns(List<IntrospectedColumn> columns, ColumnRenamingRule rule, TableConfiguration tc) {
|
||||
Pattern pattern = Pattern.compile(rule.getSearchString());
|
||||
String replaceString = rule.getReplaceString();
|
||||
replaceString = replaceString == null ? "" : replaceString;
|
||||
|
||||
for (IntrospectedColumn introspectedColumn : columns) {
|
||||
String calculatedColumnName;
|
||||
if (pattern == null) {
|
||||
calculatedColumnName = introspectedColumn.getActualColumnName();
|
||||
} else {
|
||||
Matcher matcher = pattern.matcher(introspectedColumn.getActualColumnName());
|
||||
calculatedColumnName = matcher.replaceAll(replaceString);
|
||||
}
|
||||
|
||||
if (isTrue(tc.getProperty(PropertyRegistry.TABLE_USE_ACTUAL_COLUMN_NAMES))) {
|
||||
introspectedColumn.setJavaProperty(getValidPropertyName(calculatedColumnName));
|
||||
} else if (isTrue(tc.getProperty(PropertyRegistry.TABLE_USE_COMPOUND_PROPERTY_NAMES))) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(calculatedColumnName);
|
||||
sb.append('_');
|
||||
sb.append(getCamelCaseString(introspectedColumn.getRemarks(), true));
|
||||
introspectedColumn.setJavaProperty(getValidPropertyName(sb.toString()));
|
||||
} else {
|
||||
introspectedColumn.setJavaProperty(getCamelCaseString(calculatedColumnName, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import java.util.regex.Pattern;
|
||||
* @time:2017/6/6 15:18
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
@Deprecated
|
||||
public class TableRenamePlugin extends BasePlugin {
|
||||
public static final String PRO_SEARCH_STRING = "searchString"; // 查找 property
|
||||
public static final String PRO_REPLACE_STRING = "replaceString"; // 替换 property
|
||||
@@ -94,6 +95,7 @@ public class TableRenamePlugin extends BasePlugin {
|
||||
logger.error("itfsw:插件" + this.getClass().getTypeName() + "使用searchString、replaceString替换时异常!", e);
|
||||
}
|
||||
}
|
||||
super.initialized(introspectedTable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,7 +65,8 @@ public class UpsertPlugin extends BasePlugin {
|
||||
public boolean validate(List<String> warnings) {
|
||||
|
||||
// 插件使用前提是数据库为MySQL
|
||||
if ("com.mysql.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false) {
|
||||
if ("com.mysql.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false
|
||||
&& "com.mysql.cj.jdbc.Driver".equalsIgnoreCase(this.getContext().getJdbcConnectionConfiguration().getDriverClass()) == false) {
|
||||
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件使用前提是数据库为MySQL!");
|
||||
return false;
|
||||
}
|
||||
@@ -295,7 +296,7 @@ public class UpsertPlugin extends BasePlugin {
|
||||
foreachInsertColumns.addAttribute(new Attribute("collection", "selective"));
|
||||
foreachInsertColumns.addAttribute(new Attribute("item", "column"));
|
||||
foreachInsertColumns.addAttribute(new Attribute("separator", ","));
|
||||
foreachInsertColumns.addElement(new TextElement("${column.value}"));
|
||||
foreachInsertColumns.addElement(new TextElement("${column.escapedColumnName}"));
|
||||
|
||||
insertEle.addElement(foreachInsertColumns);
|
||||
|
||||
@@ -324,7 +325,7 @@ public class UpsertPlugin extends BasePlugin {
|
||||
for (int i = 0; i < columns1.size(); i++) {
|
||||
IntrospectedColumn introspectedColumn = columns.get(i);
|
||||
XmlElement check = new XmlElement("if");
|
||||
check.addAttribute(new Attribute("test", "'" + introspectedColumn.getActualColumnName() + "' == column.value"));
|
||||
check.addAttribute(new Attribute("test", "'" + introspectedColumn.getActualColumnName() + "'.toString() == column.value"));
|
||||
check.addElement(new TextElement(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.")));
|
||||
|
||||
foreachInsertColumnsCheck.addElement(check);
|
||||
@@ -342,7 +343,7 @@ public class UpsertPlugin extends BasePlugin {
|
||||
foreachSetColumns.addAttribute(new Attribute("collection", "selective"));
|
||||
foreachSetColumns.addAttribute(new Attribute("item", "column"));
|
||||
foreachSetColumns.addAttribute(new Attribute("separator", ","));
|
||||
foreachSetColumns.addElement(new TextElement("${column.value} = values(${column.value})"));
|
||||
foreachSetColumns.addElement(new TextElement("${column.escapedColumnName} = values(${column.escapedColumnName})"));
|
||||
|
||||
document.getRootElement().addElement(insertEle);
|
||||
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加batchUpsertSelective实现方法。");
|
||||
|
||||
@@ -19,7 +19,9 @@ package com.itfsw.mybatis.generator.plugins.utils;
|
||||
import com.itfsw.mybatis.generator.plugins.CommentPlugin;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.enhanced.TemplateCommentGenerator;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.hook.HookAggregator;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.hook.ITableConfigurationHook;
|
||||
import org.mybatis.generator.api.CommentGenerator;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.api.PluginAdapter;
|
||||
import org.mybatis.generator.config.Context;
|
||||
import org.mybatis.generator.config.PluginConfiguration;
|
||||
@@ -97,4 +99,17 @@ public class BasePlugin extends PluginAdapter {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @param introspectedTable
|
||||
*/
|
||||
@Override
|
||||
public void initialized(IntrospectedTable introspectedTable) {
|
||||
super.initialized(introspectedTable);
|
||||
if (StringUtility.stringHasValue(introspectedTable.getTableConfiguration().getAlias())){
|
||||
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "请不要配置alias属性,这个属性官方支持也很混乱,导致插件支持会存在问题!");
|
||||
}
|
||||
PluginTools.getHook(ITableConfigurationHook.class).tableConfiguration(introspectedTable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,14 +58,15 @@ public class BeanUtils {
|
||||
/**
|
||||
* 执行无参方法
|
||||
* @param bean
|
||||
* @param clazz
|
||||
* @param name
|
||||
* @return
|
||||
* @throws NoSuchMethodException
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static Object invoke(final Object bean, final String name) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
Method method = bean.getClass().getDeclaredMethod(name);
|
||||
public static Object invoke(final Object bean, Class clazz, final String name) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
Method method = clazz.getDeclaredMethod(name);
|
||||
method.setAccessible(true);
|
||||
return method.invoke(bean);
|
||||
}
|
||||
|
||||
+5
-1
@@ -52,11 +52,15 @@ public class XmlElementGeneratorTools {
|
||||
* @return the selectKey element
|
||||
*/
|
||||
public static Element getSelectKey(IntrospectedColumn introspectedColumn, GeneratedKey generatedKey) {
|
||||
return getSelectKey(introspectedColumn, generatedKey, null);
|
||||
}
|
||||
|
||||
public static Element getSelectKey(IntrospectedColumn introspectedColumn, GeneratedKey generatedKey, String prefix) {
|
||||
String identityColumnType = introspectedColumn.getFullyQualifiedJavaType().getFullyQualifiedName();
|
||||
|
||||
XmlElement answer = new XmlElement("selectKey");
|
||||
answer.addAttribute(new Attribute("resultType", identityColumnType));
|
||||
answer.addAttribute(new Attribute("keyProperty", introspectedColumn.getJavaProperty()));
|
||||
answer.addAttribute(new Attribute("keyProperty", (prefix == null ? "" : prefix) + introspectedColumn.getJavaProperty()));
|
||||
answer.addAttribute(new Attribute("order", generatedKey.getMyBatis3Order()));
|
||||
|
||||
answer.addElement(new TextElement(generatedKey.getRuntimeSqlStatement()));
|
||||
|
||||
@@ -43,7 +43,7 @@ import java.util.List;
|
||||
* @time:2018/4/27 11:33
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class HookAggregator implements IUpsertPluginHook, IModelBuilderPluginHook, IIncrementsPluginHook, IOptimisticLockerPluginHook, ISelectOneByExamplePluginHook {
|
||||
public class HookAggregator implements IUpsertPluginHook, IModelBuilderPluginHook, IIncrementsPluginHook, IOptimisticLockerPluginHook, ISelectOneByExamplePluginHook, ITableConfigurationHook {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(BasePlugin.class); // 日志
|
||||
private final static HookAggregator instance = new HookAggregator();
|
||||
private Context context;
|
||||
@@ -250,4 +250,13 @@ public class HookAggregator implements IUpsertPluginHook, IModelBuilderPluginHoo
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================= ITableConfigurationHook ==============================================
|
||||
|
||||
@Override
|
||||
public void tableConfiguration(IntrospectedTable introspectedTable) {
|
||||
if (!this.getPlugins(ITableConfigurationHook.class).isEmpty()) {
|
||||
this.getPlugins(ITableConfigurationHook.class).get(0).tableConfiguration(introspectedTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2018.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins.utils.hook;
|
||||
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
*
|
||||
* ---------------------------------------------------------------------------
|
||||
* @author: hewei
|
||||
* @time:2018/5/21 11:24
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public interface ITableConfigurationHook {
|
||||
/**
|
||||
* 表配置
|
||||
* @param introspectedTable
|
||||
*/
|
||||
void tableConfiguration(IntrospectedTable introspectedTable);
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2018.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins;
|
||||
|
||||
import com.itfsw.mybatis.generator.plugins.tools.*;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
*
|
||||
* ---------------------------------------------------------------------------
|
||||
* @author: hewei
|
||||
* @time:2018/5/29 15:56
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class BugFixedTest {
|
||||
/**
|
||||
* 在使用 ModelColumnPlugin 插件时遇到关键词column或者table定义了alias属性,插件没有正确取值
|
||||
*/
|
||||
@Test
|
||||
public void bug0001() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/bug-0001.xml");
|
||||
tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/bug-0001.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
|
||||
ObjectUtil tb = new ObjectUtil(loader, packagz + ".Tb");
|
||||
tb.set("id", 121L);
|
||||
tb.set("inc", "inc_001");
|
||||
tb.set("table", "tb");
|
||||
// selective
|
||||
ObjectUtil TbColumnId = new ObjectUtil(loader, packagz + ".Tb$Column#id");
|
||||
ObjectUtil TbColumnInc = new ObjectUtil(loader, packagz + ".Tb$Column#inc");
|
||||
ObjectUtil TbColumnTable = new ObjectUtil(loader, packagz + ".Tb$Column#table");
|
||||
Object columns = Array.newInstance(TbColumnInc.getCls(), 3);
|
||||
Array.set(columns, 0, TbColumnId.getObject());
|
||||
Array.set(columns, 1, TbColumnInc.getObject());
|
||||
Array.set(columns, 2, TbColumnTable.getObject());
|
||||
|
||||
// sql
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "insertSelective", tb.getObject(), columns);
|
||||
Assert.assertEquals(sql, "insert into tb ( id , field1 , `table` ) values ( 121 , 'inc_001' , 'tb' )");
|
||||
Object result = tbMapper.invoke("insertSelective", tb.getObject(), columns);
|
||||
Assert.assertEquals(result, 1);
|
||||
|
||||
// 执行查询
|
||||
ObjectUtil tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdLessThan", 160l);
|
||||
tbExample.set("orderByClause", TbColumnTable.invoke("asc"));
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExampleSelective", tbExample.getObject(), columns);
|
||||
Assert.assertEquals(sql, "select id , field1 , `table` from tb Test WHERE ( Test.id < '160' ) order by `table` ASC");
|
||||
ObjectUtil result1 = new ObjectUtil(((List) tbMapper.invoke("selectByExampleSelective", tbExample.getObject(), columns)).get(0));
|
||||
Assert.assertEquals(result1.get("table"), "tb");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* insertSelective 因为集成SelectiveEnhancedPlugin,传入参数变成map,自增ID返回要修正
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void bug0002() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/bug-0002.xml");
|
||||
tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/bug-0002.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
|
||||
ObjectUtil tb = new ObjectUtil(loader, packagz + ".Tb");
|
||||
tb.set("field1", "ts1");
|
||||
|
||||
// selective
|
||||
ObjectUtil TbColumnField1 = new ObjectUtil(loader, packagz + ".Tb$Column#field1");
|
||||
Object columns = Array.newInstance(TbColumnField1.getCls(), 1);
|
||||
Array.set(columns, 0, TbColumnField1.getObject());
|
||||
|
||||
// sql
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "insertSelective", tb.getObject(), columns);
|
||||
Assert.assertEquals(sql, "insert into tb ( field1 ) values ( 'ts1' )");
|
||||
Object result = tbMapper.invoke("insertSelective", tb.getObject(), columns);
|
||||
Assert.assertEquals(result, 1);
|
||||
// 自增ID
|
||||
Assert.assertEquals(tb.get("id"), 1L);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* typeHandler 导致的问题
|
||||
*/
|
||||
@Test
|
||||
public void issues36() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-36.xml");
|
||||
tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-36.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
// Example 编译报错
|
||||
new ObjectUtil(loader, packagz + ".TbExample");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 乐观锁插件好像变量作用域问题导致,前一个表的配置会影响后一个表配置
|
||||
*/
|
||||
@Test
|
||||
public void issues39() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-39.xml");
|
||||
tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-39.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
// 第一个生成对应方法
|
||||
Assert.assertEquals(tbMapper.getMethods(OptimisticLockerPlugin.METHOD_DELETE_WITH_VERSION_BY_EXAMPLE).size(), 1);
|
||||
|
||||
ObjectUtil tb1Mapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".Tb1Mapper")));
|
||||
// 第一个生成对应方法
|
||||
Assert.assertEquals(tb1Mapper.getMethods(OptimisticLockerPlugin.METHOD_DELETE_WITH_VERSION_BY_EXAMPLE).size(), 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,9 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.lang.reflect.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
@@ -42,7 +40,7 @@ public class ExampleEnhancedPluginTest {
|
||||
* 初始化数据库
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void init() throws SQLException, IOException, ClassNotFoundException {
|
||||
public static void init() throws SQLException, IOException {
|
||||
DBHelper.createDB("scripts/ExampleEnhancedPlugin/init.sql");
|
||||
}
|
||||
|
||||
@@ -62,7 +60,7 @@ public class ExampleEnhancedPluginTest {
|
||||
|
||||
// 调用example方法能正常返回
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExampleCriteria.invoke("example"));
|
||||
Assert.assertEquals(sql, "select id, field1 from tb");
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -85,7 +83,7 @@ public class ExampleEnhancedPluginTest {
|
||||
tbExample.invoke("orderBy", order); // 可变参数方法直接设置order by
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1 from tb order by id desc , field1 asc");
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb order by id desc , field1 asc");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -98,37 +96,109 @@ public class ExampleEnhancedPluginTest {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleEnhancedPlugin/mybatis-generator.xml");
|
||||
tool.generate(new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) {
|
||||
try {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
|
||||
// 1. andIf true
|
||||
ObjectUtil tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil tbExampleCriteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
|
||||
// 代理实现接口
|
||||
Object criteriaAdd = Proxy.newProxyInstance(loader, new Class[]{
|
||||
loader.loadClass(packagz + ".TbExample$Criteria$ICriteriaAdd")
|
||||
}, new TestInvocationHandler());
|
||||
Method method = tbExampleCriteria.getMethods("andIf").get(0);
|
||||
method.invoke(tbExampleCriteria.getObject(), true, criteriaAdd);
|
||||
// 1. andIf true
|
||||
ObjectUtil tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil tbExampleCriteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1 from tb WHERE ( id = '5' )");
|
||||
// 代理实现接口
|
||||
Object criteriaAdd = Proxy.newProxyInstance(loader, new Class[]{
|
||||
loader.loadClass(packagz + ".TbExample$Criteria$ICriteriaAdd")
|
||||
}, new TestInvocationHandler());
|
||||
Method method = tbExampleCriteria.getMethods("andIf").get(0);
|
||||
method.invoke(tbExampleCriteria.getObject(), true, criteriaAdd);
|
||||
|
||||
// 2. andIf false
|
||||
ObjectUtil tbExample1 = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil tbExampleCriteria1 = new ObjectUtil(tbExample1.invoke("createCriteria"));
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb WHERE ( id = '5' )");
|
||||
|
||||
method = tbExampleCriteria1.getMethods("andIf").get(0);
|
||||
method.invoke(tbExampleCriteria1.getObject(), false, criteriaAdd);
|
||||
// 2. andIf false
|
||||
ObjectUtil tbExample1 = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil tbExampleCriteria1 = new ObjectUtil(tbExample1.invoke("createCriteria"));
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample1.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1 from tb");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Assert.assertTrue(false);
|
||||
}
|
||||
method = tbExampleCriteria1.getMethods("andIf").get(0);
|
||||
method.invoke(tbExampleCriteria1.getObject(), false, criteriaAdd);
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample1.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试配置ModelColumnPlugin插件
|
||||
*/
|
||||
@Test
|
||||
public void testWithModelColumnPlugin() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleEnhancedPlugin/mybatis-generator-with-ModelColumnPlugin.xml");
|
||||
tool.generate(new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
|
||||
ObjectUtil columnField2 = new ObjectUtil(loader, packagz + ".Tb$Column#field2");
|
||||
|
||||
// 1. EqualTo
|
||||
ObjectUtil tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdEqualToColumn", columnField2.getObject());
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb WHERE ( id = field2 )");
|
||||
List list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(list.size(), 1);
|
||||
|
||||
// 2. NotEqualTo
|
||||
tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdNotEqualToColumn", columnField2.getObject());
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb WHERE ( id <> field2 )");
|
||||
list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(list.size(), 9);
|
||||
|
||||
// 3. GreaterThan
|
||||
tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdGreaterThanColumn", columnField2.getObject());
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb WHERE ( id > field2 )");
|
||||
list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(list.size(), 4);
|
||||
|
||||
// 4. GreaterThanOrEqualTo
|
||||
tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdGreaterThanOrEqualToColumn", columnField2.getObject());
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb WHERE ( id >= field2 )");
|
||||
list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(list.size(), 5);
|
||||
|
||||
// 5. LessThan
|
||||
tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdLessThanColumn", columnField2.getObject());
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb WHERE ( id < field2 )");
|
||||
list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(list.size(), 5);
|
||||
|
||||
// 6. LessThanOrEqualTo
|
||||
tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdLessThanOrEqualToColumn", columnField2.getObject());
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, field2 from tb WHERE ( id <= field2 )");
|
||||
list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(list.size(), 6);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* Copyright (c) 2018.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins;
|
||||
|
||||
import com.itfsw.mybatis.generator.plugins.tools.*;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mybatis.generator.api.GeneratedJavaFile;
|
||||
import org.mybatis.generator.api.GeneratedXmlFile;
|
||||
import org.mybatis.generator.api.MyBatisGenerator;
|
||||
import org.mybatis.generator.api.dom.java.Field;
|
||||
import org.mybatis.generator.api.dom.java.TopLevelClass;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
*
|
||||
* ---------------------------------------------------------------------------
|
||||
* @author: hewei
|
||||
* @time:2018/5/22 13:22
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class TableRenameConfigurationPluginTest {
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
DBHelper.createDB("scripts/TableRenameConfigurationPlugin/init.sql");
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试domainObjectRenamingRule
|
||||
*/
|
||||
@Test
|
||||
public void testDomainObjectRenamingRule() throws Exception {
|
||||
// 规则 ^T 替换成空,也就是去掉前缀
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenameConfigurationPlugin/mybatis-generator-with-domainObjectRenamingRule-relacePrefix.xml");
|
||||
MyBatisGenerator myBatisGenerator = tool.generate();
|
||||
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
|
||||
String name = file.getCompilationUnit().getType().getShortName();
|
||||
if (!name.matches("B.*")){
|
||||
Assert.assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
// 规则 ^T 替换成 Test
|
||||
tool = MyBatisGeneratorTool.create("scripts/TableRenameConfigurationPlugin/mybatis-generator-with-domainObjectRenamingRule.xml");
|
||||
myBatisGenerator = tool.generate();
|
||||
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
|
||||
String name = file.getCompilationUnit().getType().getShortName();
|
||||
if (!(name.matches("Testb.*") || name.matches("TbBlobs.*"))){
|
||||
Assert.assertTrue(false);
|
||||
}
|
||||
}
|
||||
// 执行一条语句确认其可用
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/TableRenameConfigurationPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TestbMapper")));
|
||||
|
||||
ObjectUtil tbExample = new ObjectUtil(loader, packagz + ".TestbExample");
|
||||
ObjectUtil criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdLessThan", 4L);
|
||||
|
||||
// sql
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, inc_f1, inc_f2, inc_f3 from tb WHERE ( id < '4' )");
|
||||
// 执行
|
||||
List list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(list.size(), 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试columnRenamingRule
|
||||
*/
|
||||
@Test
|
||||
public void testColumnRenamingRule() throws Exception {
|
||||
// 规则 ^T 替换成 Test
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenameConfigurationPlugin/mybatis-generator-with-columnRenamingRule.xml");
|
||||
MyBatisGenerator myBatisGenerator = tool.generate();
|
||||
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
|
||||
if (file.getFileName().equals("Tb.java")){
|
||||
int count = 0;
|
||||
for (Field field : ((TopLevelClass)(file.getCompilationUnit())).getFields()){
|
||||
if (field.getName().startsWith("increment")){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(count, 3);
|
||||
}
|
||||
if (file.getFileName().equals("TbBlobs.java")){
|
||||
int count = 0;
|
||||
for (Field field : ((TopLevelClass)(file.getCompilationUnit())).getFields()){
|
||||
if (field.getName().startsWith("increment")){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(count, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// 执行一条语句确认其可用
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/TableRenameConfigurationPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
|
||||
ObjectUtil tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdEqualTo", 4L);
|
||||
|
||||
ObjectUtil tb = new ObjectUtil(loader, packagz + ".Tb");
|
||||
tb.set("id", 4L);
|
||||
tb.set("field1", "ts1");
|
||||
tb.set("incrementF1", 5L);
|
||||
|
||||
// sql
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "updateByExample", tb.getObject(), tbExample.getObject());
|
||||
Assert.assertEquals(sql, "update tb set id = 4, field1 = 'ts1', inc_f1 = 5, inc_f2 = null, inc_f3 = null WHERE ( id = '4' )");
|
||||
// 执行
|
||||
int count = (int) tbMapper.invoke("updateByExample", tb.getObject(), tbExample.getObject());
|
||||
Assert.assertEquals(count, 1);
|
||||
// 执行结果查询
|
||||
List list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
ObjectUtil result = new ObjectUtil(list.get(0));
|
||||
Assert.assertEquals(result.get("id"), 4L);
|
||||
Assert.assertEquals(result.get("field1"), "ts1");
|
||||
Assert.assertEquals(result.get("incrementF1"), 5L);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试clientSuffix
|
||||
*/
|
||||
@Test
|
||||
public void testClientSuffix() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenameConfigurationPlugin/mybatis-generator-with-clientSuffix.xml");
|
||||
MyBatisGenerator myBatisGenerator = tool.generate();
|
||||
|
||||
boolean find = false;
|
||||
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
|
||||
String name = file.getCompilationUnit().getType().getShortName();
|
||||
if (name.equals("TbDao")){
|
||||
find = true;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(find);
|
||||
|
||||
find = false;
|
||||
for (GeneratedXmlFile file : myBatisGenerator.getGeneratedXmlFiles()) {
|
||||
String name = file.getFileName();
|
||||
if (name.equals("TbDao.xml")){
|
||||
find = true;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(find);
|
||||
|
||||
// 执行一条语句确认其可用
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/TableRenameConfigurationPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbDao = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbDao")));
|
||||
|
||||
ObjectUtil tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdLessThan", 4L);
|
||||
|
||||
// sql
|
||||
String sql = SqlHelper.getFormatMapperSql(tbDao.getObject(), "selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, inc_f1, inc_f2, inc_f3 from tb WHERE ( id < '4' )");
|
||||
// 执行
|
||||
List list = (List) tbDao.invoke("selectByExample", tbExample.getObject());
|
||||
Assert.assertEquals(list.size(), 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试exampleSuffix
|
||||
*/
|
||||
@Test
|
||||
public void testExampleSuffix() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenameConfigurationPlugin/mybatis-generator-with-exampleSuffix.xml");
|
||||
MyBatisGenerator myBatisGenerator = tool.generate();
|
||||
|
||||
boolean find = false;
|
||||
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
|
||||
String name = file.getCompilationUnit().getType().getShortName();
|
||||
if (name.equals("TbQuery")){
|
||||
find = true;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(find);
|
||||
// 执行一条语句确认其可用
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/TableRenameConfigurationPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
|
||||
ObjectUtil tbQuery = new ObjectUtil(loader, packagz + ".TbQuery");
|
||||
ObjectUtil criteria = new ObjectUtil(tbQuery.invoke("createCriteria"));
|
||||
criteria.invoke("andIdLessThan", 4L);
|
||||
|
||||
// sql
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbQuery.getObject());
|
||||
Assert.assertEquals(sql, "select id, field1, inc_f1, inc_f2, inc_f3 from tb WHERE ( id < '4' )");
|
||||
// 执行
|
||||
List list = (List) tbMapper.invoke("selectByExample", tbQuery.getObject());
|
||||
Assert.assertEquals(list.size(), 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试modelSuffix
|
||||
*/
|
||||
@Test
|
||||
public void testModelSuffix() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenameConfigurationPlugin/mybatis-generator-with-modelSuffix.xml");
|
||||
MyBatisGenerator myBatisGenerator = tool.generate();
|
||||
|
||||
boolean find = false;
|
||||
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
|
||||
String name = file.getCompilationUnit().getType().getShortName();
|
||||
if (name.equals("TbEntity")){
|
||||
find = true;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(find);
|
||||
// 执行一条语句确认其可用
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/TableRenameConfigurationPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
|
||||
ObjectUtil tbExample = new ObjectUtil(loader, packagz + ".TbExample");
|
||||
ObjectUtil criteria = new ObjectUtil(tbExample.invoke("createCriteria"));
|
||||
criteria.invoke("andIdEqualTo", 4L);
|
||||
|
||||
ObjectUtil tb = new ObjectUtil(loader, packagz + ".TbEntity");
|
||||
tb.set("id", 4L);
|
||||
tb.set("field1", "ts1");
|
||||
tb.set("incF1", 5L);
|
||||
|
||||
// sql
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "updateByExample", tb.getObject(), tbExample.getObject());
|
||||
Assert.assertEquals(sql, "update tb set id = 4, field1 = 'ts1', inc_f1 = 5, inc_f2 = null, inc_f3 = null WHERE ( id = '4' )");
|
||||
// 执行
|
||||
int count = (int) tbMapper.invoke("updateByExample", tb.getObject(), tbExample.getObject());
|
||||
Assert.assertEquals(count, 1);
|
||||
// 执行结果查询
|
||||
List list = (List) tbMapper.invoke("selectByExample", tbExample.getObject());
|
||||
ObjectUtil result = new ObjectUtil(list.get(0));
|
||||
Assert.assertEquals(result.get("id"), 4L);
|
||||
Assert.assertEquals(result.get("field1"), "ts1");
|
||||
Assert.assertEquals(result.get("incF1"), 5L);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Navicat MySQL Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Version : 50617
|
||||
Source Host : localhost:3306
|
||||
Source Database : mybatis-generator-plugin
|
||||
|
||||
Target Server Type : MYSQL
|
||||
Target Server Version : 50617
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 2017-06-27 11:17:08
|
||||
*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb`;
|
||||
CREATE TABLE `tb` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int DEFAULT NULL,
|
||||
`table` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<property name="autoDelimitKeywords" value="true"/>
|
||||
<property name="beginningDelimiter" value="`"/>
|
||||
<property name="endingDelimiter" value="`"/>
|
||||
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.SelectiveEnhancedPlugin"/>
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.SelectSelectivePlugin"/>
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.ModelColumnPlugin"/>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb" alias="Test">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
<columnOverride column="field1" property="inc"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Navicat MySQL Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Version : 50617
|
||||
Source Host : localhost:3306
|
||||
Source Database : mybatis-generator-plugin
|
||||
|
||||
Target Server Type : MYSQL
|
||||
Target Server Version : 50617
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 2017-06-27 11:17:08
|
||||
*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb`;
|
||||
CREATE TABLE `tb` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<property name="autoDelimitKeywords" value="true"/>
|
||||
<property name="beginningDelimiter" value="`"/>
|
||||
<property name="endingDelimiter" value="`"/>
|
||||
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.SelectiveEnhancedPlugin"/>
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.ModelColumnPlugin"/>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Navicat MySQL Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Version : 50617
|
||||
Source Host : localhost:3306
|
||||
Source Database : mybatis-generator-plugin
|
||||
|
||||
Target Server Type : MYSQL
|
||||
Target Server Version : 50617
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 2017-06-27 11:17:08
|
||||
*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb`;
|
||||
CREATE TABLE `tb` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`t_date` date DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<property name="autoDelimitKeywords" value="true"/>
|
||||
<property name="beginningDelimiter" value="`"/>
|
||||
<property name="endingDelimiter" value="`"/>
|
||||
|
||||
<!-- 数据Model属性对应Column获取插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.ModelColumnPlugin"/>
|
||||
<!-- Selective选择插入更新增强插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.SelectiveEnhancedPlugin"/>
|
||||
<!-- Example Criteria 增强插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin"/>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<columnOverride column="field1" javaType="java.sql.Array" typeHandler="org.apache.ibatis.type.ArrayTypeHandler"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Navicat MySQL Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Version : 50617
|
||||
Source Host : localhost:3306
|
||||
Source Database : mybatis-generator-plugin
|
||||
|
||||
Target Server Type : MYSQL
|
||||
Target Server Version : 50617
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 2017-06-27 11:17:08
|
||||
*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb`;
|
||||
CREATE TABLE `tb` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`vs` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb1
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb1`;
|
||||
CREATE TABLE `tb1` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`vs` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<property name="autoDelimitKeywords" value="true"/>
|
||||
<property name="beginningDelimiter" value="`"/>
|
||||
<property name="endingDelimiter" value="`"/>
|
||||
|
||||
<!-- 乐观锁插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.OptimisticLockerPlugin"></plugin>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<property name="versionColumn" value="vs"/>
|
||||
</table>
|
||||
<table tableName="tb1">
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
@@ -22,19 +22,20 @@ DROP TABLE IF EXISTS `tb`;
|
||||
CREATE TABLE `tb` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` bigint(20) NOT NULL COMMENT '注释3',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
-- ----------------------------
|
||||
INSERT INTO `tb` VALUES ('1', 'f1');
|
||||
INSERT INTO `tb` VALUES ('2', 'f2');
|
||||
INSERT INTO `tb` VALUES ('3', 'f3');
|
||||
INSERT INTO `tb` VALUES ('4', 'f4');
|
||||
INSERT INTO `tb` VALUES ('5', 'f5');
|
||||
INSERT INTO `tb` VALUES ('6', 'f6');
|
||||
INSERT INTO `tb` VALUES ('7', 'f7');
|
||||
INSERT INTO `tb` VALUES ('8', 'f8');
|
||||
INSERT INTO `tb` VALUES ('9', 'f9');
|
||||
INSERT INTO `tb` VALUES ('10', 'f10');
|
||||
INSERT INTO `tb` VALUES ('1', 'f1', '1');
|
||||
INSERT INTO `tb` VALUES ('2', 'f2', '1');
|
||||
INSERT INTO `tb` VALUES ('3', 'f3', '1');
|
||||
INSERT INTO `tb` VALUES ('4', 'f4', '1');
|
||||
INSERT INTO `tb` VALUES ('5', 'f5', '1');
|
||||
INSERT INTO `tb` VALUES ('6', 'f6', '100');
|
||||
INSERT INTO `tb` VALUES ('7', 'f7', '100');
|
||||
INSERT INTO `tb` VALUES ('8', 'f8', '100');
|
||||
INSERT INTO `tb` VALUES ('9', 'f9', '100');
|
||||
INSERT INTO `tb` VALUES ('10', 'f10', '100');
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin"/>
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.ModelColumnPlugin"/>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
Navicat MySQL Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Version : 50617
|
||||
Source Host : localhost:3306
|
||||
Source Database : mybatis-generator-plugin
|
||||
|
||||
Target Server Type : MYSQL
|
||||
Target Server Version : 50617
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 2017-07-05 17:21:41
|
||||
*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb`;
|
||||
CREATE TABLE `tb` (
|
||||
`id` bigint(20) NOT NULL COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`inc_f1` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f2` bigint(20) DEFAULT '0',
|
||||
`inc_f3` bigint(20) DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
-- ----------------------------
|
||||
INSERT INTO `tb` VALUES ('1', 'fd1', '0', '0', '0');
|
||||
INSERT INTO `tb` VALUES ('2', 'fd2', '1', '2', '3');
|
||||
INSERT INTO `tb` VALUES ('3', null, '3', '2', '1');
|
||||
INSERT INTO `tb` VALUES ('4', 'fd3', '1', '1', '1');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb_blobs
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb_blobs`;
|
||||
CREATE TABLE `tb_blobs` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL,
|
||||
`field2` longtext COMMENT '注释2',
|
||||
`field3` longtext,
|
||||
`inc_f1` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
-- ----------------------------
|
||||
INSERT INTO `tb_blobs` VALUES ('1', 'fd1', null, null, '1', '2', '3');
|
||||
INSERT INTO `tb_blobs` VALUES ('2', null, 'fd2', null, '3', '2', '1');
|
||||
INSERT INTO `tb_blobs` VALUES ('3', null, null, 'fd3', '1', '1', '1');
|
||||
INSERT INTO `tb_blobs` VALUES ('4', 'fd4', 'fd5', 'fd6', '0', '0', '0');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb_keys
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb_keys`;
|
||||
CREATE TABLE `tb_keys` (
|
||||
`key1` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`key2` varchar(255) NOT NULL,
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
`inc_f1` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
-- ----------------------------
|
||||
INSERT INTO `tb_keys` VALUES ('1', 'k1', 'fd1', null, '1', '2', '3');
|
||||
INSERT INTO `tb_keys` VALUES ('2', 'k2', null, '2', '3', '2', '1');
|
||||
INSERT INTO `tb_keys` VALUES ('3', 'k3', null, null, '1', '1', '1');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb_single_blob
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb_single_blob`;
|
||||
CREATE TABLE `tb_single_blob` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` longtext COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
`inc_f1` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_single_blob
|
||||
-- ----------------------------
|
||||
INSERT INTO `tb_single_blob` VALUES ('1', 'fd1', '0', '1', '2', '3');
|
||||
INSERT INTO `tb_single_blob` VALUES ('2', null, null, '3', '2', '1');
|
||||
INSERT INTO `tb_single_blob` VALUES ('3', null, null, '1', '1', '1');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb_key_word
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb_key_word`;
|
||||
CREATE TABLE `tb_key_word` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
`inc_f1` bigint(20) NOT NULL DEFAULT '0',
|
||||
`update` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_key_word
|
||||
-- ----------------------------
|
||||
INSERT INTO `tb_key_word` VALUES ('1', '0', '0', '1');
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<property name="clientSuffix" value="Dao"/>
|
||||
</plugin>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
<table tableName="tb_keys"/>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<property name="columnRenamingRule.searchString" value="^inc_"/>
|
||||
<property name="columnRenamingRule.replaceString" value="Increment_"/>
|
||||
</plugin>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
<table tableName="tb_blobs">
|
||||
<property name="columnRenamingRule.disable" value="true"/>
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<property name="domainObjectRenamingRule.searchString" value="^T"/>
|
||||
<property name="domainObjectRenamingRule.replaceString" value=""/>
|
||||
</plugin>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<property name="domainObjectRenamingRule.searchString" value="^T"/>
|
||||
<property name="domainObjectRenamingRule.replaceString" value="Test"/>
|
||||
</plugin>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
<table tableName="tb_blobs">
|
||||
<property name="domainObjectRenamingRule.disable" value="true"/>
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<property name="exampleSuffix" value="Query"/>
|
||||
</plugin>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
<table tableName="tb_keys"/>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<property name="modelSuffix" value="Entity"/>
|
||||
</plugin>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
<table tableName="tb_keys"/>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2018.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin">
|
||||
<property name="searchString" value="^"/>
|
||||
<property name="replaceString" value="DB1"/>
|
||||
<property name="suffixForMapper" value="Dao"/>
|
||||
</plugin>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<property name="incrementsColumns" value="inc_f1"/>
|
||||
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
<table tableName="tb_keys">
|
||||
<property name="incrementsColumns" value=" inc_f1, inc_f2, inc_f3 "/>
|
||||
</table>
|
||||
<table tableName="tb_blobs">
|
||||
<property name="incrementsColumns" value="inc_f1,inc_f3"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
Reference in New Issue
Block a user