Compare commits

..
20 Commits
Author SHA1 Message Date
hewei b48c5c4195 [maven-release-plugin] prepare release V1.2.6 2018-05-28 17:54:13 +08:00
hewei 0a94a3d811 TableRenameConfigurationPlugin 2018-05-28 17:53:19 +08:00
hewei 7d266d192d TableRenameConfigurationPlugin 2018-05-28 17:52:32 +08:00
hewei b25c6806c7 Merge branch 'master' of https://github.com/itfsw/mybatis-generator-plugin 2018-05-28 17:50:44 +08:00
hewei 72f254b018 [maven-release-plugin] prepare release V1.2.6 2018-05-28 17:49:11 +08:00
hewei 0f5547a23d TableRenameConfigurationPlugin 2018-05-28 17:48:15 +08:00
hewei 4031668d26 [maven-release-plugin] prepare release V1.2.6 2018-05-28 17:39:54 +08:00
hewei 464959ef55 TableRenameConfigurationPlugin 2018-05-28 17:33:06 +08:00
hewei 074576f60e 官方domainObjectRenamingRule的bug修复 2018-05-28 17:14:29 +08:00
hewei abc2ef16b0 TableRenameConfigurationPlugin 2018-05-28 16:35:49 +08:00
hewei 2878b98290 TableConfigurationPlugin 测试用例 2018-05-28 15:59:00 +08:00
hewei 2b326a2fe3 TableConfigurationPlugin 测试用例 2018-05-28 15:49:35 +08:00
hewei 87519edc0e TableConfigurationPlugin 测试用例 2018-05-28 15:17:33 +08:00
hewei e0614069be TableConfigurationPlugin 测试用例 2018-05-28 14:37:54 +08:00
何伟 f29a30179e Update README.md 2018-05-28 09:22:55 +08:00
何伟 3e1c68a5b7 分页插件文档 2018-05-28 09:22:03 +08:00
hewei caa5144db0 TableConfigurationPlugin 2018-05-22 16:52:38 +08:00
何伟 8588c99189 过期两个插件TablePrefixPlugin、TableRenamePlugin,新版官方已提供domainObjectRenamingRule支持 2018-05-22 11:35:42 +08:00
hewei 6c832e4981 V1.2.5 2018-05-18 11:39:08 +08:00
hewei 2c41fd735e [maven-release-plugin] prepare for next development iteration 2018-05-18 11:23:43 +08:00
21 changed files with 1233 additions and 8 deletions
+99 -3
View File
@@ -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-乐观锁插件)
* [表重命名配置插件(TableConfigurationPlugin)](#18-表重命名配置插件)
---------------------------------------
Maven引用:
@@ -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分页插件 -->
@@ -537,6 +540,7 @@ 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()
.field1(1)
@@ -568,6 +572,28 @@ public class Test {
.delFlag(Tb.DEL_FLAG_ON)
.build();
int k6 = this.tbMapper.upsertWithBLOBs(tb);
// --------------------------------- allowBatchUpsert=true ------------------------------
List<Tb> list = new ArrayList<>();
list.add(
new Tb.Builder()
.field1(0)
.field2("xx0")
.field3(0)
.field4(new Date())
.build()
);
list.add(
new 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)); // 排除某些列
}
}
```
@@ -631,7 +657,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 +706,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
@@ -1181,4 +1218,63 @@ public class Test {
// 对应生成的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>
```
+2 -2
View File
@@ -3,7 +3,7 @@
<groupId>com.itfsw</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>1.2.5</version>
<version>1.2.6</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.6</tag>
</scm>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++distribution++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@@ -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();
@@ -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);
@@ -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<>());
// 读取并验证版本列
@@ -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);
}
}
@@ -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);
}
/**
@@ -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,14 @@ public class BasePlugin extends PluginAdapter {
return true;
}
/**
* {@inheritDoc}
* @param introspectedTable
*/
@Override
public void initialized(IntrospectedTable introspectedTable) {
super.initialized(introspectedTable);
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);
}
@@ -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);
}
}
}
@@ -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,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,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');
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>