Commit 5cbb85bd authored by hewei's avatar hewei

LombokPlugin 配合 IncrementsPlugin

parent 8922abde
......@@ -17,6 +17,9 @@
package com.itfsw.mybatis.generator.plugins;
import com.itfsw.mybatis.generator.plugins.utils.BasePlugin;
import com.itfsw.mybatis.generator.plugins.utils.IntrospectedTableTools;
import com.itfsw.mybatis.generator.plugins.utils.PluginTools;
import com.itfsw.mybatis.generator.plugins.utils.hook.ILombokPluginHook;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Method;
......@@ -79,7 +82,8 @@ public class LombokPlugin extends BasePlugin {
}
// @Builder
if (this.hasBuilder) {
List<IntrospectedColumn> columns = IntrospectedTableTools.getModelBaseRecordClomns(introspectedTable);
if (this.hasBuilder && PluginTools.getHook(ILombokPluginHook.class).modelBaseRecordBuilderClassGenerated(topLevelClass, columns, introspectedTable)) {
// 有子类或者父类
if (introspectedTable.getRules().generateRecordWithBLOBsClass() || introspectedTable.getRules().generatePrimaryKeyClass() || topLevelClass.getSuperClass() != null) {
this.addAnnotations(topLevelClass, EnumLombokAnnotations.SUPER_BUILDER);
......@@ -114,7 +118,8 @@ public class LombokPlugin extends BasePlugin {
}
// @Builder
if (this.hasBuilder) {
List<IntrospectedColumn> columns = introspectedTable.getPrimaryKeyColumns();
if (this.hasBuilder && PluginTools.getHook(ILombokPluginHook.class).modelPrimaryKeyBuilderClassGenerated(topLevelClass, columns, introspectedTable)) {
// 有子类或者父类
if (introspectedTable.getRules().generateRecordWithBLOBsClass() || introspectedTable.getRules().generateBaseRecordClass() || topLevelClass.getSuperClass() != null) {
this.addAnnotations(topLevelClass, EnumLombokAnnotations.SUPER_BUILDER);
......@@ -149,7 +154,8 @@ public class LombokPlugin extends BasePlugin {
}
// @Builder
if (this.hasBuilder) {
List<IntrospectedColumn> columns = introspectedTable.getBLOBColumns();
if (this.hasBuilder && PluginTools.getHook(ILombokPluginHook.class).modelRecordWithBLOBsBuilderClassGenerated(topLevelClass, columns, introspectedTable)) {
// 有子类或者父类
if (introspectedTable.getRules().generateBaseRecordClass() || introspectedTable.getRules().generatePrimaryKeyClass() || topLevelClass.getSuperClass() != null) {
this.addAnnotations(topLevelClass, EnumLombokAnnotations.SUPER_BUILDER);
......@@ -216,6 +222,9 @@ public class LombokPlugin extends BasePlugin {
ALL_ARGS_CONSTRUCTOR("@AllArgsConstructor", "lombok.AllArgsConstructor"),
NO_ARGS_CONSTRUCTOR("@NoArgsConstructor", "lombok.NoArgsConstructor"),
EQUALS_AND_HASH_CODE_CALL_SUPER("@EqualsAndHashCode(callSuper = true)", "lombok.EqualsAndHashCode"),
SETTER("@Setter", "lombok.Setter"),
ACCESSORS_FLUENT_TRUE("@Accessors(fluent = true)", "lombok.experimental.Accessors"),
TO_STRING("@ToString", "lombok.ToString"),
TO_STRING_CALL_SUPER("@ToString(callSuper = true)", "lombok.ToString");
private final String annotation;
......
......@@ -28,12 +28,12 @@ import org.mybatis.generator.internal.util.StringUtility;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
/**
* ---------------------------------------------------------------------------
* IntrospectedTable 的一些拓展增强
* ---------------------------------------------------------------------------
*
* @author: hewei
* @time:2017/6/13 13:48
* ---------------------------------------------------------------------------
......@@ -42,7 +42,6 @@ public class IntrospectedTableTools {
/**
* 设置DomainObjectName和MapperName
*
* @param introspectedTable
* @param context
* @param domainObjectName
......@@ -84,7 +83,6 @@ public class IntrospectedTableTools {
/**
* 安全获取column 通过正则获取的name可能包含beginningDelimiter&&endingDelimiter
*
* @param introspectedTable
* @param columnName
* @return
......@@ -104,4 +102,49 @@ public class IntrospectedTableTools {
return introspectedTable.getColumn(columnName);
}
/**
* 获取生成model baseRecord的列
* @param introspectedTable
* @return
*/
public static List<IntrospectedColumn> getModelBaseRecordClomns(IntrospectedTable introspectedTable) {
List<IntrospectedColumn> introspectedColumns;
if (includePrimaryKeyColumns(introspectedTable)) {
if (includeBLOBColumns(introspectedTable)) {
introspectedColumns = introspectedTable.getAllColumns();
} else {
introspectedColumns = introspectedTable.getNonBLOBColumns();
}
} else {
if (includeBLOBColumns(introspectedTable)) {
introspectedColumns = introspectedTable
.getNonPrimaryKeyColumns();
} else {
introspectedColumns = introspectedTable.getBaseColumns();
}
}
return introspectedColumns;
}
/**
* 是否有primaryKey 列
* @param introspectedTable
* @return
*/
public static boolean includePrimaryKeyColumns(IntrospectedTable introspectedTable) {
return !introspectedTable.getRules().generatePrimaryKeyClass()
&& introspectedTable.hasPrimaryKeyColumns();
}
/**
* 是否有 blob 列
* @param introspectedTable
* @return
*/
public static boolean includeBLOBColumns(IntrospectedTable introspectedTable) {
return !introspectedTable.getRules().generateRecordWithBLOBsClass()
&& introspectedTable.hasBLOBColumns();
}
}
......@@ -49,11 +49,16 @@ public class PluginTools {
/**
* 检查插件依赖
* @param context 上下文
* @param plugin 插件
* @param plugins 插件
* @return
*/
public static boolean checkDependencyPlugin(Context context, Class plugin) {
return getPluginIndex(context, plugin) >= 0;
public static boolean checkDependencyPlugin(Context context, Class... plugins) {
for (Class plugin : plugins) {
if (getPluginIndex(context, plugin) < 0) {
return false;
}
}
return true;
}
/**
......
/*
* 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.enhanced;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
/**
* ---------------------------------------------------------------------------
*
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2018/11/2 18:21
* ---------------------------------------------------------------------------
*/
public class SpecTypeArgumentsFullyQualifiedJavaType extends FullyQualifiedJavaType {
private String fullTypeSpecification;
/**
* Use this constructor to construct a generic type with the specified type parameters.
* @param fullTypeSpecification the full type specification
*/
public SpecTypeArgumentsFullyQualifiedJavaType(String fullTypeSpecification) {
super("");
this.fullTypeSpecification = fullTypeSpecification;
}
@Override
public String getShortName() {
return this.fullTypeSpecification.substring(1, this.fullTypeSpecification.length() - 1);
}
}
......@@ -49,6 +49,7 @@ public class HookAggregator implements IUpsertPluginHook,
IOptimisticLockerPluginHook,
ISelectOneByExamplePluginHook,
ITableConfigurationHook,
ILombokPluginHook,
ILogicalDeletePluginHook {
protected static final Logger logger = LoggerFactory.getLogger(BasePlugin.class); // 日志
......@@ -308,4 +309,38 @@ public class HookAggregator implements IUpsertPluginHook,
}
return true;
}
// ============================================= ILombokPluginHook ==============================================
@Override
public boolean modelBaseRecordBuilderClassGenerated(TopLevelClass topLevelClass, List<IntrospectedColumn> columns, IntrospectedTable introspectedTable) {
for (ILombokPluginHook plugin : this.getPlugins(ILombokPluginHook.class)) {
if (!plugin.modelBaseRecordBuilderClassGenerated(topLevelClass, columns, introspectedTable)) {
return false;
}
}
return true;
}
@Override
public boolean modelPrimaryKeyBuilderClassGenerated(TopLevelClass topLevelClass, List<IntrospectedColumn> columns, IntrospectedTable introspectedTable) {
for (ILombokPluginHook plugin : this.getPlugins(ILombokPluginHook.class)) {
if (!plugin.modelPrimaryKeyBuilderClassGenerated(topLevelClass, columns, introspectedTable)) {
return false;
}
}
return true;
}
@Override
public boolean modelRecordWithBLOBsBuilderClassGenerated(TopLevelClass topLevelClass, List<IntrospectedColumn> columns, IntrospectedTable introspectedTable) {
for (ILombokPluginHook plugin : this.getPlugins(ILombokPluginHook.class)) {
if (!plugin.modelRecordWithBLOBsBuilderClassGenerated(topLevelClass, columns, introspectedTable)) {
return false;
}
}
return true;
}
}
/*
* 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.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import java.util.List;
/**
* ---------------------------------------------------------------------------
*
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2018/10/31 17:27
* ---------------------------------------------------------------------------
*/
public interface ILombokPluginHook {
/**
* Model builder class 生成
* @param topLevelClass
* @param columns
* @param introspectedTable
* @return
*/
boolean modelBaseRecordBuilderClassGenerated(TopLevelClass topLevelClass, List<IntrospectedColumn> columns, IntrospectedTable introspectedTable);
/**
* Model builder class 生成
* @param topLevelClass
* @param columns
* @param introspectedTable
* @return
*/
boolean modelPrimaryKeyBuilderClassGenerated(TopLevelClass topLevelClass, List<IntrospectedColumn> columns, IntrospectedTable introspectedTable);
/**
* Model builder class 生成
* @param topLevelClass
* @param columns
* @param introspectedTable
* @return
*/
boolean modelRecordWithBLOBsBuilderClassGenerated(TopLevelClass topLevelClass, List<IntrospectedColumn> columns, IntrospectedTable introspectedTable);
}
......@@ -54,7 +54,7 @@ public class IncrementsPluginTest {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-without-model-builder-plugin.xml");
tool.generate();
Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.IncrementsPlugin插件需配合com.itfsw.mybatis.generator.plugins.ModelBuilderPlugin插件使用!");
Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.IncrementsPlugin插件需配合com.itfsw.mybatis.generator.plugins.ModelBuilderPlugin或者com.itfsw.mybatis.generator.plugins.LombokPlugin插件使用!");
}
/**
......@@ -63,7 +63,7 @@ public class IncrementsPluginTest {
@Test
public void testModelBuilderMethod() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator.xml");
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// 1. 测试生成的方法
......@@ -112,7 +112,7 @@ public class IncrementsPluginTest {
@Test
public void testSqlAndExecute() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator.xml");
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
......@@ -214,7 +214,7 @@ public class IncrementsPluginTest {
@Test
public void testWithSelectiveEnhancedPlugin() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-selective-enhanced-plugin.xml");
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// 1. 测试updateByExampleSelective
......@@ -307,7 +307,7 @@ public class IncrementsPluginTest {
@Test
public void testWithUpsertPlugin() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-upsert-plugin.xml");
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/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")));
......@@ -399,7 +399,7 @@ public class IncrementsPluginTest {
@Test
public void testWithAutoDelimitKeywords() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-autoDelimitKeywords.xml");
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// 1. 测试updateByExample、updateByExampleSelective
......@@ -433,7 +433,7 @@ public class IncrementsPluginTest {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-upsert-and-selective-enhanced-plugin.xml");
// upsertSelective 基于原生非空判断
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/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")));
......@@ -459,7 +459,7 @@ public class IncrementsPluginTest {
});
// upsertByExampleSelective 基于原生非空判断
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// 1. 测试updateByExampleSelective
......@@ -499,7 +499,7 @@ public class IncrementsPluginTest {
});
// upsertSelective 基于指定字段
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/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")));
......@@ -536,7 +536,7 @@ public class IncrementsPluginTest {
});
// upsertByExampleSelective 基于指定字段
tool.generate(() -> DBHelper.resetDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// 1. 测试updateByExampleSelective
......@@ -585,4 +585,33 @@ public class IncrementsPluginTest {
}
});
}
/**
* 测试同时整合 LombokPlugin
*/
@Test
public void testWithLombokPlugin() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-LombokPlugin.xml");
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init-lombok.sql"), new AbstractShellCallback() {
@Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// ------------------------------------- builder ----------------------------------------
// normal builder
ObjectUtil tbBuilder = new ObjectUtil(loader.loadClass(packagz + ".Tb").getMethod("builder").invoke(null));
tbBuilder = new ObjectUtil(tbBuilder.invoke("id", 1L));
tbBuilder.invoke("field1", "ts1");
ObjectUtil tb = new ObjectUtil(tbBuilder.invoke("build"));
Assert.assertEquals(tb.invoke("toString"), "Tb(id=1, field1=ts1, field2=null)");
// super
ObjectUtil tbLombokWithBLOBsBuilder = new ObjectUtil(loader.loadClass(packagz + ".TbLombokWithBLOBs").getMethod("builder").invoke(null));
tbLombokWithBLOBsBuilder.invoke("field3", "ts3");
Assert.assertEquals(tbLombokWithBLOBsBuilder.invoke("toString"), "TbLombokWithBLOBs.TbLombokWithBLOBsBuilder(super=TbLombok.TbLombokBuilder(super=TbLombokKey.TbLombokKeyBuilder(id=null, key1=null), field1=null, incF1=null), field3=ts3, field4=null)");
tbLombokWithBLOBsBuilder.invoke("field1", "ts1");
Assert.assertEquals(tbLombokWithBLOBsBuilder.invoke("toString"), "TbLombokWithBLOBs.TbLombokWithBLOBsBuilder(super=TbLombok.TbLombokBuilder(super=TbLombokKey.TbLombokKeyBuilder(id=null, key1=null), field1=ts1, incF1=null), field3=ts3, field4=null)");
tbLombokWithBLOBsBuilder.invoke("id", 100L);
Assert.assertEquals(tbLombokWithBLOBsBuilder.invoke("toString"), "TbLombokWithBLOBs.TbLombokWithBLOBsBuilder(super=TbLombok.TbLombokBuilder(super=TbLombokKey.TbLombokKeyBuilder(id=100, key1=null), field1=ts1, incF1=null), field3=ts3, field4=null)");
}
});
}
}
......@@ -151,6 +151,7 @@ public class ObjectUtil {
}
if (flag) {
method.setAccessible(true);
return method.invoke(this.object, args);
}
}
......
/*
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-03 17:34:11
*/
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',
`field2` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb
-- ----------------------------
INSERT INTO `tb` VALUES ('1', 'fd1', '0');
INSERT INTO `tb` VALUES ('2', 'fd2', '1');
INSERT INTO `tb` VALUES ('3', null, '3');
-- ----------------------------
-- Table structure for tb_keys
-- ----------------------------
DROP TABLE IF EXISTS `tb_keys`;
CREATE TABLE `tb_keys` (
`key1` bigint(20) NOT NULL 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',
PRIMARY KEY (`key1`,`key2`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_keys
-- ----------------------------
INSERT INTO `tb_keys` VALUES ('1', 'key1', 'fd1', '0', '1');
INSERT INTO `tb_keys` VALUES ('2', 'key2', 'fd2', '1', '2');
INSERT INTO `tb_keys` VALUES ('3', 'key3', null, '3', '3');
-- ----------------------------
-- Table structure for tb_lombok
-- ----------------------------
DROP TABLE IF EXISTS `tb_lombok`;
CREATE TABLE `tb_lombok` (
`id` bigint(20) NOT NULL COMMENT '注释1',
`key1` varchar(20) NOT NULL,
`field1` varchar(10) COMMENT '注释2',
`inc_f1` tinyint(1),
`field3` longtext,
`field4` longtext,
PRIMARY KEY (`id`,`key1`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_lombok
-- ----------------------------
INSERT INTO `tb_lombok` VALUES ('1', 'key1', 'fd1', '0', 'xx1', null);
INSERT INTO `tb_lombok` VALUES ('2', 'key2', 'fd2', '1', 'xx2', 'ss2');
INSERT INTO `tb_lombok` VALUES ('3', 'key3', null, '3', 'xx3', null);
\ No newline at end of file
<?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.IncrementsPlugin" />
<plugin type="com.itfsw.mybatis.generator.plugins.LombokPlugin">
<property name="@Builder" value="true"/>
</plugin>
<!--jdbc的数据库连接 -->
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
targetPackage 指定生成的model生成所在的包名
targetProject 指定在该项目下所在的路径 -->
<javaModelGenerator targetPackage="" targetProject="">
<!-- 是否对model添加 构造函数 -->
<!-- 给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="field2"/>
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
<table tableName="tb_keys">
<property name="incrementsColumns" value="inc_f1, field2"/>
</table>
<table tableName="tb_lombok">
<property name="incrementsColumns" value="inc_f1"/>
</table>
</context>
</generatorConfiguration>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment