Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0a92c5d6b | ||
|
|
15cc5eade9 | ||
|
|
887bd057fd | ||
|
|
1ebf829d57 | ||
|
|
a87dcf9a01 | ||
|
|
f6b040a4ff | ||
|
|
c8869e95c1 | ||
|
|
787a0da847 |
@@ -30,7 +30,7 @@ Maven引用:
|
||||
<dependency>
|
||||
<groupId>com.itfsw</groupId>
|
||||
<artifactId>mybatis-generator-plugin</artifactId>
|
||||
<version>1.2.3</version>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
```
|
||||
---------------------------------------
|
||||
@@ -311,14 +311,17 @@ Mybatis Generator 插件默认把Model类和Example类都生成到一个包下
|
||||
</plugin>
|
||||
```
|
||||
### 6. 批量插入插件
|
||||
提供了批量插入batchInsert和batchInsertSelective方法,因为方法使用了使用了JDBC的getGenereatedKeys方法返回插入主键,所以只能在MYSQL和SQLServer下使用。
|
||||
需配合数据Model属性对应Column获取插件(ModelColumnPlugin)插件使用,实现类似于insertSelective插入列!
|
||||
PS:为了和Mybatis官方代码风格保持一致,1.0.5+版本把批量插入方法分开了,基于老版本1.0.5-版本生成的代码请继续使用“com.itfsw.mybatis.generator.plugins.BatchInsertOldPlugin”不影响使用
|
||||
PS:继续PS,本来想继续保留老版本代码,不影响老版本已经生成代码使用的,但是始终没有绕过BindingException,只能把代码移入BatchInsertOldPlugin类~~~~~
|
||||
提供了批量插入batchInsert和batchInsertSelective方法,需配合数据Model属性对应Column获取插件(ModelColumnPlugin)插件使用,实现类似于insertSelective插入列!
|
||||
插件:
|
||||
```xml
|
||||
<!-- 批量插入插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.BatchInsertPlugin"/>
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.BatchInsertPlugin">
|
||||
<!--
|
||||
开启后可以实现官方插件根据属性是否为空决定是否插入该字段功能
|
||||
!需开启allowMultiQueries=true多条sql提交操作,所以不建议使用!插件默认不开启
|
||||
-->
|
||||
<property name="allowMultiQueries" value="false"/>
|
||||
</plugin>
|
||||
```
|
||||
使用:
|
||||
```java
|
||||
@@ -500,9 +503,14 @@ public class Test {
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.UpsertPlugin">
|
||||
<!--
|
||||
支持upsertByExample,upsertByExampleSelective操作
|
||||
!需开启allowMultiQueries=true多条sql提交操作,所以不建议使用!
|
||||
!需开启allowMultiQueries=true多条sql提交操作,所以不建议使用!插件默认不开启
|
||||
-->
|
||||
<property name="allowMultiQueries" value="true"/>
|
||||
<property name="allowMultiQueries" value="false"/>
|
||||
<!--
|
||||
开启批量功能,支持batchUpsert,batchUpsertWithBLOBs,batchUpserSelective
|
||||
!这几个方法中无法支持IncrementsPlugin的方法!插件默认不开启
|
||||
-->
|
||||
<property name="allowBatchUpsert" value="fasle"/>
|
||||
</plugin>
|
||||
```
|
||||
使用:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<groupId>com.itfsw</groupId>
|
||||
<artifactId>mybatis-generator-plugin</artifactId>
|
||||
<version>1.2.4</version>
|
||||
<version>1.2.5</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.4</tag>
|
||||
<tag>V1.2.5</tag>
|
||||
</scm>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++distribution++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
@@ -23,8 +23,11 @@ import org.mybatis.generator.api.dom.java.*;
|
||||
import org.mybatis.generator.api.dom.xml.*;
|
||||
import org.mybatis.generator.codegen.mybatis3.ListUtilities;
|
||||
import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
|
||||
import org.mybatis.generator.internal.util.StringUtility;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
@@ -37,6 +40,8 @@ import java.util.List;
|
||||
public class BatchInsertPlugin extends BasePlugin {
|
||||
public static final String METHOD_BATCH_INSERT = "batchInsert"; // 方法名
|
||||
public static final String METHOD_BATCH_INSERT_SELECTIVE = "batchInsertSelective"; // 方法名
|
||||
public static final String PRO_ALLOW_MULTI_QUERIES = "allowMultiQueries"; // property allowMultiQueries
|
||||
private boolean allowMultiQueries = false; // 是否允许多sql提交
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -59,6 +64,15 @@ public class BatchInsertPlugin extends BasePlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 插件是否开启了多sql提交
|
||||
Properties properties = this.getProperties();
|
||||
String allowMultiQueries = properties.getProperty(PRO_ALLOW_MULTI_QUERIES);
|
||||
this.allowMultiQueries = allowMultiQueries == null ? false : StringUtility.isTrue(allowMultiQueries);
|
||||
if (this.allowMultiQueries) {
|
||||
// 提示用户注意信息
|
||||
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件您开启了allowMultiQueries支持,注意在jdbc url 配置中增加“allowMultiQueries=true”支持(不怎么建议使用该功能,开启多sql提交会增加sql注入的风险,请确保你所有sql都使用MyBatis书写,请不要使用statement进行sql提交)!");
|
||||
}
|
||||
|
||||
return super.validate(warnings);
|
||||
}
|
||||
|
||||
@@ -143,23 +157,75 @@ public class BatchInsertPlugin extends BasePlugin {
|
||||
// values 构建
|
||||
batchInsertEle.addElement(new TextElement("values"));
|
||||
batchInsertEle.addElement(foreachElement);
|
||||
if (context.getPlugins().sqlMapInsertElementGenerated(batchInsertEle, introspectedTable)) {
|
||||
document.getRootElement().addElement(batchInsertEle);
|
||||
logger.debug("itfsw(批量插入插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加batchInsert实现方法。");
|
||||
}
|
||||
document.getRootElement().addElement(batchInsertEle);
|
||||
logger.debug("itfsw(批量插入插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加batchInsert实现方法。");
|
||||
|
||||
// 2. batchInsertSelective
|
||||
XmlElement element = new XmlElement("insert");
|
||||
element.addAttribute(new Attribute("id", METHOD_BATCH_INSERT_SELECTIVE));
|
||||
// 参数类型
|
||||
element.addAttribute(new Attribute("parameterType", "map"));
|
||||
XmlElement batchInsertSelectiveEle = new XmlElement("insert");
|
||||
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
|
||||
commentGenerator.addComment(element);
|
||||
commentGenerator.addComment(batchInsertSelectiveEle);
|
||||
|
||||
batchInsertSelectiveEle.addAttribute(new Attribute("id", METHOD_BATCH_INSERT_SELECTIVE));
|
||||
// 参数类型
|
||||
batchInsertSelectiveEle.addAttribute(new Attribute("parameterType", "map"));
|
||||
|
||||
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
|
||||
XmlElementGeneratorTools.useGeneratedKeys(element, introspectedTable);
|
||||
XmlElementGeneratorTools.useGeneratedKeys(batchInsertSelectiveEle, introspectedTable);
|
||||
|
||||
element.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime() + " ("));
|
||||
// 支持原生字段非空判断
|
||||
if (this.allowMultiQueries) {
|
||||
XmlElement chooseEle = new XmlElement("choose");
|
||||
|
||||
// selective 增强
|
||||
XmlElement selectiveEnhancedEle = new XmlElement("when");
|
||||
selectiveEnhancedEle.addAttribute(new Attribute("test", "selective != null and selective.length > 0"));
|
||||
chooseEle.addElement(selectiveEnhancedEle);
|
||||
|
||||
selectiveEnhancedEle.getElements().addAll(this.generateSelectiveEnhancedEles(introspectedTable));
|
||||
|
||||
// 原生非空判断语句
|
||||
XmlElement selectiveNormalEle = new XmlElement("otherwise");
|
||||
chooseEle.addElement(selectiveNormalEle);
|
||||
|
||||
XmlElement foreachEle = new XmlElement("foreach");
|
||||
selectiveNormalEle.addElement(foreachEle);
|
||||
foreachEle.addAttribute(new Attribute("collection", "list"));
|
||||
foreachEle.addAttribute(new Attribute("item", "item"));
|
||||
foreachEle.addAttribute(new Attribute("separator", ";"));
|
||||
|
||||
|
||||
foreachEle.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
|
||||
|
||||
XmlElement insertTrimElement = new XmlElement("trim");
|
||||
foreachEle.addElement(insertTrimElement);
|
||||
insertTrimElement.addElement(XmlElementGeneratorTools.generateKeysSelective(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns()), "item."));
|
||||
|
||||
foreachEle.addElement(new TextElement("values"));
|
||||
|
||||
XmlElement valuesTrimElement = new XmlElement("trim");
|
||||
foreachEle.addElement(valuesTrimElement);
|
||||
valuesTrimElement.addElement(XmlElementGeneratorTools.generateValuesSelective(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns()), "item."));
|
||||
|
||||
batchInsertSelectiveEle.addElement(chooseEle);
|
||||
} else {
|
||||
batchInsertSelectiveEle.getElements().addAll(this.generateSelectiveEnhancedEles(introspectedTable));
|
||||
}
|
||||
|
||||
document.getRootElement().addElement(batchInsertSelectiveEle);
|
||||
logger.debug("itfsw(批量插入插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加batchInsertSelective实现方法。");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成insert selective 增强的插入语句
|
||||
* @param introspectedTable
|
||||
* @return
|
||||
*/
|
||||
private List<Element> generateSelectiveEnhancedEles(IntrospectedTable introspectedTable) {
|
||||
List<Element> eles = new ArrayList<>();
|
||||
|
||||
eles.add(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime() + " ("));
|
||||
|
||||
XmlElement foreachInsertColumns = new XmlElement("foreach");
|
||||
foreachInsertColumns.addAttribute(new Attribute("collection", "selective"));
|
||||
@@ -167,12 +233,12 @@ public class BatchInsertPlugin extends BasePlugin {
|
||||
foreachInsertColumns.addAttribute(new Attribute("separator", ","));
|
||||
foreachInsertColumns.addElement(new TextElement("${column.value}"));
|
||||
|
||||
element.addElement(foreachInsertColumns);
|
||||
eles.add(foreachInsertColumns);
|
||||
|
||||
element.addElement(new TextElement(")"));
|
||||
eles.add(new TextElement(")"));
|
||||
|
||||
// values
|
||||
element.addElement(new TextElement("values"));
|
||||
eles.add(new TextElement("values"));
|
||||
|
||||
// foreach values
|
||||
XmlElement foreachValues = new XmlElement("foreach");
|
||||
@@ -203,14 +269,8 @@ public class BatchInsertPlugin extends BasePlugin {
|
||||
|
||||
foreachValues.addElement(new TextElement(")"));
|
||||
|
||||
element.addElement(foreachValues);
|
||||
eles.add(foreachValues);
|
||||
|
||||
if (context.getPlugins().sqlMapInsertElementGenerated(element, introspectedTable)) {
|
||||
document.getRootElement().addElement(element);
|
||||
logger.debug("itfsw(批量插入插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加batchInsertSelective实现方法。");
|
||||
}
|
||||
|
||||
return true;
|
||||
return eles;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,9 +23,11 @@ import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.api.dom.java.*;
|
||||
import org.mybatis.generator.api.dom.xml.*;
|
||||
import org.mybatis.generator.codegen.mybatis3.ListUtilities;
|
||||
import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
|
||||
import org.mybatis.generator.internal.util.StringUtility;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -42,13 +44,19 @@ public class UpsertPlugin extends BasePlugin {
|
||||
public static final String METHOD_UPSERT_WITH_BLOBS = "upsertWithBLOBs"; // 方法名
|
||||
public static final String METHOD_UPSERT_SELECTIVE = "upsertSelective"; // 方法名
|
||||
|
||||
public static final String METHOD_BATCH_UPSERT = "batchUpsert"; // 方法名
|
||||
public static final String METHOD_BATCH_UPSERT_WITH_BLOBS = "batchUpsertWithBLOBs"; // 方法名
|
||||
public static final String METHOD_BATCH_UPSERT_SELECTIVE = "batchUpsertSelective"; // 方法名
|
||||
|
||||
public static final String METHOD_UPSERT_BY_EXAMPLE = "upsertByExample"; // 方法名
|
||||
public static final String METHOD_UPSERT_BY_EXAMPLE_WITH_BLOBS = "upsertByExampleWithBLOBs"; // 方法名
|
||||
public static final String METHOD_UPSERT_BY_EXAMPLE_SELECTIVE = "upsertByExampleSelective"; // 方法名
|
||||
|
||||
|
||||
public static final String PRO_ALLOW_MULTI_QUERIES = "allowMultiQueries"; // property allowMultiQueries
|
||||
public static final String PRO_ALLOW_BATCH_UPSERT = "allowBatchUpsert"; // property allowBatch
|
||||
private boolean allowMultiQueries = false; // 是否允许多sql提交
|
||||
private boolean allowBatchUpsert = false;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -71,6 +79,16 @@ public class UpsertPlugin extends BasePlugin {
|
||||
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件您开启了allowMultiQueries支持,注意在jdbc url 配置中增加“allowMultiQueries=true”支持(不怎么建议使用该功能,开启多sql提交会增加sql注入的风险,请确保你所有sql都使用MyBatis书写,请不要使用statement进行sql提交)!");
|
||||
}
|
||||
|
||||
// 是否允许批量
|
||||
String allowBatchUpsert = properties.getProperty(PRO_ALLOW_BATCH_UPSERT);
|
||||
this.allowBatchUpsert = allowBatchUpsert == null ? false : StringUtility.isTrue(allowBatchUpsert);
|
||||
|
||||
// 批量时依赖插件 ModelColumnPlugin
|
||||
if (this.allowBatchUpsert && !PluginTools.checkDependencyPlugin(context, ModelColumnPlugin.class)) {
|
||||
// 提示用户注意信息
|
||||
warnings.add("itfsw:插件" + this.getClass().getTypeName() + "插件您开启了allowBatchUpsert支持,请配置依赖的插件" + ModelColumnPlugin.class.getTypeName() + "!");
|
||||
}
|
||||
|
||||
return super.validate(warnings);
|
||||
}
|
||||
|
||||
@@ -108,7 +126,7 @@ public class UpsertPlugin extends BasePlugin {
|
||||
commentGenerator.addGeneralMethodComment(mUpsertWithBLOBs, introspectedTable);
|
||||
// interface 增加方法
|
||||
FormatTools.addMethodWithBestPosition(interfaze, mUpsertWithBLOBs);
|
||||
logger.debug("itfsw(存在即更新插件):" + interfaze.getType().getShortName() + "增加upsert方法。");
|
||||
logger.debug("itfsw(存在即更新插件):" + interfaze.getType().getShortName() + "增加upsertWithBLOBs方法。");
|
||||
}
|
||||
|
||||
// ====================================== upsertSelective ======================================
|
||||
@@ -155,7 +173,7 @@ public class UpsertPlugin extends BasePlugin {
|
||||
commentGenerator.addGeneralMethodComment(mUpsertByExampleWithBLOBs, introspectedTable);
|
||||
// interface 增加方法
|
||||
FormatTools.addMethodWithBestPosition(interfaze, mUpsertByExampleWithBLOBs);
|
||||
logger.debug("itfsw(存在即更新插件):" + interfaze.getType().getShortName() + "增加upsertByExample方法。");
|
||||
logger.debug("itfsw(存在即更新插件):" + interfaze.getType().getShortName() + "增加upsertByExampleWithBLOBs方法。");
|
||||
}
|
||||
|
||||
// ====================================== upsertByExampleSelective ======================================
|
||||
@@ -175,6 +193,55 @@ public class UpsertPlugin extends BasePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.allowBatchUpsert) {
|
||||
// ====================================== batchUpsert ======================================
|
||||
FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
|
||||
returnType.addTypeArgument(JavaElementGeneratorTools.getModelTypeWithoutBLOBs(introspectedTable));
|
||||
Method mBatchUpsert = JavaElementGeneratorTools.generateMethod(
|
||||
METHOD_BATCH_UPSERT,
|
||||
JavaVisibility.DEFAULT,
|
||||
FullyQualifiedJavaType.getIntInstance(),
|
||||
new Parameter(returnType, "list", "@Param(\"list\")")
|
||||
);
|
||||
commentGenerator.addGeneralMethodComment(mBatchUpsert, introspectedTable);
|
||||
// interface 增加方法
|
||||
FormatTools.addMethodWithBestPosition(interfaze, mBatchUpsert);
|
||||
logger.debug("itfsw(存在即更新插件):" + interfaze.getType().getShortName() + "增加batchUpsert方法。");
|
||||
|
||||
// ====================================== batchUpsertWithBLOBs ======================================
|
||||
// !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
|
||||
if (introspectedTable.hasBLOBColumns()) {
|
||||
returnType = FullyQualifiedJavaType.getNewListInstance();
|
||||
returnType.addTypeArgument(JavaElementGeneratorTools.getModelTypeWithBLOBs(introspectedTable));
|
||||
Method mBatchUpsertWithBLOBs = JavaElementGeneratorTools.generateMethod(
|
||||
METHOD_BATCH_UPSERT_WITH_BLOBS,
|
||||
JavaVisibility.DEFAULT,
|
||||
FullyQualifiedJavaType.getIntInstance(),
|
||||
new Parameter(returnType, "list", "@Param(\"list\")")
|
||||
);
|
||||
commentGenerator.addGeneralMethodComment(mBatchUpsertWithBLOBs, introspectedTable);
|
||||
// interface 增加方法
|
||||
FormatTools.addMethodWithBestPosition(interfaze, mBatchUpsertWithBLOBs);
|
||||
logger.debug("itfsw(存在即更新插件):" + interfaze.getType().getShortName() + "增加batchUpsertWithBLOBs方法。");
|
||||
}
|
||||
|
||||
// ====================================== batchUpsertSelective ======================================
|
||||
returnType = FullyQualifiedJavaType.getNewListInstance();
|
||||
returnType.addTypeArgument(fullFieldModel);
|
||||
FullyQualifiedJavaType selectiveType = new FullyQualifiedJavaType(introspectedTable.getRules().calculateAllFieldsClass().getShortName() + "." + ModelColumnPlugin.ENUM_NAME);
|
||||
Method mBatchUpsertSelective = JavaElementGeneratorTools.generateMethod(
|
||||
METHOD_BATCH_UPSERT_SELECTIVE,
|
||||
JavaVisibility.DEFAULT,
|
||||
FullyQualifiedJavaType.getIntInstance(),
|
||||
new Parameter(returnType, "list", "@Param(\"list\")"),
|
||||
new Parameter(selectiveType, "selective", "@Param(\"selective\")", true)
|
||||
);
|
||||
commentGenerator.addGeneralMethodComment(mBatchUpsertSelective, introspectedTable);
|
||||
// interface 增加方法
|
||||
FormatTools.addMethodWithBestPosition(interfaze, mBatchUpsertSelective);
|
||||
logger.debug("itfsw(存在即更新插件):" + interfaze.getType().getShortName() + "增加batchUpsertSelective方法。");
|
||||
}
|
||||
|
||||
return super.clientGenerated(interfaze, topLevelClass, introspectedTable);
|
||||
}
|
||||
|
||||
@@ -193,9 +260,147 @@ public class UpsertPlugin extends BasePlugin {
|
||||
this.generateXmlElement(document, introspectedTable, true);
|
||||
}
|
||||
|
||||
if (this.allowBatchUpsert) {
|
||||
this.generateBatchXmlElementSelective(document, introspectedTable);
|
||||
this.generateBatchXmlElement(document, introspectedTable, false);
|
||||
if (introspectedTable.hasBLOBColumns()) {
|
||||
this.generateBatchXmlElement(document, introspectedTable, true);
|
||||
}
|
||||
}
|
||||
|
||||
return super.sqlMapDocumentGenerated(document, introspectedTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量
|
||||
* @param document
|
||||
* @param introspectedTable
|
||||
*/
|
||||
private void generateBatchXmlElementSelective(Document document, IntrospectedTable introspectedTable) {
|
||||
XmlElement insertEle = new XmlElement("insert");
|
||||
insertEle.addAttribute(new Attribute("id", METHOD_BATCH_UPSERT_SELECTIVE));
|
||||
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
|
||||
commentGenerator.addComment(insertEle);
|
||||
|
||||
// 参数类型
|
||||
insertEle.addAttribute(new Attribute("parameterType", "map"));
|
||||
|
||||
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
|
||||
XmlElementGeneratorTools.useGeneratedKeys(insertEle, introspectedTable);
|
||||
|
||||
// insert
|
||||
insertEle.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime() + " ("));
|
||||
|
||||
XmlElement foreachInsertColumns = new XmlElement("foreach");
|
||||
foreachInsertColumns.addAttribute(new Attribute("collection", "selective"));
|
||||
foreachInsertColumns.addAttribute(new Attribute("item", "column"));
|
||||
foreachInsertColumns.addAttribute(new Attribute("separator", ","));
|
||||
foreachInsertColumns.addElement(new TextElement("${column.value}"));
|
||||
|
||||
insertEle.addElement(foreachInsertColumns);
|
||||
|
||||
insertEle.addElement(new TextElement(")"));
|
||||
|
||||
// values
|
||||
insertEle.addElement(new TextElement("values"));
|
||||
|
||||
// foreach values
|
||||
XmlElement foreachValues = new XmlElement("foreach");
|
||||
foreachValues.addAttribute(new Attribute("collection", "list"));
|
||||
foreachValues.addAttribute(new Attribute("item", "item"));
|
||||
foreachValues.addAttribute(new Attribute("separator", ","));
|
||||
|
||||
foreachValues.addElement(new TextElement("("));
|
||||
|
||||
// foreach 所有插入的列,比较是否存在
|
||||
XmlElement foreachInsertColumnsCheck = new XmlElement("foreach");
|
||||
foreachInsertColumnsCheck.addAttribute(new Attribute("collection", "selective"));
|
||||
foreachInsertColumnsCheck.addAttribute(new Attribute("item", "column"));
|
||||
foreachInsertColumnsCheck.addAttribute(new Attribute("separator", ","));
|
||||
|
||||
// 所有表字段
|
||||
List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns());
|
||||
List<IntrospectedColumn> columns1 = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns());
|
||||
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.addElement(new TextElement(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.")));
|
||||
|
||||
foreachInsertColumnsCheck.addElement(check);
|
||||
}
|
||||
foreachValues.addElement(foreachInsertColumnsCheck);
|
||||
|
||||
foreachValues.addElement(new TextElement(")"));
|
||||
|
||||
insertEle.addElement(foreachValues);
|
||||
|
||||
insertEle.addElement(new TextElement("on duplicate key update "));
|
||||
// set
|
||||
XmlElement foreachSetColumns = new XmlElement("foreach");
|
||||
insertEle.addElement(foreachSetColumns);
|
||||
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})"));
|
||||
|
||||
document.getRootElement().addElement(insertEle);
|
||||
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加batchUpsertSelective实现方法。");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量
|
||||
* @param document
|
||||
* @param introspectedTable
|
||||
* @param withBLOBs
|
||||
*/
|
||||
private void generateBatchXmlElement(Document document, IntrospectedTable introspectedTable, boolean withBLOBs) {
|
||||
List<IntrospectedColumn> columns = ListUtilities.removeGeneratedAlwaysColumns(withBLOBs ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns());
|
||||
XmlElement insertEle = new XmlElement("insert");
|
||||
insertEle.addAttribute(new Attribute("id", withBLOBs ? METHOD_BATCH_UPSERT_WITH_BLOBS : METHOD_BATCH_UPSERT));
|
||||
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
|
||||
commentGenerator.addComment(insertEle);
|
||||
|
||||
// 参数类型
|
||||
insertEle.addAttribute(new Attribute("parameterType", "map"));
|
||||
|
||||
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
|
||||
XmlElementGeneratorTools.useGeneratedKeys(insertEle, introspectedTable);
|
||||
|
||||
// insert
|
||||
insertEle.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
|
||||
for (Element element : XmlElementGeneratorTools.generateUpsertKeys(columns, null)) {
|
||||
insertEle.addElement(element);
|
||||
}
|
||||
insertEle.addElement(new TextElement("values"));
|
||||
|
||||
// values
|
||||
XmlElement foreachEle = new XmlElement("foreach");
|
||||
insertEle.addElement(foreachEle);
|
||||
foreachEle.addAttribute(new Attribute("collection", "list"));
|
||||
foreachEle.addAttribute(new Attribute("item", "item"));
|
||||
foreachEle.addAttribute(new Attribute("separator", ","));
|
||||
|
||||
for (Element element : XmlElementGeneratorTools.generateUpsertValues(columns, "item.", true)) {
|
||||
foreachEle.addElement(element);
|
||||
}
|
||||
insertEle.addElement(new TextElement("on duplicate key update "));
|
||||
// set
|
||||
Iterator<IntrospectedColumn> columnIterator = columns.iterator();
|
||||
while (columnIterator.hasNext()) {
|
||||
IntrospectedColumn column = columnIterator.next();
|
||||
insertEle.addElement(new TextElement(
|
||||
MyBatis3FormattingUtilities.getEscapedColumnName(column)
|
||||
+ " = values(" + MyBatis3FormattingUtilities.getEscapedColumnName(column)
|
||||
+ ")"
|
||||
+ (columnIterator.hasNext() ? "," : "")
|
||||
));
|
||||
}
|
||||
|
||||
document.getRootElement().addElement(insertEle);
|
||||
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加" + (withBLOBs ? "batchUpsertWithBLOBs" : "batchUpsert") + "实现方法。");
|
||||
}
|
||||
|
||||
/**
|
||||
* 当Selective情况
|
||||
* @param document
|
||||
@@ -315,7 +520,7 @@ public class UpsertPlugin extends BasePlugin {
|
||||
}
|
||||
|
||||
document.getRootElement().addElement(insertEle);
|
||||
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加upsert实现方法。");
|
||||
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加" + (withBLOBs ? "upsertWithBLOBs" : "upsert") + "实现方法。");
|
||||
|
||||
if (this.allowMultiQueries) {
|
||||
// ====================================== upsertByExample ======================================
|
||||
@@ -352,7 +557,7 @@ public class UpsertPlugin extends BasePlugin {
|
||||
this.generateExistsClause(introspectedTable, updateEle, XmlElementGeneratorTools.generateUpsertValues(columns, "record.", false));
|
||||
|
||||
document.getRootElement().addElement(updateEle);
|
||||
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加upsertByExample实现方法。");
|
||||
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加" + (withBLOBs ? "upsertByExampleWithBLOBs" : "upsertByExample") + "实现方法。");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,11 @@ public class BatchInsertPluginTest {
|
||||
|
||||
Assert.assertTrue(tool.getWarnings().size() == 2);
|
||||
Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.BatchInsertPlugin插件需配合com.itfsw.mybatis.generator.plugins.ModelColumnPlugin插件使用!");
|
||||
|
||||
// 2. 普通提示
|
||||
tool = MyBatisGeneratorTool.create("scripts/BatchInsertPlugin/mybatis-generator-with-allowMultiQueries.xml");
|
||||
tool.generate();
|
||||
Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.BatchInsertPlugin插件您开启了allowMultiQueries支持,注意在jdbc url 配置中增加“allowMultiQueries=true”支持(不怎么建议使用该功能,开启多sql提交会增加sql注入的风险,请确保你所有sql都使用MyBatis书写,请不要使用statement进行sql提交)!");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +147,7 @@ public class BatchInsertPluginTest {
|
||||
@Test
|
||||
public void testBatchInsert() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BatchInsertPlugin/mybatis-generator.xml");
|
||||
tool.generate(new AbstractShellCallback() {
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/BatchInsertPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
// 1. 测试sql
|
||||
@@ -164,6 +169,11 @@ public class BatchInsertPluginTest {
|
||||
// 2. 执行sql
|
||||
Object count = tbMapper.invoke("batchInsert", params);
|
||||
Assert.assertEquals(count, 2);
|
||||
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
ObjectUtil item = new ObjectUtil(params.get(i));
|
||||
Assert.assertEquals(item.get("id"), 1L + i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -174,7 +184,7 @@ public class BatchInsertPluginTest {
|
||||
@Test
|
||||
public void testBatchInsertSelective() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BatchInsertPlugin/mybatis-generator.xml");
|
||||
tool.generate(new AbstractShellCallback() {
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/BatchInsertPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
// 1. 测试sql
|
||||
@@ -204,4 +214,50 @@ public class BatchInsertPluginTest {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试开启 AllowMultiQueries 支持
|
||||
*/
|
||||
@Test
|
||||
public void testAllowMultiQueries() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BatchInsertPlugin/mybatis-generator-with-allowMultiQueries.xml");
|
||||
|
||||
// 1. 测试增强的selective
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/BatchInsertPlugin/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")));
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(new ObjectUtil(loader, packagz + ".Tb").set("field1", "test").getObject());
|
||||
params.add(new ObjectUtil(loader, packagz + ".Tb").set("field1", "test").set("field2", 1).getObject());
|
||||
|
||||
ObjectUtil columnField2 = new ObjectUtil(loader, packagz + ".Tb$Column#field2");
|
||||
Object columns = Array.newInstance(columnField2.getCls(), 1);
|
||||
Array.set(columns, 0, columnField2.getObject());
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "batchInsertSelective", params, columns);
|
||||
Assert.assertEquals(sql, "insert into tb ( field2 ) values ( null ) , ( 1 )");
|
||||
// 2. 执行sql
|
||||
Object count = tbMapper.invoke("batchInsertSelective", params, columns);
|
||||
Assert.assertEquals(count, 2);
|
||||
}
|
||||
});
|
||||
|
||||
// 2. 测试原生非空判断
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/BatchInsertPlugin/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")));
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(new ObjectUtil(loader, packagz + ".Tb").set("field1", "test").getObject());
|
||||
params.add(new ObjectUtil(loader, packagz + ".Tb").set("field1", "test").set("field2", 1).getObject());
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "batchInsertSelective", params, null);
|
||||
Assert.assertEquals(sql, "insert into tb ( field1 ) values ( 'test' ) ; insert into tb ( field1, field2 ) values ( 'test', 1 )");
|
||||
// 2. 执行sql
|
||||
Object count = tbMapper.invoke("batchInsertSelective", params, null);
|
||||
Assert.assertTrue((int) count > 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,11 @@ import org.mybatis.generator.exception.InvalidConfigurationException;
|
||||
import org.mybatis.generator.exception.XMLParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
@@ -41,7 +44,7 @@ public class UpsertPluginTest {
|
||||
* 初始化
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void init() throws Exception{
|
||||
public static void init() throws Exception {
|
||||
DBHelper.createDB("scripts/UpsertPlugin/init.sql");
|
||||
}
|
||||
|
||||
@@ -421,4 +424,136 @@ public class UpsertPluginTest {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试批量batchUpsert
|
||||
*/
|
||||
@Test
|
||||
public void testBatchUpsert() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator-with-allowBatchUpsert.xml");
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/UpsertPlugin/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")));
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(new ObjectUtil(loader, packagz + ".Tb").set("id", 1L).set("field1", "ts1").getObject());
|
||||
params.add(new ObjectUtil(loader, packagz + ".Tb").set("id", 6L).set("field1", "ts2").set("field2", 1).getObject());
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "batchUpsert", params);
|
||||
Assert.assertEquals(sql, "insert into tb (id, field1, field2) values (1, 'ts1', null ) , (6, 'ts2', 1 ) on duplicate key update id = values(id), field1 = values(field1), field2 = values(field2)");
|
||||
// 2. 执行sql
|
||||
Object count = tbMapper.invoke("batchUpsert", params);
|
||||
Assert.assertEquals(count, 3);
|
||||
|
||||
// 验证
|
||||
ResultSet rs = DBHelper.execute(sqlSession, "select * from tb where id = 1");
|
||||
rs.first();
|
||||
Assert.assertEquals(rs.getString("field1"), "ts1");
|
||||
|
||||
rs = DBHelper.execute(sqlSession, "select * from tb where id = 6");
|
||||
rs.first();
|
||||
Assert.assertEquals(rs.getString("field1"), "ts2");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试批量batchUpsertWithBLOBs
|
||||
*/
|
||||
@Test
|
||||
public void testBatchUpsertWithBLOBs() throws Exception {
|
||||
// 1. batchUpsert
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator-with-allowBatchUpsert.xml");
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/UpsertPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbBlobsMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbBlobsMapper")));
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(new ObjectUtil(loader, packagz + ".TbBlobs").set("id", 1L).set("field1", "ts1").getObject());
|
||||
params.add(new ObjectUtil(loader, packagz + ".TbBlobs").set("id", 6L).set("field1", "ts2").getObject());
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbBlobsMapper.getObject(), "batchUpsert", params);
|
||||
Assert.assertEquals(sql, "insert into tb_blobs (id, field1) values (1, 'ts1') , (6, 'ts2') on duplicate key update id = values(id), field1 = values(field1)");
|
||||
// 2. 执行sql
|
||||
Object count = tbBlobsMapper.invoke("batchUpsert", params);
|
||||
Assert.assertEquals(count, 3);
|
||||
|
||||
// 验证
|
||||
ResultSet rs = DBHelper.execute(sqlSession, "select * from tb_blobs where id = 1");
|
||||
rs.first();
|
||||
Assert.assertEquals(rs.getString("field1"), "ts1");
|
||||
|
||||
rs = DBHelper.execute(sqlSession, "select * from tb_blobs where id = 6");
|
||||
rs.first();
|
||||
Assert.assertEquals(rs.getString("field1"), "ts2");
|
||||
}
|
||||
});
|
||||
|
||||
// 2. batchUpsertWithBLOBs
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/UpsertPlugin/init.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbBlobsMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbBlobsMapper")));
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(new ObjectUtil(loader, packagz + ".TbBlobsWithBLOBs").set("id", 1L).set("field1", "ts1").set("field3", "ff1").getObject());
|
||||
params.add(new ObjectUtil(loader, packagz + ".TbBlobsWithBLOBs").set("id", 6L).set("field1", "ts2").set("field3", "ff2").getObject());
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbBlobsMapper.getObject(), "batchUpsertWithBLOBs", params);
|
||||
Assert.assertEquals(sql, "insert into tb_blobs (id, field1, field2, field3) values (1, 'ts1', 'null', 'ff1') , (6, 'ts2', 'null', 'ff2') on duplicate key update id = values(id), field1 = values(field1), field2 = values(field2), field3 = values(field3)");
|
||||
// 2. 执行sql
|
||||
Object count = tbBlobsMapper.invoke("batchUpsertWithBLOBs", params);
|
||||
Assert.assertEquals(count, 3);
|
||||
|
||||
// 验证
|
||||
ResultSet rs = DBHelper.execute(sqlSession, "select * from tb_blobs where id = 1");
|
||||
rs.first();
|
||||
Assert.assertEquals(rs.getString("field1"), "ts1");
|
||||
Assert.assertEquals(rs.getString("field3"), "ff1");
|
||||
|
||||
rs = DBHelper.execute(sqlSession, "select * from tb_blobs where id = 6");
|
||||
rs.first();
|
||||
Assert.assertEquals(rs.getString("field1"), "ts2");
|
||||
Assert.assertEquals(rs.getString("field3"), "ff2");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试批量batchUpsertSelective
|
||||
*/
|
||||
@Test
|
||||
public void testBatchUpsertSelective() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator-with-allowBatchUpsert.xml");
|
||||
tool.generate(() -> DBHelper.resetDB("scripts/UpsertPlugin/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")));
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(new ObjectUtil(loader, packagz + ".Tb").set("id", 1L).set("field1", "ts1").getObject());
|
||||
params.add(new ObjectUtil(loader, packagz + ".Tb").set("id", 6L).set("field1", "ts2").set("field2", 1).getObject());
|
||||
|
||||
ObjectUtil columnId = new ObjectUtil(loader, packagz + ".Tb$Column#id");
|
||||
ObjectUtil columnField1 = new ObjectUtil(loader, packagz + ".Tb$Column#field1");
|
||||
Object columns = Array.newInstance(columnId.getCls(), 2);
|
||||
Array.set(columns, 0, columnId.getObject());
|
||||
Array.set(columns, 1, columnField1.getObject());
|
||||
|
||||
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "batchUpsertSelective", params, columns);
|
||||
Assert.assertEquals(sql, "insert into tb ( id , field1 ) values ( 1 , 'ts1' ) , ( 6 , 'ts2' ) on duplicate key update id = values(id) , field1 = values(field1)");
|
||||
// 2. 执行sql
|
||||
Object count = tbMapper.invoke("batchUpsertSelective", params, columns);
|
||||
Assert.assertEquals(count, 3);
|
||||
|
||||
// 验证
|
||||
ResultSet rs = DBHelper.execute(sqlSession, "select * from tb where id = 1");
|
||||
rs.first();
|
||||
Assert.assertEquals(rs.getString("field1"), "ts1");
|
||||
|
||||
rs = DBHelper.execute(sqlSession, "select * from tb where id = 6");
|
||||
rs.first();
|
||||
Assert.assertEquals(rs.getString("field1"), "ts2");
|
||||
Assert.assertNull(rs.getString("field2"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ CREATE TABLE `tb` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
@@ -40,7 +40,7 @@ CREATE TABLE `tb_blobs` (
|
||||
`field2` longtext COMMENT '注释2',
|
||||
`field3` longtext,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
@@ -56,7 +56,7 @@ CREATE TABLE `tb_keys` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int DEFAULT NULL,
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
@@ -71,7 +71,7 @@ CREATE TABLE `tb_single_blob` (
|
||||
`field1` longtext COMMENT '注释2',
|
||||
`field2` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_single_blob
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?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.BatchInsertPlugin">
|
||||
<property name="allowMultiQueries" value="true"/>
|
||||
</plugin>
|
||||
<!-- 数据Model属性对应Column获取插件 -->
|
||||
<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>
|
||||
<table tableName="tb_keys" />
|
||||
<table tableName="tb_single_blob">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
<table tableName="tb_blobs">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
@@ -23,4 +23,4 @@ CREATE TABLE `tb` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB;
|
||||
) ENGINE=MyISAM;
|
||||
@@ -26,7 +26,7 @@ CREATE TABLE `tb` (
|
||||
`inc_f2` bigint(20) DEFAULT '0',
|
||||
`inc_f3` bigint(20) DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
@@ -49,7 +49,7 @@ CREATE TABLE `tb_blobs` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
@@ -72,7 +72,7 @@ CREATE TABLE `tb_keys` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
@@ -93,7 +93,7 @@ CREATE TABLE `tb_single_blob` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_single_blob
|
||||
@@ -112,7 +112,7 @@ CREATE TABLE `tb_key_word` (
|
||||
`inc_f1` bigint(20) NOT NULL DEFAULT '0',
|
||||
`update` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_key_word
|
||||
|
||||
@@ -28,7 +28,7 @@ CREATE TABLE `tb` (
|
||||
`ts_3` float DEFAULT NULL,
|
||||
`ts_4` varchar(10) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
|
||||
@@ -26,7 +26,7 @@ CREATE TABLE `tb` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
@@ -45,7 +45,7 @@ CREATE TABLE `tb_blobs` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
@@ -64,7 +64,7 @@ CREATE TABLE `tb_keys` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
@@ -83,7 +83,7 @@ CREATE TABLE `tb_keys_blobs` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
|
||||
@@ -26,7 +26,7 @@ CREATE TABLE `tb` (
|
||||
`inc_f2` bigint(20) DEFAULT '0',
|
||||
`inc_f3` bigint(20) DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
@@ -45,7 +45,7 @@ CREATE TABLE `tb_blobs` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
@@ -64,7 +64,7 @@ CREATE TABLE `tb_keys` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`key_1`,`key_2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
|
||||
@@ -26,7 +26,7 @@ CREATE TABLE `tb` (
|
||||
`inc_f2` bigint(20) DEFAULT '0',
|
||||
`inc_f3` bigint(20) DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
@@ -49,7 +49,7 @@ CREATE TABLE `tb_blobs` (
|
||||
`inc_f2` bigint(20) DEFAULT '0',
|
||||
`inc_f3` bigint(20) DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
@@ -72,7 +72,7 @@ CREATE TABLE `tb_keys` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
@@ -93,7 +93,7 @@ CREATE TABLE `tb_single_blob` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_single_blob
|
||||
@@ -112,7 +112,7 @@ CREATE TABLE `tb_key_word` (
|
||||
`inc_f1` bigint(20) NOT NULL DEFAULT '0',
|
||||
`update` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_key_word
|
||||
|
||||
@@ -24,7 +24,7 @@ CREATE TABLE `tb` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
@@ -43,7 +43,7 @@ CREATE TABLE `tb_blobs` (
|
||||
`field2` longtext COMMENT '注释2',
|
||||
`field3` longtext,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
@@ -60,7 +60,7 @@ CREATE TABLE `tb_keys` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
|
||||
@@ -24,7 +24,7 @@ CREATE TABLE `tb` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
@@ -44,7 +44,7 @@ CREATE TABLE `tb_blobs` (
|
||||
`field2` longtext COMMENT '注释2',
|
||||
`field3` longtext,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
@@ -64,7 +64,7 @@ CREATE TABLE `tb_keys` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
@@ -82,7 +82,7 @@ CREATE TABLE `tb_single_blob` (
|
||||
`field1` longtext COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_single_blob
|
||||
|
||||
@@ -26,7 +26,7 @@ CREATE TABLE `tb` (
|
||||
`inc_f2` bigint(20) NOT NULL DEFAULT '0',
|
||||
`inc_f3` bigint(20) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
|
||||
@@ -24,7 +24,7 @@ CREATE TABLE `tb` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb
|
||||
@@ -43,11 +43,14 @@ CREATE TABLE `tb_blobs` (
|
||||
`field2` longtext COMMENT '注释2',
|
||||
`field3` longtext,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_blobs
|
||||
-- ----------------------------
|
||||
INSERT INTO `tb_blobs` VALUES ('1', 'fd1', null, 'KK1');
|
||||
INSERT INTO `tb_blobs` VALUES ('2', null, '2', null);
|
||||
INSERT INTO `tb_blobs` VALUES ('3', 'fd3', '3', 'KK3');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb_keys
|
||||
@@ -59,7 +62,7 @@ CREATE TABLE `tb_keys` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`key1`,`key2`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_keys
|
||||
@@ -77,7 +80,7 @@ CREATE TABLE `tb_single_blob` (
|
||||
`field1` longtext COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of tb_single_blob
|
||||
@@ -92,7 +95,7 @@ CREATE TABLE `tb_with_inc_id` (
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`field2` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
-- ----------------------------
|
||||
-- Table structure for tb_with_inc_id
|
||||
-- ----------------------------
|
||||
@@ -107,7 +110,7 @@ CREATE TABLE `tb_blobs_with_inc_id` (
|
||||
`field2` longtext COMMENT '注释3',
|
||||
`field3` longtext,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
|
||||
-- ----------------------------
|
||||
-- Table structure for tb_blobs_with_inc_id
|
||||
-- ----------------------------
|
||||
@@ -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">
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.UpsertPlugin">
|
||||
<property name="allowBatchUpsert" value="true"/>
|
||||
</plugin>
|
||||
<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=""/>
|
||||
<!--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"/>
|
||||
<table tableName="tb_keys"/>
|
||||
<table tableName="tb_single_blob"/>
|
||||
<table tableName="tb_blobs"/>
|
||||
<table tableName="tb_with_inc_id">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
<table tableName="tb_blobs_with_inc_id">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
Reference in New Issue
Block a user