From 0d11c8d20748381e04a9dd36515709a2b39b93bb Mon Sep 17 00:00:00 2001 From: ztyzbb <741073274@qq.com> Date: Sat, 18 Aug 2018 16:44:59 +0800 Subject: [PATCH 001/109] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8UpdateByExam?= =?UTF-8?q?ple=E4=B8=80=E4=B8=AA=E5=90=AB=E4=B9=90=E8=A7=82=E9=94=81?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E4=BD=93=E6=97=B6=E6=8A=A5=E7=9A=84BindingEx?= =?UTF-8?q?ception=EF=BC=8C=E5=90=8C=E6=A0=B7=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=BF=98=E6=9C=89UpdateByExampleSelective=E3=80=81UpdateByDiff?= =?UTF-8?q?er=E3=80=81UpdateByPrimaryKeySelectiveForce=20=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3EntityColumn=E7=9A=84=E6=B3=A8=E9=87=8A=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20=E4=B8=BASqlHelper#whereVersion=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B8=A6=E5=AE=9E=E4=BD=93=E5=90=8D=E7=A7=B0=E7=9A=84=E9=87=8D?= =?UTF-8?q?=E8=BD=BD=20=E6=9C=AA=E8=83=BD=E4=BF=AE=E5=A4=8DUpdateByExample?= =?UTF-8?q?=E7=9A=84=E4=B9=90=E8=A7=82=E9=94=81=E5=A4=B1=E6=95=88=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E6=89=BE=E4=B8=8D=E5=88=B0=E5=90=88=E9=80=82?= =?UTF-8?q?=E7=9A=84=E5=9C=B0=E6=96=B9=E6=8F=92=E5=85=A5=E4=B9=90=E8=A7=82?= =?UTF-8?q?=E9=94=81=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=EF=BC=8C=E8=AF=A6?= =?UTF-8?q?=E8=A7=81ExampleProvider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/provider/ExampleProvider.java | 10 ++++++ .../mybatis/mapper/entity/EntityColumn.java | 2 +- .../mapper/mapperhelper/SqlHelper.java | 36 +++++++++++++------ .../update/differ/UpdateByDifferProvider.java | 2 +- ...ateByPrimaryKeySelectiveForceProvider.java | 14 +++++--- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java b/base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java index 32d5af748..9e43fa4c4 100644 --- a/base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java +++ b/base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java @@ -134,6 +134,11 @@ public String updateByExampleSelective(MappedStatement ms) { sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass), "example")); sql.append(SqlHelper.updateSetColumns(entityClass, "record", true, isNotEmpty())); sql.append(SqlHelper.updateByExampleWhereClause()); + //TODO 加入乐观锁查询条件 + //乐观锁条件,加在example后面,有两个问题 + // 1.会和example的条件混在一起,导致or和and逻辑混乱 + // 2.如果example为空,会缺少WHERE + //sql.append(SqlHelper.whereVersion(entityClass, "record")); return sql.toString(); } @@ -156,6 +161,11 @@ public String updateByExample(MappedStatement ms) { sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass), "example")); sql.append(SqlHelper.updateSetColumns(entityClass, "record", false, false)); sql.append(SqlHelper.updateByExampleWhereClause()); + //TODO 加入乐观锁查询条件 + //乐观锁条件,加在example后面,有两个问题 + // 1.会和example的条件混在一起,导致or和and逻辑混乱 + // 2.如果example为空,会缺少WHERE + //sql.append(SqlHelper.whereVersion(entityClass, "record")); return sql.toString(); } diff --git a/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java b/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java index 323d66c80..23d319010 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java @@ -72,7 +72,7 @@ public EntityColumn(EntityTable table) { } /** - * 返回格式如:colum = #{age,jdbcType=NUMERIC,typeHandler=MyTypeHandler} + * 返回格式如:colum = #{entityName.age,jdbcType=NUMERIC,typeHandler=MyTypeHandler} * * @param entityName * @return diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java index 095641dfc..9df22482d 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java @@ -436,14 +436,14 @@ public static String insertValuesColumns(Class entityClass, boolean skipId, b return sql.toString(); } - /** + /** * update set列 * - * @param entityClass + * @param entityClass 实体Class * @param entityName 实体映射名 * @param notNull 是否判断!=null * @param notEmpty 是否判断String类型!='' - * @return + * @return XML中的SET语句块 */ public static String updateSetColumns(Class entityClass, String entityName, boolean notNull, boolean notEmpty) { StringBuilder sql = new StringBuilder(); @@ -467,14 +467,17 @@ public static String updateSetColumns(Class entityClass, String entityName, b //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)} sql.append(column.getColumn()) .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") - .append("@").append(versionClass).append("@class, ") - .append(column.getProperty()).append(")},"); + .append("@").append(versionClass).append("@class, "); + if (StringUtil.isNotEmpty(entityName)) { + sql.append(entityName).append('.'); + } + sql.append(column.getProperty()).append(")},"); } else if (notNull) { sql.append(SqlHelper.getIfNotNull(entityName, column, column.getColumnEqualsHolder(entityName) + ",", notEmpty)); } else { - sql.append(column.getColumnEqualsHolder(entityName) + ","); + sql.append(column.getColumnEqualsHolder(entityName)).append(","); } - } else if(column.isId() && column.isUpdatable()){ + } else if (column.isId() && column.isUpdatable()) { //set id = id, sql.append(column.getColumn()).append(" = ").append(column.getColumn()).append(","); } @@ -496,7 +499,7 @@ public static String notAllNullParameterCheck(String parameterName, Set 0){ + if (fields.length() > 0) { fields.append(","); } fields.append(column.getProperty()); @@ -548,7 +551,7 @@ public static String wherePKColumns(Class entityClass, boolean useVersion) { * @param useVersion * @return */ - public static String wherePKColumns(Class entityClass,String entityName, boolean useVersion) { + public static String wherePKColumns(Class entityClass, String entityName, boolean useVersion) { StringBuilder sql = new StringBuilder(); sql.append(""); //获取全部列 @@ -607,7 +610,18 @@ public static String whereAllIfColumns(Class entityClass, boolean empty, bool * @param entityClass * @return */ - public static String whereVersion(Class entityClass) { + public static String whereVersion(Class entityClass){ + return whereVersion(entityClass,null); + } + + /** + * 乐观锁字段条件 + * + * @param entityClass + * @param entityName 实体名称 + * @return + */ + public static String whereVersion(Class entityClass,String entityName) { Set columnSet = EntityHelper.getColumns(entityClass); boolean hasVersion = false; String result = ""; @@ -617,7 +631,7 @@ public static String whereVersion(Class entityClass) { throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); } hasVersion = true; - result = " AND " + column.getColumnEqualsHolder(); + result = " AND " + column.getColumnEqualsHolder(entityName); } } return result; diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java index 1de389093..7ffce1854 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java @@ -134,7 +134,7 @@ public String updateSetColumnsByDiffer(Class entityClass) { sql.append(column.getColumn()) .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") .append("@").append(versionClass).append("@class, ") - .append(column.getProperty()).append(")},"); + .append(NEWER).append('.').append(column.getProperty()).append(")},"); } else { //if old.xx != newer.xx sql.append(getIfNotEqual(column, column.getColumnEqualsHolder(NEWER) + ",")); diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java index e1c2cbc77..ec658ba7e 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java @@ -37,8 +37,8 @@ import java.util.Set; /** - * @Description: 通用Mapper接口,更新,强制,实现 * @author qrqhuangcy + * @Description: 通用Mapper接口, 更新, 强制,实现 * @date 2018-06-26 */ public class UpdateByPrimaryKeySelectiveForceProvider extends MapperTemplate { @@ -91,14 +91,18 @@ public String updateSetColumnsForce(Class entityClass, String entityName, boo //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)} sql.append(column.getColumn()) .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") - .append("@").append(versionClass).append("@class, ") - .append(column.getProperty()).append(")},"); + .append("@").append(versionClass).append("@class, "); + //虽然从函数调用上来看entityName必为"record",但还是判断一下 + if (StringUtil.isNotEmpty(entityName)) { + sql.append(entityName).append('.'); + } + sql.append(column.getProperty()).append(")},"); } else if (notNull) { sql.append(this.getIfNotNull(entityName, column, column.getColumnEqualsHolder(entityName) + ",", notEmpty)); } else { - sql.append(column.getColumnEqualsHolder(entityName) + ","); + sql.append(column.getColumnEqualsHolder(entityName)).append(","); } - } else if(column.isId() && column.isUpdatable()){ + } else if (column.isId() && column.isUpdatable()) { //set id = id, sql.append(column.getColumn()).append(" = ").append(column.getColumn()).append(","); } From 574589a58e031f49cc602ae2860ae07f9f7594b5 Mon Sep 17 00:00:00 2001 From: calvinit <541298948@qq.com> Date: Thu, 14 Feb 2019 13:52:07 +0800 Subject: [PATCH 002/109] =?UTF-8?q?=E5=A2=9E=E5=8A=A0lombokEqualsAndHashCo?= =?UTF-8?q?deCallSuper=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=BD=93=E4=BD=BF?= =?UTF-8?q?=E7=94=A8lombok=E6=89=A9=E5=B1=95=E7=9A=84EqualsAndHashCode?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E6=97=B6=EF=BC=8C=E5=8F=AF=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E6=AD=A4=E9=85=8D=E7=BD=AE=EF=BC=88true=EF=BC=89=E4=B8=BA?= =?UTF-8?q?=E6=AD=A4=E6=B3=A8=E8=A7=A3=E6=B7=BB=E5=8A=A0=E2=80=9CcallSuper?= =?UTF-8?q?=20=3D=20true=E2=80=9D=EF=BC=8C=E8=BF=99=E5=AF=B9=E4=BA=8E?= =?UTF-8?q?=E6=9C=89=E7=BB=A7=E6=89=BF=E7=88=B6=E7=B1=BB=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=B1=BB=EF=BC=8C=E5=A6=82=E5=A2=9E=E5=8A=A0=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8A=A8=E6=80=81=E8=A1=A8=E5=90=8D=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=9C=89=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/generator/MapperPlugin.java | 55 +++++++++++-------- .../src/test/resources/generatorConfig.xml | 6 +- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index b51ab2184..ded22a0e8 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -65,6 +65,8 @@ public class MapperPlugin extends FalseMethodPlugin { private boolean needsAccessors = false; //是否需要生成EqualsAndHashCode注解 private boolean needsEqualsAndHashCode = false; + //是否需要生成EqualsAndHashCode注解,并且“callSuper = true”,如果此注解配置为true,则忽略needsEqualsAndHashCode的配置 + private boolean needsEqualsAndHashCodeAndCallSuper = false; //是否生成字段名常量 private boolean generateColumnConsts = false; //是否生成默认的属性的静态方法 @@ -113,40 +115,46 @@ public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - //引入JPA注解 + // 引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); - //lombok扩展开始 - //如果需要Data,引入包,代码增加注解 + // lombok扩展开始 + // 如果需要Data,引入包,代码增加注解 if (this.needsData) { topLevelClass.addImportedType("lombok.Data"); topLevelClass.addAnnotation("@Data"); } - //如果需要Getter,引入包,代码增加注解 + // 如果需要Getter,引入包,代码增加注解 if (this.needsGetter) { topLevelClass.addImportedType("lombok.Getter"); topLevelClass.addAnnotation("@Getter"); } - //如果需要Setter,引入包,代码增加注解 + // 如果需要Setter,引入包,代码增加注解 if (this.needsSetter) { topLevelClass.addImportedType("lombok.Setter"); topLevelClass.addAnnotation("@Setter"); } - //如果需要ToString,引入包,代码增加注解 + // 如果需要ToString,引入包,代码增加注解 if (this.needsToString) { topLevelClass.addImportedType("lombok.ToString"); topLevelClass.addAnnotation("@ToString"); } - //如果需要Getter,引入包,代码增加注解 + // 如果需要EqualsAndHashCode,并且“callSuper = true”,引入包,代码增加注解 + if (this.needsEqualsAndHashCodeAndCallSuper) { + topLevelClass.addImportedType("lombok.EqualsAndHashCode"); + topLevelClass.addAnnotation("@EqualsAndHashCode(callSuper = true)"); + } else { + // 如果需要EqualsAndHashCode,引入包,代码增加注解 + if (this.needsEqualsAndHashCode) { + topLevelClass.addImportedType("lombok.EqualsAndHashCode"); + topLevelClass.addAnnotation("@EqualsAndHashCode"); + } + } + // 如果需要Getter,引入包,代码增加注解 if (this.needsAccessors) { topLevelClass.addImportedType("lombok.experimental.Accessors"); topLevelClass.addAnnotation("@Accessors(chain = true)"); } - //如果需要Getter,引入包,代码增加注解 - if (this.needsEqualsAndHashCode) { - topLevelClass.addImportedType("lombok.EqualsAndHashCode"); - topLevelClass.addAnnotation("@EqualsAndHashCode"); - } - //lombok扩展结束 + // lombok扩展结束 // region swagger扩展 if (this.needsSwagger) { //导包 @@ -161,13 +169,13 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i } // endregion swagger扩展 String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); - //如果包含空格,或者需要分隔符,需要完善 + // 如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } - //是否忽略大小写,对于区分大小写的数据库,会有用 + // 是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { @@ -216,7 +224,7 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i } if (introspectedColumn.getDefaultValue() != null) { String defaultValue = introspectedColumn.getDefaultValue(); - //去除前后'',如 '123456' -> 123456 + // 去除前后'',如 '123456' -> 123456 if (defaultValue.startsWith("'") && defaultValue.endsWith("'")) { if (defaultValue.length() == 2) { defaultValue = ""; @@ -224,7 +232,7 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i defaultValue = defaultValue.substring(1, defaultValue.length() - 1); } } - //暂不支持时间类型默认值识别,不同数据库表达式不同 + // 暂不支持时间类型默认值识别,不同数据库表达式不同 if ("Boolean".equals(shortName)) { if ("0".equals(defaultValue)) { defaultValue = "false"; @@ -232,7 +240,7 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i defaultValue = "true"; } } - //通过 new 方法转换 + // 通过 new 方法转换 defaultMethod.addBodyLine(String.format("instance.%s = new %s(\"%s\");", introspectedColumn.getJavaProperty(), shortName, defaultValue)); } @@ -337,20 +345,23 @@ public void setProperties(Properties properties) { this.beginningDelimiter = getProperty("beginningDelimiter", ""); this.endingDelimiter = getProperty("endingDelimiter", ""); this.schema = getProperty("schema"); - //lombok扩展 + // lombok扩展 String lombok = getProperty("lombok"); if (lombok != null && !"".equals(lombok)) { this.needsData = lombok.contains("Data"); - //@Data 优先级高于 @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode + // @Data 优先级高于 @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode this.needsGetter = !this.needsData && lombok.contains("Getter"); this.needsSetter = !this.needsData && lombok.contains("Setter"); this.needsToString = !this.needsData && lombok.contains("ToString"); this.needsEqualsAndHashCode = !this.needsData && lombok.contains("EqualsAndHashCode"); + // 配置lombok扩展EqualsAndHashCode注解是否添加“callSuper = true” + String lombokEqualsAndHashCodeCallSuper = getProperty("lombokEqualsAndHashCodeCallSuper", "false"); + this.needsEqualsAndHashCodeAndCallSuper = this.needsEqualsAndHashCode && "TRUE".equalsIgnoreCase(lombokEqualsAndHashCodeCallSuper); this.needsAccessors = lombok.contains("Accessors"); } - //swagger扩展 + // swagger扩展 String swagger = getProperty("swagger", "false"); - if ("true".equalsIgnoreCase(swagger)) { + if ("TRUE".equalsIgnoreCase(swagger)) { this.needsSwagger = true; } if (useMapperCommentGenerator) { diff --git a/generator/src/test/resources/generatorConfig.xml b/generator/src/test/resources/generatorConfig.xml index b6c0da5b0..f5988c5aa 100644 --- a/generator/src/test/resources/generatorConfig.xml +++ b/generator/src/test/resources/generatorConfig.xml @@ -41,8 +41,10 @@ - - + + + + From ae901608a2532b5f0ff598c4b96f87d43b27afaa Mon Sep 17 00:00:00 2001 From: calvinit <541298948@qq.com> Date: Thu, 14 Feb 2019 13:52:07 +0800 Subject: [PATCH 003/109] =?UTF-8?q?=E5=A2=9E=E5=8A=A0lombokEqualsAndHashCo?= =?UTF-8?q?deCallSuper=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=BD=93=E4=BD=BF?= =?UTF-8?q?=E7=94=A8lombok=E6=89=A9=E5=B1=95=E7=9A=84EqualsAndHashCode?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E6=97=B6=EF=BC=8C=E5=8F=AF=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E6=AD=A4=E9=85=8D=E7=BD=AE=EF=BC=88true=EF=BC=89=E4=B8=BA?= =?UTF-8?q?=E6=AD=A4=E6=B3=A8=E8=A7=A3=E6=B7=BB=E5=8A=A0=E2=80=9CcallSuper?= =?UTF-8?q?=20=3D=20true=E2=80=9D=EF=BC=8C=E8=BF=99=E5=AF=B9=E4=BA=8E?= =?UTF-8?q?=E6=9C=89=E7=BB=A7=E6=89=BF=E7=88=B6=E7=B1=BB=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=B1=BB=EF=BC=8C=E5=A6=82=E5=A2=9E=E5=8A=A0=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8A=A8=E6=80=81=E8=A1=A8=E5=90=8D=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=9C=89=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/generator/MapperPlugin.java | 55 +++++++++++-------- .../src/test/resources/generatorConfig.xml | 6 +- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index b51ab2184..24ac56f61 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -65,6 +65,8 @@ public class MapperPlugin extends FalseMethodPlugin { private boolean needsAccessors = false; //是否需要生成EqualsAndHashCode注解 private boolean needsEqualsAndHashCode = false; + //是否需要生成EqualsAndHashCode注解,并且“callSuper = true” + private boolean needsEqualsAndHashCodeAndCallSuper = false; //是否生成字段名常量 private boolean generateColumnConsts = false; //是否生成默认的属性的静态方法 @@ -113,40 +115,46 @@ public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - //引入JPA注解 + // 引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); - //lombok扩展开始 - //如果需要Data,引入包,代码增加注解 + // lombok扩展开始 + // 如果需要Data,引入包,代码增加注解 if (this.needsData) { topLevelClass.addImportedType("lombok.Data"); topLevelClass.addAnnotation("@Data"); } - //如果需要Getter,引入包,代码增加注解 + // 如果需要Getter,引入包,代码增加注解 if (this.needsGetter) { topLevelClass.addImportedType("lombok.Getter"); topLevelClass.addAnnotation("@Getter"); } - //如果需要Setter,引入包,代码增加注解 + // 如果需要Setter,引入包,代码增加注解 if (this.needsSetter) { topLevelClass.addImportedType("lombok.Setter"); topLevelClass.addAnnotation("@Setter"); } - //如果需要ToString,引入包,代码增加注解 + // 如果需要ToString,引入包,代码增加注解 if (this.needsToString) { topLevelClass.addImportedType("lombok.ToString"); topLevelClass.addAnnotation("@ToString"); } - //如果需要Getter,引入包,代码增加注解 + // 如果需要EqualsAndHashCode,并且“callSuper = true”,引入包,代码增加注解 + if (this.needsEqualsAndHashCodeAndCallSuper) { + topLevelClass.addImportedType("lombok.EqualsAndHashCode"); + topLevelClass.addAnnotation("@EqualsAndHashCode(callSuper = true)"); + } else { + // 如果需要EqualsAndHashCode,引入包,代码增加注解 + if (this.needsEqualsAndHashCode) { + topLevelClass.addImportedType("lombok.EqualsAndHashCode"); + topLevelClass.addAnnotation("@EqualsAndHashCode"); + } + } + // 如果需要Getter,引入包,代码增加注解 if (this.needsAccessors) { topLevelClass.addImportedType("lombok.experimental.Accessors"); topLevelClass.addAnnotation("@Accessors(chain = true)"); } - //如果需要Getter,引入包,代码增加注解 - if (this.needsEqualsAndHashCode) { - topLevelClass.addImportedType("lombok.EqualsAndHashCode"); - topLevelClass.addAnnotation("@EqualsAndHashCode"); - } - //lombok扩展结束 + // lombok扩展结束 // region swagger扩展 if (this.needsSwagger) { //导包 @@ -161,13 +169,13 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i } // endregion swagger扩展 String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); - //如果包含空格,或者需要分隔符,需要完善 + // 如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } - //是否忽略大小写,对于区分大小写的数据库,会有用 + // 是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { @@ -216,7 +224,7 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i } if (introspectedColumn.getDefaultValue() != null) { String defaultValue = introspectedColumn.getDefaultValue(); - //去除前后'',如 '123456' -> 123456 + // 去除前后'',如 '123456' -> 123456 if (defaultValue.startsWith("'") && defaultValue.endsWith("'")) { if (defaultValue.length() == 2) { defaultValue = ""; @@ -224,7 +232,7 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i defaultValue = defaultValue.substring(1, defaultValue.length() - 1); } } - //暂不支持时间类型默认值识别,不同数据库表达式不同 + // 暂不支持时间类型默认值识别,不同数据库表达式不同 if ("Boolean".equals(shortName)) { if ("0".equals(defaultValue)) { defaultValue = "false"; @@ -232,7 +240,7 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i defaultValue = "true"; } } - //通过 new 方法转换 + // 通过 new 方法转换 defaultMethod.addBodyLine(String.format("instance.%s = new %s(\"%s\");", introspectedColumn.getJavaProperty(), shortName, defaultValue)); } @@ -337,20 +345,23 @@ public void setProperties(Properties properties) { this.beginningDelimiter = getProperty("beginningDelimiter", ""); this.endingDelimiter = getProperty("endingDelimiter", ""); this.schema = getProperty("schema"); - //lombok扩展 + // lombok扩展 String lombok = getProperty("lombok"); if (lombok != null && !"".equals(lombok)) { this.needsData = lombok.contains("Data"); - //@Data 优先级高于 @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode + // @Data 优先级高于 @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode this.needsGetter = !this.needsData && lombok.contains("Getter"); this.needsSetter = !this.needsData && lombok.contains("Setter"); this.needsToString = !this.needsData && lombok.contains("ToString"); this.needsEqualsAndHashCode = !this.needsData && lombok.contains("EqualsAndHashCode"); + // 配置lombok扩展EqualsAndHashCode注解是否添加“callSuper = true” + String lombokEqualsAndHashCodeCallSuper = getProperty("lombokEqualsAndHashCodeCallSuper", "false"); + this.needsEqualsAndHashCodeAndCallSuper = this.needsEqualsAndHashCode && "TRUE".equalsIgnoreCase(lombokEqualsAndHashCodeCallSuper); this.needsAccessors = lombok.contains("Accessors"); } - //swagger扩展 + // swagger扩展 String swagger = getProperty("swagger", "false"); - if ("true".equalsIgnoreCase(swagger)) { + if ("TRUE".equalsIgnoreCase(swagger)) { this.needsSwagger = true; } if (useMapperCommentGenerator) { diff --git a/generator/src/test/resources/generatorConfig.xml b/generator/src/test/resources/generatorConfig.xml index b6c0da5b0..f5988c5aa 100644 --- a/generator/src/test/resources/generatorConfig.xml +++ b/generator/src/test/resources/generatorConfig.xml @@ -41,8 +41,10 @@ - - + + + + From b4acbf485562ddc8fcc283e057744e02d7416354 Mon Sep 17 00:00:00 2001 From: wugh <328043740@qq.com> Date: Thu, 30 May 2019 11:28:22 +0800 Subject: [PATCH 004/109] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=AE=9E=E4=BD=93=E7=B1=BB=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?,=E4=BD=BF=E7=94=A8=E8=A1=A8=E6=B3=A8=E9=87=8A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=B1=BB=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/generator/MapperPlugin.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index b51ab2184..7010bbacf 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -161,6 +161,27 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i } // endregion swagger扩展 String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); + + //region 文档注释 + String remarks = introspectedTable.getRemarks(); + topLevelClass.addJavaDocLine("/**"); + topLevelClass.addJavaDocLine(" * 表名:" + tableName); + if (remarks != null) { + remarks = remarks.trim(); + } + if (remarks != null && remarks.trim().length() > 0) { + String[] lines = remarks.split("\\r?\\n"); + for (int i = 0; i < lines.length; i++) { + String line = lines[i]; + if (i == 0) { + topLevelClass.addJavaDocLine(" * 表注释:" + line); + } else { + topLevelClass.addJavaDocLine(" * " + line); + } + } + } + topLevelClass.addJavaDocLine("*/"); + //endregion //如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() From cf3e40aacf0f64f0a228ad6c76b67ba157c4121d Mon Sep 17 00:00:00 2001 From: wugh <328043740@qq.com> Date: Thu, 30 May 2019 13:58:07 +0800 Subject: [PATCH 005/109] =?UTF-8?q?[bug=E4=BF=AE=E5=A4=8D]=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DgenerateDefaultInstanceMethod=E5=8F=82=E6=95=B0,?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E5=AE=9E=E4=BD=93=E7=B1=BB=E7=9A=84?= =?UTF-8?q?defaultInstance=E9=9D=99=E6=80=81=E6=96=B9=E5=BC=8F.=201.?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E9=BB=98=E8=AE=A4=E5=80=BC=E4=B8=BA''::chara?= =?UTF-8?q?cter=20varying=E9=97=AE=E9=A2=98=202.=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/generator/MapperPlugin.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index 7010bbacf..0f504242f 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -223,7 +223,15 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i } } if (generateDefaultInstanceMethod) { + //注意基本类型和包装的index要一致,方便后面使用 + List baseClassName = Arrays.asList("byte", "short", "char", "int", "long", "float", "double", "boolean"); + List wrapperClassName = Arrays.asList("Byte", "Short", "Character", "Integer", "Long", "Float", "Double", "Boolean"); + List otherClassName = Arrays.asList("String", "BigDecimal", "BigInteger"); Method defaultMethod = new Method(); + //增加方法注释 + defaultMethod.addJavaDocLine("/**"); + defaultMethod.addJavaDocLine(" * 带默认值的实例"); + defaultMethod.addJavaDocLine("*/"); defaultMethod.setStatic(true); defaultMethod.setName("defaultInstance"); defaultMethod.setVisibility(JavaVisibility.PUBLIC); @@ -231,12 +239,16 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i defaultMethod.addBodyLine(String.format("%s instance = new %s();", topLevelClass.getType().getShortName(), topLevelClass.getType().getShortName())); for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { String shortName = introspectedColumn.getFullyQualifiedJavaType().getShortName(); - List supportType = Arrays.asList("Byte", "Short", "Character", "Integer", "Long", "Float", "Double", "String", "BigDecimal", "BigInteger"); - if (!supportType.contains(shortName)) { + if (!baseClassName.contains(shortName) && !wrapperClassName.contains(shortName) && !otherClassName.contains(shortName)) { continue; } if (introspectedColumn.getDefaultValue() != null) { String defaultValue = introspectedColumn.getDefaultValue(); + //处理备注中带有类型描述情况,如 postgresql中存在 ''::character varying + if (defaultValue.matches("'\\.*'::\\w+(\\s\\w+)?")) { + // + defaultValue = defaultValue.substring(0, defaultValue.lastIndexOf("::")); + } //去除前后'',如 '123456' -> 123456 if (defaultValue.startsWith("'") && defaultValue.endsWith("'")) { if (defaultValue.length() == 2) { @@ -246,15 +258,27 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i } } //暂不支持时间类型默认值识别,不同数据库表达式不同 - if ("Boolean".equals(shortName)) { + if ("Boolean".equals(shortName) || "boolean".equals(shortName)) { if ("0".equals(defaultValue)) { defaultValue = "false"; } else if ("1".equals(defaultValue)) { defaultValue = "true"; } } - //通过 new 方法转换 - defaultMethod.addBodyLine(String.format("instance.%s = new %s(\"%s\");", introspectedColumn.getJavaProperty(), shortName, defaultValue)); + + if ("String".equals(shortName)) { + //字符串,不通过new String 创建 + // 其实通过new String 没有任何问题,不过强迫症,idea会提示,所以改了 + defaultMethod.addBodyLine(String.format("instance.%s = \"%s\";", introspectedColumn.getJavaProperty(), defaultValue)); + } else { + String javaProperty = introspectedColumn.getJavaProperty(); + if (baseClassName.contains(shortName)) { + //基本类型,转成包装类的new 创建 + javaProperty = wrapperClassName.get(baseClassName.indexOf(shortName)); + } + //通过 new 方法转换 + defaultMethod.addBodyLine(String.format("instance.%s = new %s(\"%s\");", javaProperty, shortName, defaultValue)); + } } } From 3e25bb9bad66a2b38a4039b84ad4f95ae168f932 Mon Sep 17 00:00:00 2001 From: wugh <328043740@qq.com> Date: Thu, 30 May 2019 14:41:30 +0800 Subject: [PATCH 006/109] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=20Weekend=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=A2=9E=E5=8A=A0excludeProperties=E3=80=81selectProp?= =?UTF-8?q?erties=E3=80=81orderBy=E3=80=81withCountProperty=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81lambda=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=86=99=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=90=8D=20=E4=BD=BF=E7=94=A8withXXXXX=E7=9A=84?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E6=96=B9=E5=BC=8F=E9=93=BE=E5=BC=8F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/weekend/Weekend.java | 51 +++++++++++++++++++ .../mapper/weekend/UserMapperTest.java | 16 ++++++ 2 files changed, 67 insertions(+) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/Weekend.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/Weekend.java index 3d5520d87..3490610a0 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/Weekend.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/Weekend.java @@ -25,6 +25,10 @@ package tk.mybatis.mapper.weekend; +import tk.mybatis.mapper.weekend.reflection.Reflections; + +import java.util.stream.Stream; + /** * @author Frank */ @@ -69,4 +73,51 @@ public WeekendCriteria weekendCriteria() { return (WeekendCriteria) this.createCriteria(); } + /** + * 排除查询字段,优先级低于 selectProperties + * + * @param fns 属性名的可变参数 + * @return + */ + public Weekend excludeProperties(Fn... fns) { + String[] properties = Stream.of(fns).map(Reflections::fnToFieldName).toArray(String[]::new); + this.excludeProperties(properties); + return this; + } + + /** + * 指定要查询的属性列 - 这里会自动映射到表字段 + * + * @param fns + * @return + */ + public Weekend selectProperties(Fn... fns) { + String[] properties = Stream.of(fns).map(Reflections::fnToFieldName).toArray(String[]::new); + this.selectProperties(properties); + return this; + } + + public OrderBy orderBy(Fn fn) { + return this.orderBy(Reflections.fnToFieldName(fn)); + } + + public Weekend withDistinct(boolean distinct) { + this.setDistinct(distinct); + return this; + } + + public Weekend withForUpdate(boolean forUpdate) { + this.setForUpdate(forUpdate); + return this; + } + + public Weekend withCountProperty(Fn fn) { + this.setCountProperty(Reflections.fnToFieldName(fn)); + return this; + } + + public Weekend withTableName(String tableName) { + this.setTableName(tableName); + return this; + } } diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java index 3a6120edc..ec33b7012 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java @@ -29,7 +29,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; +import tk.mybatis.mapper.weekend.entity.Country; import tk.mybatis.mapper.weekend.entity.User; +import tk.mybatis.mapper.weekend.mapper.CountryMapper; import tk.mybatis.mapper.weekend.mapper.UserMapper; import java.util.Arrays; @@ -61,4 +63,18 @@ public void testSelectIdIsNull(){ System.out.println(user.getUserName()); } } + @Test + public void testExcludeAndSelectProperties(){ + SqlSession sqlSession = MybatisHelper.getSqlSession(); + CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class); + Weekend weekend1 = Weekend.of(Country.class); + weekend1.excludeProperties(Country::getId,Country::getCountryname); + //查看日志执行的sql + countryMapper.selectByExample(weekend1); + Weekend weekend2 = Weekend.of(Country.class); + weekend2.selectProperties(Country::getId); + //查看日志执行的sql + countryMapper.selectByExample(weekend2); + + } } From dbe24fef75a34992c6ddbd25fdd5060618200f7c Mon Sep 17 00:00:00 2001 From: isea533 Date: Thu, 30 May 2019 21:28:52 +0800 Subject: [PATCH 007/109] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20count=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/tk/mybatis/mapper/weekend/UserMapperTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java index ec33b7012..6617c120f 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java @@ -75,6 +75,9 @@ public void testExcludeAndSelectProperties(){ weekend2.selectProperties(Country::getId); //查看日志执行的sql countryMapper.selectByExample(weekend2); + //count 查询 + weekend2.withCountProperty(Country::getCountryname); + countryMapper.selectCountByExample(weekend2); } } From 1764748eedb2f320a0d1c43cb4f928c4ccb1f2f5 Mon Sep 17 00:00:00 2001 From: isea533 Date: Tue, 18 Jun 2019 22:03:36 +0800 Subject: [PATCH 008/109] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=BC=82=E5=B8=B8=E5=92=8C=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8Cfixed=20#IXNLU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/mapperhelper/MapperHelper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java index 2978dc6ad..d3b86352a 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java @@ -29,6 +29,8 @@ import org.apache.ibatis.annotations.SelectProvider; import org.apache.ibatis.annotations.UpdateProvider; import org.apache.ibatis.builder.annotation.ProviderSqlSource; +import org.apache.ibatis.logging.Log; +import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.session.Configuration; import tk.mybatis.mapper.MapperException; @@ -53,6 +55,8 @@ */ public class MapperHelper { + private static final Log log = LogFactory.getLog(MapperHelper.class); + /** * 注册的接口 */ @@ -117,6 +121,7 @@ private MapperTemplate fromMapperClass(Class mapperClass) { if (templateClass == null) { templateClass = tempClass; } else if (templateClass != tempClass) { + log.error("一个通用Mapper中只允许存在一个MapperTemplate子类!"); throw new MapperException("一个通用Mapper中只允许存在一个MapperTemplate子类!"); } } @@ -127,6 +132,7 @@ private MapperTemplate fromMapperClass(Class mapperClass) { try { mapperTemplate = (MapperTemplate) templateClass.getConstructor(Class.class, MapperHelper.class).newInstance(mapperClass, this); } catch (Exception e) { + log.error("实例化MapperTemplate对象失败:" + e, e); throw new MapperException("实例化MapperTemplate对象失败:" + e.getMessage()); } //注册方法 @@ -134,6 +140,7 @@ private MapperTemplate fromMapperClass(Class mapperClass) { try { mapperTemplate.addMethodMap(methodName, templateClass.getMethod(methodName, MappedStatement.class)); } catch (NoSuchMethodException e) { + log.error(templateClass.getCanonicalName() + "中缺少" + methodName + "方法!", e); throw new MapperException(templateClass.getCanonicalName() + "中缺少" + methodName + "方法!"); } } @@ -168,6 +175,7 @@ public void registerMapper(String mapperClass) { try { registerMapper(Class.forName(mapperClass)); } catch (ClassNotFoundException e) { + log.error("注册通用Mapper[" + mapperClass + "]失败,找不到该通用Mapper!", e); throw new MapperException("注册通用Mapper[" + mapperClass + "]失败,找不到该通用Mapper!"); } } @@ -188,6 +196,7 @@ public MapperTemplate isMapperMethod(String msId) { mapperTemplate = getMapperTemplateByMsId(msId); } } catch (Exception e){ + log.warn("特殊情况: " + e); } } return mapperTemplate; @@ -318,6 +327,8 @@ public void setConfig(Config config) { try { EntityHelper.setResolve(config.getResolveClass().newInstance()); } catch (Exception e) { + log.error("创建 " + config.getResolveClass().getCanonicalName() + + " 实例失败,请保证该类有默认的构造方法!", e); throw new MapperException("创建 " + config.getResolveClass().getCanonicalName() + " 实例失败,请保证该类有默认的构造方法!", e); } @@ -343,6 +354,7 @@ public void setProperties(Properties properties) { try { EntityHelper.setResolve((EntityResolve) Class.forName(resolveClass).newInstance()); } catch (Exception e) { + log.error("创建 " + resolveClass + " 实例失败!", e); throw new MapperException("创建 " + resolveClass + " 实例失败!", e); } } From 389dc21df0bd0a62fccb1e0b383a274eb3a94c07 Mon Sep 17 00:00:00 2001 From: wenlh Date: Wed, 18 Sep 2019 17:57:33 +0800 Subject: [PATCH 009/109] =?UTF-8?q?Example=E8=B0=83=E7=94=A8getOredCriteri?= =?UTF-8?q?a=E6=96=B9=E6=B3=95=E8=BF=94=E5=9B=9E=E5=8F=AA=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E4=B8=80=E4=B8=AACriteria=E7=9A=84=E6=95=B0=E7=BB=84?= =?UTF-8?q?=EF=BC=8C=E4=B8=94Criterion=E8=B0=83=E7=94=A8getAllCriteria?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=A9=BAList=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=EF=BC=8C=E9=80=BB=E8=BE=91=E5=88=A0=E9=99=A4=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=90=8E=E4=B8=8D=E5=BA=94=E5=BD=93=E6=8B=BC=E6=8E=A5and?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/tk/mybatis/mapper/util/OGNL.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java index 5884e209d..415de84f6 100644 --- a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java +++ b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java @@ -247,7 +247,7 @@ public static String andNotLogicDelete(Object parameter) { // 如果Example中有条件,则拼接" and ", // 如果是空的oredCriteria,则where中只有逻辑删除注解的未删除条件 - if (example.getOredCriteria() != null && example.getOredCriteria().size() != 0) { + if (hasWhereCause(example)) { result += " and "; } } @@ -256,4 +256,22 @@ public static String andNotLogicDelete(Object parameter) { return result; } + /** + * 检查是否存在where条件,存在返回true,不存在返回false. + * + * @param example + * @return + */ + private static boolean hasWhereCause(Example example) { + if (example.getOredCriteria() == null || example.getOredCriteria().size() == 0) { + return false; + } + for (Example.Criteria oredCriterion : example.getOredCriteria()) { + if (oredCriterion.getAllCriteria().size() != 0) { + return true; + } + } + return false; + } + } From bd101038379a6a2a5c320cb029b6ac136fbf7302 Mon Sep 17 00:00:00 2001 From: jingkaihui Date: Sat, 19 Oct 2019 22:14:08 +0800 Subject: [PATCH 010/109] =?UTF-8?q?=E6=89=A9=E5=B1=95=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=B1=9E=E6=80=A7=E5=8F=8A=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=80=BC=E6=9F=A5=E8=AF=A2=E7=9A=84=E9=80=9A=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/pom.xml | 11 + .../select/SelectByPropertyMapper.java | 81 ++++++ .../select/SelectPropertyProvider.java | 256 ++++++++++++++++++ .../mapper/additional/select/Book.java | 52 ++++ .../mapper/additional/select/BookMapper.java | 8 + .../mapper/additional/select/CreateDB.sql | 13 + .../select/SelectByPropertyMapperTest.java | 111 ++++++++ .../additional/select/mybatis-config.xml | 51 ++++ 8 files changed, 583 insertions(+) create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/select/BookMapper.java create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapperTest.java create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml diff --git a/extra/pom.xml b/extra/pom.xml index 6061e7cb1..9cdeafce1 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -36,6 +36,11 @@ mapper-extra Mybatis 通用 Mapper 扩展方法 + + 1.8 + 1.1.5 + + org.mybatis @@ -47,6 +52,12 @@ ${project.version} provided + + tk.mybatis + mapper-weekend + ${project.version} + provided + tk.mybatis mapper-base diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java new file mode 100644 index 000000000..c1e3243dc --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java @@ -0,0 +1,81 @@ +package tk.mybatis.mapper.additional.select; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.SelectProvider; +import tk.mybatis.mapper.annotation.RegisterMapper; +import tk.mybatis.mapper.weekend.Fn; + +import java.util.List; + +/** + * 根据属性查询接口 + * + * @param 不能为空 + * + * @author jingkaihui + * @date 2019/10/11 + */ +@RegisterMapper +public interface SelectByPropertyMapper { + + /** + * 根据属性及对应值进行查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 + * + * @param fn 查询属性 + * @param value 属性值 + * @return + */ + @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") + T selectOneByProperty(@Param("fn") Fn fn, @Param("value") Object value); + + /** + * 根据属性及对应值进行查询,有多个返回值,查询条件使用等号 + * + * @param fn 查询属性 + * @param value 属性值 + * @return + */ + @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") + List selectByProperty(@Param("fn") Fn fn, @Param("value") Object value); + + /** + * 根据属性及对应值进行查询,查询条件使用 in + * + * @param fn 查询属性 + * @param values 属性值集合,集合不能空 + * @return + */ + @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") + List selectInByProperty(@Param("fn") Fn fn, @Param("values") List values); + + /** + * 根据属性及对应值进行查询,查询条件使用 between + * + * @param fn 查询属性 + * @param begin 开始值 + * @param end 开始值 + * @return + */ + @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") + List selectBetweenByProperty(@Param("fn") Fn fn, @Param("begin") Object begin, @Param("end") Object end); + + /** + * 根据属性及对应值进行查询,检查是否存在对应记录,查询条件使用等号 + * + * @param fn 查询属性 + * @param value 属性值 + * @return + */ + @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") + boolean existsWithProperty(@Param("fn") Fn fn, @Param("value") Object value); + + /** + * 根据属性及对应值进行查询,统计符合条件的记录数,查询条件使用等号 + * + * @param fn 查询属性 + * @param value 属性值 + * @return + */ + @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") + int selectCountByProperty(@Param("fn") Fn fn, @Param("value") Object value); +} diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java new file mode 100644 index 000000000..57fb529b9 --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java @@ -0,0 +1,256 @@ +package tk.mybatis.mapper.additional.select; + +import org.apache.ibatis.logging.Log; +import org.apache.ibatis.logging.LogFactory; +import org.apache.ibatis.mapping.MappedStatement; +import tk.mybatis.mapper.entity.EntityColumn; +import tk.mybatis.mapper.entity.EntityTable; +import tk.mybatis.mapper.mapperhelper.EntityHelper; +import tk.mybatis.mapper.mapperhelper.MapperHelper; +import tk.mybatis.mapper.mapperhelper.MapperTemplate; +import tk.mybatis.mapper.mapperhelper.SqlHelper; +import tk.mybatis.mapper.util.StringUtil; + +import java.util.Objects; + +/** + * @author jingkaihui + * @date 2019/10/11 + */ +public class SelectPropertyProvider extends MapperTemplate { + + private static final Log log = LogFactory.getLog(SelectPropertyProvider.class); + + public SelectPropertyProvider(Class mapperClass, MapperHelper mapperHelper) { + super(mapperClass, mapperHelper); + } + + /**Ba + * 根据属性查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 + * + * @param ms + * @return + */ + public String selectOneByProperty(MappedStatement ms) { + String propertyHelper = SelectPropertyProvider.class.getName(); + Class entityClass = getEntityClass(ms); + //修改返回值类型为实体类型 + setResultType(ms, entityClass); + StringBuilder sql = new StringBuilder(); + sql.append(SqlHelper.selectAllColumns(entityClass)); + sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); + sql.append("\n"); + sql.append("\n"); + String entityClassName = entityClass.getName(); + //通过实体类名获取运行时属性对应的字段 + String ognl = new StringBuilder("${@") + .append(propertyHelper) + .append("@getColumnByProperty(@java.lang.Class@forName(\"") + .append(entityClassName) + .append("\"), @tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))}").toString(); + sql.append(ognl + " = #{value}\n"); + sql.append("\n"); + // 逻辑删除的未删除查询条件 + sql.append(SqlHelper.whereLogicDelete(entityClass, false)); + sql.append(""); + return sql.toString(); + } + + /** + * 根据属性查询,查询条件使用等号 + * + * @param ms + * @return + */ + public String selectByProperty(MappedStatement ms) { + String propertyHelper = SelectPropertyProvider.class.getName(); + Class entityClass = getEntityClass(ms); + //修改返回值类型为实体类型 + setResultType(ms, entityClass); + StringBuilder sql = new StringBuilder(); + sql.append(SqlHelper.selectAllColumns(entityClass)); + sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); + sql.append("\n"); + sql.append("\n"); + String entityClassName = entityClass.getName(); + //通过实体类名获取运行时属性对应的字段 + String ognl = new StringBuilder("${@") + .append(propertyHelper) + .append("@getColumnByProperty(@java.lang.Class@forName(\"") + .append(entityClassName) + .append("\"), @tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))}").toString(); + sql.append(ognl + " = #{value}\n"); + sql.append("\n"); + // 逻辑删除的未删除查询条件 + sql.append(SqlHelper.whereLogicDelete(entityClass, false)); + sql.append(""); + return sql.toString(); + } + + /** + * 根据属性查询,查询条件使用 in + * + * @param ms + * @return + */ + public String selectInByProperty(MappedStatement ms) { + Class entityClass = getEntityClass(ms); + //修改返回值类型为实体类型 + setResultType(ms, entityClass); + StringBuilder sql = new StringBuilder(); + sql.append(SqlHelper.selectAllColumns(entityClass)); + sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); + sql.append("\n"); + String entityClassName = entityClass.getName(); + String propertyHelper = SelectPropertyProvider.class.getName(); + String sqlSegment = + "${@" + propertyHelper + "@getColumnByProperty(@java.lang.Class@forName(\"" + entityClassName + "\")," + + "@tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))} in" + + "\n" + + "#{obj}\n" + + "\n"; + sql.append(sqlSegment); + // 逻辑删除的未删除查询条件 + sql.append(SqlHelper.whereLogicDelete(entityClass, false)); + sql.append(""); + return sql.toString(); + } + + /** + * 根据属性查询,查询条件使用 between + * + * @param ms + * @return + */ + public String selectBetweenByProperty(MappedStatement ms) { + Class entityClass = getEntityClass(ms); + //修改返回值类型为实体类型 + setResultType(ms, entityClass); + StringBuilder sql = new StringBuilder(); + sql.append(SqlHelper.selectAllColumns(entityClass)); + sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); + sql.append("\n"); + String entityClassName = entityClass.getName(); + String propertyHelper = SelectPropertyProvider.class.getName(); + String sqlSegment = + "${@" + propertyHelper + "@getColumnByProperty(@java.lang.Class@forName(\"" + entityClassName + "\")," + + "@tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))} " + + "between #{begin} and #{end}"; + sql.append(sqlSegment); + // 逻辑删除的未删除查询条件 + sql.append(SqlHelper.whereLogicDelete(entityClass, false)); + sql.append(""); + return sql.toString(); + } + + /** + * 根据属性查询总数,查询条件使用等号 + * + * @param ms + * @return + */ + public String existsWithProperty(MappedStatement ms) { + String propertyHelper = SelectPropertyProvider.class.getName(); + Class entityClass = getEntityClass(ms); + + StringBuilder sql = new StringBuilder(); + sql.append(SqlHelper.selectCountExists(entityClass)); + sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); + sql.append("\n"); + sql.append("\n"); + String entityClassName = entityClass.getName(); + //通过实体类名获取运行时属性对应的字段 + String ognl = new StringBuilder("${@") + .append(propertyHelper) + .append("@getColumnByProperty(@java.lang.Class@forName(\"") + .append(entityClassName) + .append("\"), @tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))}").toString(); + sql.append(ognl + " = #{value}\n"); + sql.append("\n"); + // 逻辑删除的未删除查询条件 + sql.append(SqlHelper.whereLogicDelete(entityClass, false)); + sql.append(""); + return sql.toString(); + } + + /** + * 根据属性查询总数,查询条件使用等号 + * + * @param ms + * @return + */ + public String selectCountByProperty(MappedStatement ms) { + Class entityClass = getEntityClass(ms); + String propertyHelper = SelectPropertyProvider.class.getName(); + + StringBuilder sql = new StringBuilder(); + sql.append(SqlHelper.selectCount(entityClass)); + sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); + sql.append("\n"); + sql.append("\n"); + String entityClassName = entityClass.getName(); + //通过实体类名获取运行时属性对应的字段 + String ognl = new StringBuilder("${@") + .append(propertyHelper) + .append("@getColumnByProperty(@java.lang.Class@forName(\"") + .append(entityClassName) + .append("\"), @tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))}").toString(); + sql.append(ognl + " = #{value}\n"); + sql.append("\n"); + // 逻辑删除的未删除查询条件 + sql.append(SqlHelper.whereLogicDelete(entityClass, false)); + sql.append(""); + return sql.toString(); + } + + /** + * 根据实体Class和属性名获取对应的表字段名 + * @param entityClass 实体Class对象 + * @param property 属性名 + * @return + */ + public static String getColumnByProperty(Class entityClass, String property) { + EntityTable entityTable = EntityHelper.getEntityTable(entityClass); + EntityColumn entityColumn = entityTable.getPropertyMap().get(property); + return entityColumn.getColumn(); + } + + /** + * 判断是否需要拼接 where 条件 + * @param value + * @param notEmpty + * @return + */ + public static boolean existsWhereCondition(Object value, boolean notEmpty) { + boolean appendWhereCondition = true; + if (Objects.isNull(value)) { + log.warn("value is null! this will case no conditions after where keyword"); + } else { + if (String.class.equals(value.getClass()) && notEmpty && StringUtil.isEmpty(value.toString())) { + // 如果 value 是 String 类型,则根据是否允许为空串做进一步校验来决定是否拼接 where 条件 + appendWhereCondition = false; + } + } + return appendWhereCondition; + } +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java b/extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java new file mode 100644 index 000000000..05557600e --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java @@ -0,0 +1,52 @@ +package tk.mybatis.mapper.additional.select; + +import javax.persistence.Id; +import java.time.LocalDate; + +/** + * @author jingkaihui + * @date 2019/10/19 + */ +public class Book { + + @Id + private Integer id; + + private String name; + + private Integer price; + + private LocalDate published; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getPrice() { + return price; + } + + public void setPrice(Integer price) { + this.price = price; + } + + public LocalDate getPublished() { + return published; + } + + public void setPublished(LocalDate published) { + this.published = published; + } +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/BookMapper.java b/extra/src/test/java/tk/mybatis/mapper/additional/select/BookMapper.java new file mode 100644 index 000000000..92c4400ee --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/BookMapper.java @@ -0,0 +1,8 @@ +package tk.mybatis.mapper.additional.select; + +/** + * @author jingkaihui + * @date 2019/10/19 + */ +public interface BookMapper extends SelectByPropertyMapper { +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql new file mode 100644 index 000000000..64001f5b7 --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql @@ -0,0 +1,13 @@ +drop table book if exists; + +create table book ( + id integer NOT NULL PRIMARY KEY, + name varchar(32), + price integer, + published date +); + +INSERT INTO book VALUES (1, 'Java入门1', '50', '2015-11-11'); +INSERT INTO book VALUES (2, 'Java入门2', '50', '2015-11-11'); +INSERT INTO book VALUES (3, 'Java中级', '80', '2017-11-11'); +INSERT INTO book VALUES (4, 'Java高级', '100', '2019-11-11'); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapperTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapperTest.java new file mode 100644 index 000000000..5913107ee --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapperTest.java @@ -0,0 +1,111 @@ +package tk.mybatis.mapper.additional.select; + +import org.apache.ibatis.session.SqlSession; +import org.junit.Assert; +import org.junit.Test; +import tk.mybatis.mapper.additional.BaseTest; + +import java.io.IOException; +import java.io.Reader; +import java.net.URL; +import java.time.LocalDate; +import java.util.Arrays; +import java.util.List; + +public class SelectByPropertyMapperTest extends BaseTest { + + /** + * 获取 mybatis 配置 + * + * @return + */ + protected Reader getConfigFileAsReader() throws IOException { + URL url = getClass().getResource("mybatis-config.xml"); + return toReader(url); + } + + /** + * 获取初始化 sql + * + * @return + */ + protected Reader getSqlFileAsReader() throws IOException { + URL url = getClass().getResource("CreateDB.sql"); + return toReader(url); + } + + @Test + public void selectOneByPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + BookMapper mapper = sqlSession.getMapper(BookMapper.class); + Book book = mapper.selectOneByProperty(Book::getName, "Java入门1"); + Assert.assertNotNull(book); + Assert.assertEquals("Java入门1", book.getName()); + } finally { + sqlSession.close(); + } + } + + @Test + public void selectByPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + BookMapper mapper = sqlSession.getMapper(BookMapper.class); + List books = mapper.selectByProperty(Book::getPrice, 50); + Assert.assertEquals(2, books.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void selectInByPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + BookMapper mapper = sqlSession.getMapper(BookMapper.class); + List books = mapper.selectInByProperty(Book::getPrice, Arrays.asList(50, 80)); + Assert.assertEquals(3, books.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void selectBetweenByPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + BookMapper mapper = sqlSession.getMapper(BookMapper.class); + List books = mapper.selectBetweenByProperty(Book::getPublished, LocalDate.of(2015, 11, 11), + LocalDate.of(2019, 11, 11)); + Assert.assertEquals(4, books.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void selectCountByPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + BookMapper mapper = sqlSession.getMapper(BookMapper.class); + int count = mapper.selectCountByProperty(Book::getPrice, 50); + Assert.assertEquals(2, count); + } finally { + sqlSession.close(); + } + } + + @Test + public void existsWithPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + BookMapper mapper = sqlSession.getMapper(BookMapper.class); + boolean exist = mapper.existsWithProperty(Book::getPrice, 50); + Assert.assertTrue(exist); + } finally { + sqlSession.close(); + } + } + +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml new file mode 100644 index 000000000..099e6079d --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + From 93b9621565e2e0d9ae6fbb0f1488a4c975683670 Mon Sep 17 00:00:00 2001 From: Liuzh Date: Tue, 17 Mar 2020 09:13:22 +0800 Subject: [PATCH 011/109] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d9570db5a..13cf94ab3 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ 强烈建议初学者阅读本文,先从整体上了解 通用 Mapper,然后再通过下面的文档更深入的了解。 +## [**通用 Mapper 进阶实例:为什么好久都没更新了?**](https://blog.csdn.net/isea533/article/details/104776347) + +通过本文,希望读者能有收获,能根据自己的需要设计通用方法,不要只是为了偷懒将自己局限在已有的通用方法中。大而全的通用方法不一定适合自己,根据自己需要选择和设计的通用方法才更满足自己的需要。 + ## 项目文档 - [文档 - Gitee](https://gitee.com/free/Mapper/wikis/Home) @@ -65,4 +69,4 @@ - CSDN博客:http://blog.csdn.net/isea533/article/details/73555400 -- GitHub项目:https://github.com/mybatis-book/book \ No newline at end of file +- GitHub项目:https://github.com/mybatis-book/book From ba417dc33b3842814f13385cd7e83a731af55f86 Mon Sep 17 00:00:00 2001 From: abel533 Date: Mon, 27 Jul 2020 21:52:34 +0800 Subject: [PATCH 012/109] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9C=B0=E5=9D=80=20?= =?UTF-8?q?https://mybatis.io?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- base/pom.xml | 2 +- core/README.md | 4 ++-- core/pom.xml | 2 +- generator/README.md | 4 ++-- pom.xml | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 13cf94ab3..0a1e82251 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,13 @@ ## 作者信息 - MyBatis 工具网站:[http://mybatis.tk](http://www.mybatis.tk) + MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) 作者博客:http://blog.csdn.net/isea533 作者邮箱: abel533@gmail.com - 如需加群,请通过 http://mybatis.tk 首页按钮加群。 + 如需加群,请通过 https://mybatis.io 首页按钮加群。 推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper) diff --git a/base/pom.xml b/base/pom.xml index 381dac6e2..63e72933d 100644 --- a/base/pom.xml +++ b/base/pom.xml @@ -35,7 +35,7 @@ mapper-base Mybatis 通用 Mapper 基础方法实现 - http://www.mybatis.tk + https://mybatis.io diff --git a/core/README.md b/core/README.md index 60e27f7de..ffd9eba5f 100644 --- a/core/README.md +++ b/core/README.md @@ -147,12 +147,12 @@ http://repo1.maven.org/maven2/javax/persistence/persistence-api/1.0/ ##作者信息 -MyBatis 工具网站:[http://mybatis.tk](http://www.mybatis.tk) +MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) 作者博客:http://blog.csdn.net/isea533 作者邮箱: abel533@gmail.com -如需加群,请通过 http://mybatis.tk 首页按钮加群。 +如需加群,请通过 https://mybatis.io 首页按钮加群。 推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper) \ No newline at end of file diff --git a/core/pom.xml b/core/pom.xml index 9d4fdf6be..8dc6ea81c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -35,7 +35,7 @@ mapper-core Mybatis 通用 Mapper - http://www.mybatis.tk + https://mybatis.io diff --git a/generator/README.md b/generator/README.md index 15b2d16b3..a2a73f519 100644 --- a/generator/README.md +++ b/generator/README.md @@ -610,9 +610,9 @@ Blob列: > >支付宝 > ->支付宝 +>支付宝 > >微信 > ->微信 +>微信 diff --git a/pom.xml b/pom.xml index 9aeb3a47f..423169e80 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ mapper-parent Mybatis 通用 Mapper 聚合模块 - http://www.mybatis.tk + https://mybatis.io From b08258bc7c1c29cfcd83e6243749293f62cdb639 Mon Sep 17 00:00:00 2001 From: wanglei Date: Wed, 24 Jan 2018 11:04:38 +0800 Subject: [PATCH 013/109] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84getter=E6=96=B9=E6=B3=95=E6=B3=A8=E9=87=8A=E4=B8=AD@re?= =?UTF-8?q?turn=20=E5=88=97=E5=90=8D=E4=B8=BA@return=20=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/generator/MapperCommentGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java index 985618dfa..c29a754e3 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java @@ -242,7 +242,7 @@ public void addGetterComment(Method method, IntrospectedTable introspectedTable, } sb.setLength(0); sb.append(" * @return "); - sb.append(introspectedColumn.getActualColumnName()); + sb.append(introspectedColumn.getJavaProperty()); if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) { sb.append(" - "); sb.append(introspectedColumn.getRemarks()); From 570ef15427d99c2da83f053da4ae4e60c12f0de5 Mon Sep 17 00:00:00 2001 From: jingkaihui Date: Mon, 20 Jul 2020 15:31:23 +0800 Subject: [PATCH 014/109] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Example.Criteria?= =?UTF-8?q?=20=E6=9C=AA=E8=AE=BE=E7=BD=AE=20where=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=97=B6=EF=BC=8C=E5=B8=A6=E6=9C=89=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=E6=B3=A8=E8=A7=A3=E7=9A=84=E8=A1=A8?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=EF=BC=8Cfixed=20#722?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/tk/mybatis/mapper/mapperhelper/SqlHelper.java | 4 ++-- core/src/main/java/tk/mybatis/mapper/util/OGNL.java | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java index 45a3e1f51..2378e17c4 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java @@ -944,7 +944,6 @@ public static String exampleCheck(Class entityClass) { public static String exampleWhereClause() { return "" + "\n" + - " ${@tk.mybatis.mapper.util.OGNL@andNotLogicDelete(_parameter)}" + " \n" + " \n" + " \n" + @@ -973,6 +972,7 @@ public static String exampleWhereClause() { " \n" + " \n" + " \n" + + " ${@tk.mybatis.mapper.util.OGNL@andNotLogicDelete(_parameter)}" + "" + ""; } @@ -984,7 +984,6 @@ public static String exampleWhereClause() { */ public static String updateByExampleWhereClause() { return "\n" + - " ${@tk.mybatis.mapper.util.OGNL@andNotLogicDelete(example)}" + " \n" + " \n" + " \n" + @@ -1013,6 +1012,7 @@ public static String updateByExampleWhereClause() { " \n" + " \n" + " \n" + + " ${@tk.mybatis.mapper.util.OGNL@andNotLogicDelete(example)}" + ""; } diff --git a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java index 5884e209d..6100f98a8 100644 --- a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java +++ b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java @@ -243,13 +243,7 @@ public static String andNotLogicDelete(Object parameter) { EntityColumn column = entry.getValue(); if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) { // 未逻辑删除的条件 - result = column.getColumn() + " = " + SqlHelper.getLogicDeletedValue(column, false); - - // 如果Example中有条件,则拼接" and ", - // 如果是空的oredCriteria,则where中只有逻辑删除注解的未删除条件 - if (example.getOredCriteria() != null && example.getOredCriteria().size() != 0) { - result += " and "; - } + result = "and " + column.getColumn() + " = " + SqlHelper.getLogicDeletedValue(column, false); } } } From 3bf2e1a07b4d09dbdce7ff8de01cf5e33e8dab52 Mon Sep 17 00:00:00 2001 From: jingkaihui Date: Mon, 20 Jul 2020 17:25:14 +0800 Subject: [PATCH 015/109] =?UTF-8?q?=E6=89=A9=E5=B1=95=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=B1=9E=E6=80=A7=E5=8F=8A=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=80=BC=E5=88=A0=E9=99=A4=E7=9A=84=E9=80=9A=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../delete/DeleteByPropertyMapper.java | 49 ++++++ .../delete/DeletePropertyProvider.java | 159 ++++++++++++++++++ .../mapper/additional/delete/Course.java | 67 ++++++++ .../additional/delete/CourseMapper.java | 10 ++ .../mapper/additional/delete/CreateDB.sql | 14 ++ .../delete/DeleteByPropertyMapperTest.java | 95 +++++++++++ .../additional/delete/mybatis-config.xml | 51 ++++++ 7 files changed, 445 insertions(+) create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapper.java create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/delete/DeletePropertyProvider.java create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/delete/CourseMapper.java create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapperTest.java create mode 100644 extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapper.java new file mode 100644 index 000000000..6175ddf27 --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapper.java @@ -0,0 +1,49 @@ +package tk.mybatis.mapper.additional.delete; + +import org.apache.ibatis.annotations.DeleteProvider; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.SelectProvider; +import tk.mybatis.mapper.annotation.RegisterMapper; +import tk.mybatis.mapper.weekend.Fn; + +import java.util.List; + +/** + * @param 不能为空 + * @author jingkaihui + * @date 2020/3/30 + */ +@RegisterMapper +public interface DeleteByPropertyMapper { + + /** + * 根据实体中的属性删除,条件使用等号 + * + * @param fn 属性 + * @param value 属性值 + * @return + */ + @DeleteProvider(type = DeletePropertyProvider.class, method = "dynamicSQL") + int deleteByProperty(@Param("fn") Fn fn, @Param("value") Object value); + + /** + * 根据实体中的属性删除,条件使用 in + * + * @param fn 属性 + * @param value 属性值 + * @return + */ + @DeleteProvider(type = DeletePropertyProvider.class, method = "dynamicSQL") + int deleteInByProperty(@Param("fn") Fn fn, @Param("values") Object value); + + /** + * 根据属性及对应值进行删除,删除条件使用 between + * + * @param fn 属性 + * @param begin 开始值 + * @param end 开始值 + * @return + */ + @SelectProvider(type = DeletePropertyProvider.class, method = "dynamicSQL") + int deleteBetweenByProperty(@Param("fn") Fn fn, @Param("begin") Object begin, @Param("end") Object end); +} diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeletePropertyProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeletePropertyProvider.java new file mode 100644 index 000000000..949886860 --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeletePropertyProvider.java @@ -0,0 +1,159 @@ +package tk.mybatis.mapper.additional.delete; + +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.SqlCommandType; +import tk.mybatis.mapper.MapperException; +import tk.mybatis.mapper.additional.select.SelectPropertyProvider; +import tk.mybatis.mapper.entity.EntityColumn; +import tk.mybatis.mapper.entity.EntityTable; +import tk.mybatis.mapper.mapperhelper.EntityHelper; +import tk.mybatis.mapper.mapperhelper.MapperHelper; +import tk.mybatis.mapper.mapperhelper.MapperTemplate; +import tk.mybatis.mapper.mapperhelper.SqlHelper; +import tk.mybatis.mapper.util.MetaObjectUtil; + +/** + * @author jingkaihui + * @date 2020/3/30 + */ +public class DeletePropertyProvider extends MapperTemplate { + + public DeletePropertyProvider(Class mapperClass, MapperHelper mapperHelper) { + super(mapperClass, mapperHelper); + } + + /** + * 根据属性删除,条件使用等号 + * + * @param ms + * @return + */ + public String deleteByProperty(MappedStatement ms) { + String propertyHelper = DeletePropertyProvider.class.getName(); + Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + // 如果是逻辑删除,则修改为更新表,修改逻辑删除字段的值 + if (SqlHelper.hasLogicDeleteColumn(entityClass)) { + sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass))); + sql.append(""); + sql.append(SqlHelper.logicDeleteColumnEqualsValue(entityClass, true)); + sql.append(""); + MetaObjectUtil.forObject(ms).setValue("sqlCommandType", SqlCommandType.UPDATE); + } else { + sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); + } + sql.append("\n"); + sql.append("\n"); + String entityClassName = entityClass.getName(); + //通过实体类名获取运行时属性对应的字段 + String ognl = new StringBuilder("${@") + .append(propertyHelper) + .append("@getColumnByProperty(@java.lang.Class@forName(\"") + .append(entityClassName) + .append("\"), @tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))}").toString(); + sql.append(ognl + " = #{value}\n"); + sql.append("\n"); + sql.append(""); + return sql.toString(); + } + + /** + * 根据属性删除,条件使用等号 + * + * @param ms + * @return + */ + public String deleteInByProperty(MappedStatement ms) { + String propertyHelper = DeletePropertyProvider.class.getName(); + Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + // 如果是逻辑删除,则修改为更新表,修改逻辑删除字段的值 + if (SqlHelper.hasLogicDeleteColumn(entityClass)) { + sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass))); + sql.append(""); + sql.append(SqlHelper.logicDeleteColumnEqualsValue(entityClass, true)); + sql.append(""); + MetaObjectUtil.forObject(ms).setValue("sqlCommandType", SqlCommandType.UPDATE); + } else { + sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); + } + sql.append("\n"); + String entityClassName = entityClass.getName(); + String sqlSegment = + "${@" + propertyHelper + "@getColumnByProperty(@java.lang.Class@forName(\"" + entityClassName + "\")," + + "@tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))} in" + + "\n" + + "#{obj}\n" + + "\n"; + sql.append(sqlSegment); + // 逻辑删除的未删除查询条件 + sql.append(SqlHelper.whereLogicDelete(entityClass, false)); + sql.append(""); + return sql.toString(); + } + + /** + * 根据属性删除,删除条件使用 between + * + * @param ms + * @return + */ + public String deleteBetweenByProperty(MappedStatement ms) { + String propertyHelper = DeletePropertyProvider.class.getName(); + Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + // 如果是逻辑删除,则修改为更新表,修改逻辑删除字段的值 + if (SqlHelper.hasLogicDeleteColumn(entityClass)) { + sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass))); + sql.append(""); + sql.append(SqlHelper.logicDeleteColumnEqualsValue(entityClass, true)); + sql.append(""); + MetaObjectUtil.forObject(ms).setValue("sqlCommandType", SqlCommandType.UPDATE); + } else { + sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); + } + sql.append("\n"); + String entityClassName = entityClass.getName(); + String sqlSegment = + "${@" + propertyHelper + "@getColumnByProperty(@java.lang.Class@forName(\"" + entityClassName + "\")," + + "@tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))} " + + "between #{begin} and #{end}"; + sql.append(sqlSegment); + // 逻辑删除的未删除查询条件 + sql.append(SqlHelper.whereLogicDelete(entityClass, false)); + sql.append(""); + return sql.toString(); + } + + /** + * 根据实体Class和属性名获取对应的表字段名 + * @param entityClass 实体Class对象 + * @param property 属性名 + * @return + */ + public static String getColumnByProperty(Class entityClass, String property) { + EntityTable entityTable = EntityHelper.getEntityTable(entityClass); + EntityColumn entityColumn = entityTable.getPropertyMap().get(property); + return entityColumn.getColumn(); + } + + public static boolean isNull(Object value, boolean safeDelete) { + boolean isNull = false; + if (safeDelete) { + if (null == value) { + throw new MapperException("安全删除模式下,不允许执行不带查询条件的 delete 方法"); + } + } else { + if (null == value) { + isNull = true; + } + } + return isNull; + } +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java b/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java new file mode 100644 index 000000000..ce37ce38f --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java @@ -0,0 +1,67 @@ +package tk.mybatis.mapper.additional.delete; + +import tk.mybatis.mapper.annotation.LogicDelete; + +import javax.persistence.Column; +import javax.persistence.Id; +import java.time.LocalDate; + +/** + * @author jingkaihui + * @date 2019/10/19 + */ +public class Course { + + @Id + private Integer id; + + private String name; + + private Integer price; + + private LocalDate published; + + @LogicDelete + @Column(name = "is_deleted") + private Boolean isDeleted; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getPrice() { + return price; + } + + public void setPrice(Integer price) { + this.price = price; + } + + public LocalDate getPublished() { + return published; + } + + public void setPublished(LocalDate published) { + this.published = published; + } + + public Boolean getDeleted() { + return isDeleted; + } + + public void setDeleted(Boolean deleted) { + isDeleted = deleted; + } +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/CourseMapper.java b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CourseMapper.java new file mode 100644 index 000000000..51a0ae119 --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CourseMapper.java @@ -0,0 +1,10 @@ +package tk.mybatis.mapper.additional.delete; + +import tk.mybatis.mapper.common.base.BaseSelectMapper; + +/** + * @author jingkaihui + * @date 2019/10/19 + */ +public interface CourseMapper extends BaseSelectMapper, DeleteByPropertyMapper { +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql new file mode 100644 index 000000000..b6c2326e8 --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql @@ -0,0 +1,14 @@ +drop table course if exists; + +create table course ( + id integer NOT NULL PRIMARY KEY, + name varchar(32), + price integer, + published date, + is_deleted integer +); + +INSERT INTO course VALUES (1, 'Java入门1', '50', '2015-11-11', '0'); +INSERT INTO course VALUES (2, 'Java入门2', '50', '2015-11-11', '0'); +INSERT INTO course VALUES (3, 'Java中级', '80', '2017-11-11', '0'); +INSERT INTO course VALUES (4, 'Java高级', '100', '2019-11-11', '0'); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapperTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapperTest.java new file mode 100644 index 000000000..4adb80112 --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapperTest.java @@ -0,0 +1,95 @@ +package tk.mybatis.mapper.additional.delete; + +import org.apache.ibatis.session.SqlSession; +import org.junit.Assert; +import org.junit.Test; +import tk.mybatis.mapper.additional.BaseTest; + +import java.io.IOException; +import java.io.Reader; +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +public class DeleteByPropertyMapperTest extends BaseTest { + + /** + * 获取 mybatis 配置 + * + * @return + */ + protected Reader getConfigFileAsReader() throws IOException { + URL url = getClass().getResource("mybatis-config.xml"); + return toReader(url); + } + + /** + * 获取初始化 sql + * + * @return + */ + protected Reader getSqlFileAsReader() throws IOException { + URL url = getClass().getResource("CreateDB.sql"); + return toReader(url); + } + + @Test + public void deleteByPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + CourseMapper mapper = sqlSession.getMapper(CourseMapper.class); + + Course beforeDelete = mapper.selectByPrimaryKey(2); + Assert.assertNotNull(beforeDelete); + Assert.assertEquals("Java入门2", beforeDelete.getName()); + + int deletedCount = mapper.deleteByProperty(Course::getName, "Java入门2"); + Assert.assertEquals(1, deletedCount); + + Course afterDelete = mapper.selectByPrimaryKey(2); + Assert.assertNull(afterDelete); + } finally { + sqlSession.close(); + } + } + + @Test + public void deleteInByPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + CourseMapper mapper = sqlSession.getMapper(CourseMapper.class); + + List beforeDelete = mapper.selectAll(); + Assert.assertEquals(4, beforeDelete.size()); + + int deletedCount = mapper.deleteInByProperty(Course::getPrice, Arrays.asList(50, 80, 100)); + + Assert.assertEquals(4, deletedCount); + + List afterDelete = mapper.selectAll(); + Assert.assertEquals(0, afterDelete.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void deleteBetweenByPropertyTest() { + SqlSession sqlSession = getSqlSession(); + try { + CourseMapper mapper = sqlSession.getMapper(CourseMapper.class); + + List beforeDelete = mapper.selectAll(); + Assert.assertEquals(4, beforeDelete.size()); + + int deletedCount = mapper.deleteBetweenByProperty(Course::getPrice, 80, 100); + + Assert.assertEquals(2, deletedCount); + + List afterDelete = mapper.selectAll(); + Assert.assertEquals(2, afterDelete.size()); + } finally { + sqlSession.close(); + } + } +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml new file mode 100644 index 000000000..e7f4502a1 --- /dev/null +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + From cadcc1c6d288ba826840edd57673b07157e2efb9 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sat, 8 Aug 2020 11:39:58 +0800 Subject: [PATCH 016/109] english --- .../java/tk/mybatis/mapper/additional/delete/CreateDB.sql | 8 ++++---- .../additional/delete/DeleteByPropertyMapperTest.java | 4 ++-- .../java/tk/mybatis/mapper/additional/select/CreateDB.sql | 8 ++++---- .../additional/select/SelectByPropertyMapperTest.java | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql index b6c2326e8..54d5c95cb 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql @@ -8,7 +8,7 @@ create table course ( is_deleted integer ); -INSERT INTO course VALUES (1, 'Java入门1', '50', '2015-11-11', '0'); -INSERT INTO course VALUES (2, 'Java入门2', '50', '2015-11-11', '0'); -INSERT INTO course VALUES (3, 'Java中级', '80', '2017-11-11', '0'); -INSERT INTO course VALUES (4, 'Java高级', '100', '2019-11-11', '0'); +INSERT INTO course VALUES (1, 'JavaStarter1', '50', '2015-11-11', '0'); +INSERT INTO course VALUES (2, 'JavaStarter2', '50', '2015-11-11', '0'); +INSERT INTO course VALUES (3, 'Java3', '80', '2017-11-11', '0'); +INSERT INTO course VALUES (4, 'Java4', '100', '2019-11-11', '0'); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapperTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapperTest.java index 4adb80112..f7ebe1f26 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapperTest.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapperTest.java @@ -41,9 +41,9 @@ public void deleteByPropertyTest() { Course beforeDelete = mapper.selectByPrimaryKey(2); Assert.assertNotNull(beforeDelete); - Assert.assertEquals("Java入门2", beforeDelete.getName()); + Assert.assertEquals("JavaStarter2", beforeDelete.getName()); - int deletedCount = mapper.deleteByProperty(Course::getName, "Java入门2"); + int deletedCount = mapper.deleteByProperty(Course::getName, "JavaStarter2"); Assert.assertEquals(1, deletedCount); Course afterDelete = mapper.selectByPrimaryKey(2); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql index 64001f5b7..b7a9fc366 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql @@ -7,7 +7,7 @@ create table book ( published date ); -INSERT INTO book VALUES (1, 'Java入门1', '50', '2015-11-11'); -INSERT INTO book VALUES (2, 'Java入门2', '50', '2015-11-11'); -INSERT INTO book VALUES (3, 'Java中级', '80', '2017-11-11'); -INSERT INTO book VALUES (4, 'Java高级', '100', '2019-11-11'); +INSERT INTO book VALUES (1, 'JavaStarter1', '50', '2015-11-11'); +INSERT INTO book VALUES (2, 'JavaStarter2', '50', '2015-11-11'); +INSERT INTO book VALUES (3, 'Java3', '80', '2017-11-11'); +INSERT INTO book VALUES (4, 'Java4', '100', '2019-11-11'); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapperTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapperTest.java index 5913107ee..8ad3eb780 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapperTest.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapperTest.java @@ -39,9 +39,9 @@ public void selectOneByPropertyTest() { SqlSession sqlSession = getSqlSession(); try { BookMapper mapper = sqlSession.getMapper(BookMapper.class); - Book book = mapper.selectOneByProperty(Book::getName, "Java入门1"); + Book book = mapper.selectOneByProperty(Book::getName, "JavaStarter1"); Assert.assertNotNull(book); - Assert.assertEquals("Java入门1", book.getName()); + Assert.assertEquals("JavaStarter1", book.getName()); } finally { sqlSession.close(); } From 8c57af043c3038adfe6b314d6237b3341cfa614f Mon Sep 17 00:00:00 2001 From: glacier Date: Wed, 1 Apr 2020 18:29:08 +0800 Subject: [PATCH 017/109] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=8C=E8=AF=A5=E9=94=99=E8=AF=AF=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=AF=BC=E8=87=B4=20EntityHelper.entityTableMap=20?= =?UTF-8?q?=E8=A2=AB=E9=94=99=E8=AF=AF=E6=B8=85=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java index aa4104d2d..e2881a5b2 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java @@ -76,7 +76,7 @@ private void removeEntityHelperCache(Class entityHelper) { for (Object key : new ArrayList(cache.keySet())) { Class entityClass = (Class) key; //清理老的ClassLoader缓存的数据,避免测试环境溢出 - if (!entityClass.getClassLoader().equals(classLoader)) { + if (!(entityClass.getClassLoader().equals(classLoader) || entityClass.getClassLoader().equals(classLoader.getParent()))) { cache.remove(entityClass); } } From 4a5675d619d0b5b02bdfe586d0057c720569f824 Mon Sep 17 00:00:00 2001 From: kong-ly <34047423+DJ-KONG@users.noreply.github.com> Date: Tue, 17 Mar 2020 16:06:40 +0800 Subject: [PATCH 018/109] Update FieldHelper.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决实体类中子类无法覆盖了父类的属性,在子类属性上加@Transient,生成的sql仍然会将父类的属性生成到sql中的问题 #674 --- .../mapper/mapperhelper/FieldHelper.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java index 44dacdebc..7a4557d71 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java @@ -104,6 +104,21 @@ public static List getAll(Class entityClass) { } return all; } + + /** + * 判断是否已经包含同名的field + * @param fieldList + * @param filedName + * @return + */ + private static boolean containFiled(List fieldList, String filedName) { + for(EntityField field: fieldList) { + if(field.getName().equals(filedName)) { + return true; + } + } + return false; + } /** * Field接口 @@ -177,6 +192,10 @@ private List _getFields(Class entityClass, List fie Field field = fields[i]; //排除静态字段,解决bug#2 if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) { + //如果父类中包含与子类同名field,则跳过处理,允许子类进行覆盖 + if(FieldHelper.containFiled(fieldList,field.getName())) { + continue; + } if (level.intValue() != 0) { //将父类的字段放在前面 fieldList.add(index, new EntityField(field, null)); @@ -300,6 +319,10 @@ private void _getFields(Class entityClass, List fieldList, Map Date: Thu, 19 Mar 2020 00:07:07 +0800 Subject: [PATCH 019/109] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AF=B9null=E5=80=BC=E7=9A=84=E5=A4=84=E7=90=86=E7=AD=96?= =?UTF-8?q?=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/weekend/SqlCriteriaHelper.java | 549 ++++++++++++++++++ .../mapper/weekend/SqlCriteriaHelperTest.java | 87 +++ 2 files changed, 636 insertions(+) create mode 100644 weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java create mode 100644 weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java new file mode 100644 index 000000000..ce0e70673 --- /dev/null +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java @@ -0,0 +1,549 @@ +package tk.mybatis.mapper.weekend; + +import tk.mybatis.mapper.util.Sqls; +import tk.mybatis.mapper.weekend.reflection.Reflections; + +import java.util.Optional; + +/** + * sql 条件语句 + * @author Cheng.Wei + * @date 2019-04-15 10:26 + */ +public class SqlCriteriaHelper implements tk.mybatis.mapper.entity.SqlsCriteria { + private Sqls.Criteria criteria; + + private SqlCriteriaHelper() { + this.criteria = new Sqls.Criteria(); + } + + private SqlCriteriaHelper(Class clazz) { + this.criteria = new Sqls.Criteria(); + } + + public static SqlCriteriaHelper custom(Class clazz) { + return new SqlCriteriaHelper(clazz); + } + + /** + * AND column IS NULL + * @param fn + * @return + */ + public SqlCriteriaHelper andIsNull(Fn fn) { + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), "is null", "and")); + return this; + } + + + /** + * AND column IS NOT NULL + * @param fn + * @return + */ + public SqlCriteriaHelper andIsNotNull(Fn fn) { + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), "is not null", "and")); + return this; + } + + /** + * AND column = value + * 当value=null则不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andEqualTo(Fn fn, Object value) { + return this.andEqualTo(fn, value, false); + } + + /** + * AND column = value + * @param fn + * @param value + * @param required false 当value=null 则不参与查询 ; + * true 当value = null 则转 is null 查询: AND column is null + * @return + */ + public SqlCriteriaHelper andEqualTo(Fn fn, Object value, boolean required) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "=", "and")); + }else { + if(required){ + // null属性查询 转 is null + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), "is null", "and")); + } + } + return this; + } + + /** + * AND column != value + * 默认 value=null 则不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andNotEqualTo(Fn fn, Object value) { + return this.andNotEqualTo(fn, value, false); + } + + /** + * AND column != value + * @param fn + * @param value + * @param required false 当value=null 则不参与查询 ; + * true 当value = null 则转 is not null 查询 : AND column is not null + * + * @return + */ + public SqlCriteriaHelper andNotEqualTo(Fn fn, Object value, boolean required) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<>", "and")); + }else { + if(required){ + //转非空查询 + this.andIsNotNull(fn); + } + } + return this; + } + + /** + * AND column > value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andGreaterThan(Fn fn, Object value) { + if (Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, ">", "and")); + } + return this; + } + + /** + * AND column >= value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andGreaterThanOrEqualTo(Fn fn, Object value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, ">=", "and")); + } + return this; + } + + /** + * AND column < value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andLessThan(Fn fn, Object value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<", "and")); + } + return this; + } + + /** + * AND column <= value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andLessThanOrEqualTo(Fn fn, Object value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<=", "and")); + } + return this; + } + + /** + * AND column IN (#{item.value}) + * 当 values = null 则当前属性不参与查询 + * @param fn + * @param values + * @return + */ + public SqlCriteriaHelper andIn(Fn fn, Iterable values) { + if(Optional.ofNullable(values).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "in", "and")); + } + return this; + } + + /** + * AND column NOT IN (#{item.value}) + * 当 values = null 则当前属性不参与查询 + * @param fn + * @param values + * @return + */ + public SqlCriteriaHelper andNotIn(Fn fn, Iterable values) { + if(Optional.ofNullable(values).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "not in", "and")); + } + return this; + } + + /** + * AND column BETWEEN value1 AND value2 + * 当 value1 或 value2 为空 则当前属性不参与查询 + * @param fn + * @param value1 + * @param value2 + * @return + */ + public SqlCriteriaHelper andBetween(Fn fn, Object value1, Object value2) { + if(Optional.ofNullable(value1).isPresent()&& Optional.ofNullable(value2).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value1, value2, "between", "and")); + } + return this; + } + + /** + * AND column NOT BETWEEN value1 AND value2 + * 当 value1 或 value2 为空 则当前属性不参与查询 + * @param fn + * @param value1 + * @param value2 + * @return + */ + public SqlCriteriaHelper andNotBetween(Fn fn, Object value1, Object value2) { + if(Optional.ofNullable(value1).isPresent()&& Optional.ofNullable(value2).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value1, value2, "not between", "and")); + } + return this; + } + + /** + * AND column LIKE %value% + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andLike(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = "%"+value+"%"; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "and")); + } + return this; + } + + + /** + * AND column LIKE %value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andLikeLeft(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = "%"+value; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "and")); + } + return this; + } + + /** + * AND column LIKE value% + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andLikeRight(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = value+"%"; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "and")); + } + return this; + } + + /** + * AND column NOT LIKE %value% + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andNotLike(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = "%"+value+"%"; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "and")); + } + return this; + } + + /** + * AND column NOT LIKE %value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andNotLikeLeft(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = "%"+value+"%"; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "and")); + } + return this; + } + + /** + * AND column NOT LIKE value% + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper andNotLikeRight(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = value+"%"; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "and")); + } + return this; + } + + /** + * OR column IS NULL + * 当 value = null 则当前属性不参与查询 + * @param fn + * @return + */ + public SqlCriteriaHelper orIsNull(Fn fn) { + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), "is null", "or")); + return this; + } + + /** + * OR column IS NOT NULL + * 当 value = null 则当前属性不参与查询 + * @param fn + * @return + */ + public SqlCriteriaHelper orIsNotNull(Fn fn) { + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), "is not null", "or")); + return this; + } + + + /** + * OR column = value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orEqualTo(Fn fn, Object value) { + return this.orEqualTo(fn, value, false); + } + + /** + * OR column = value + * 当request = true 且 value = null时 转 #{@link #orIsNull(Fn)} + * @param fn + * @param value + * @param required + * @return + */ + public SqlCriteriaHelper orEqualTo(Fn fn, Object value, boolean required) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "=", "or")); + }else { + if(required){ + //转 or null + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), "is null", "or")); + } + } + return this; + } + + /** + * OR column <> value + * 当value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orNotEqualTo(Fn fn, Object value) { + return this.orNotEqualTo(fn, value, false); + } + + /** + * OR column <> value + * 当request = true 且 value = null时 转 #{@link #orIsNotNull(Fn)} + * @param fn + * @param value + * @param required + * @return + */ + public SqlCriteriaHelper orNotEqualTo(Fn fn, Object value, boolean required) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<>", "or")); + }else { + if(required){ + // 转 or is not null + this.orIsNotNull(fn); + } + } + return this; + } + + /** + * OR column > value + * 当value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orGreaterThan(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, ">", "or")); + } + return this; + } + + /** + * OR column >= value + * 当value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orGreaterThanOrEqualTo(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, ">=", "or")); + } + return this; + } + + /** + * OR column < value + * 当value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orLessThan(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<", "or")); + } + return this; + } + + /** + * OR column <= value + * 当value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orLessThanOrEqualTo(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<=", "or")); + } + return this; + } + + /** + * OR column IN (#{item.value}) + * 当value = null 则当前属性不参与查询 + * @param fn + * @param values + * @return + */ + public SqlCriteriaHelper orIn(Fn fn, Iterable values) { + if(Optional.ofNullable(values).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "in", "or")); + } + return this; + } + + /** + * OR column NOT IN (#{item.value}) + * 当value = null 则当前属性不参与查询 + * @param fn + * @param values + * @return + */ + public SqlCriteriaHelper orNotIn(Fn fn, Iterable values) { + if(Optional.ofNullable(values).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "not in", "or")); + } + return this; + } + + /** + * OR column BETWEEN value1 AND value2 + * 当 value1 或 value2 为空 则当前属性不参与查询 + * @param fn + * @param value1 + * @param value2 + * @return + */ + public SqlCriteriaHelper orBetween(Fn fn, Object value1, Object value2) { + if(Optional.ofNullable(value1).isPresent()&& Optional.ofNullable(value2).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value1, value2, "between", "or")); + } + return this; + } + + /** + * OR column NOT BETWEEN value1 AND value2 + * 当 value1 或 value2 为空 则当前属性不参与查询 + * @param fn + * @param value1 + * @param value2 + * @return + */ + public SqlCriteriaHelper orNotBetween(Fn fn, Object value1, Object value2) { + if(Optional.ofNullable(value1).isPresent()&& Optional.ofNullable(value2).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value1, value2, "not between", "or")); + } + return this; + } + + + /** + * OR column LIKE value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orLike(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "or")); + } + return this; + } + + /** + * OR column NOT LIKE value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orNotLike(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "or")); + } + return this; + } + + @Override + public Sqls.Criteria getCriteria() { + return criteria; + } +} diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java new file mode 100644 index 000000000..14b5c89fb --- /dev/null +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java @@ -0,0 +1,87 @@ +package tk.mybatis.mapper.weekend; + +import org.apache.ibatis.session.SqlSession; +import org.junit.Assert; +import org.junit.Test; +import tk.mybatis.mapper.entity.Example; +import tk.mybatis.mapper.weekend.entity.Country; +import tk.mybatis.mapper.weekend.mapper.CountryMapper; + +import java.util.List; + +/** + * @author Cheng.Wei + */ +public class SqlCriteriaHelperTest { + /** + * 忽略null值问题 + */ + @Test + public void ignore() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); + + List selectBySqlCriteriaHelper= mapper.selectByExample(new Example.Builder(Country.class) + .where(SqlCriteriaHelper.custom(Country.class) + .andEqualTo(Country::getCountryname, null) + .andLike(Country::getCountryname, "China")).build()); + + List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) + .where(WeekendSqls.custom() + .andEqualTo(Country::getCountryname, null) + .andLike(Country::getCountrycode, "China")).build()); + } finally { + sqlSession.close(); + } + } + + + /** + * 不忽略null属性 + * 当属性为null 且不忽略 则转换查询 equal null 转 is null + */ + @Test + public void required() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); + + List selectBySqlCriteriaHelper= mapper.selectByExample(new Example.Builder(Country.class) + .where(SqlCriteriaHelper.custom(Country.class) + // required = true 则继续查询 + .andEqualTo(Country::getCountryname, null, true)).build()); + + List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) + .where(WeekendSqls.custom() + .andEqualTo(Country::getCountryname, null)).build()); + } finally { + sqlSession.close(); + } + } + + /** + * like查询 自动拼接 % + */ + @Test + public void like() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); + + List selectBySqlCriteriaHelper= mapper.selectByExample(new Example.Builder(Country.class) + .where(SqlCriteriaHelper.custom(Country.class) + .andLike(Country::getCountryname, "Chin") + .orLike(Country::getCountryname, "A")).build()); + + List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) + .where(WeekendSqls.custom() + .andLike(Country::getCountryname, "Chin") + .orLike(Country::getCountryname, "A")).build()); + //判断两个结果数组内容是否相同 + Assert.assertArrayEquals(selectBySqlCriteriaHelper.toArray(), selectByWeekendSqls.toArray()); + } finally { + sqlSession.close(); + } + } +} From 1523d57fa17ea3ac11759033d94e198c9218bc21 Mon Sep 17 00:00:00 2001 From: "Cheng.Wei" Date: Thu, 19 Mar 2020 00:24:45 +0800 Subject: [PATCH 020/109] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=AF=B9null?= =?UTF-8?q?=E7=9A=84=E6=9F=A5=E8=AF=A2=20=E6=94=B9=E8=BF=9B=E5=AF=B9?= =?UTF-8?q?=E7=A9=BA=E9=9B=86=E5=90=88=E7=9A=84=E6=9F=A5=E8=AF=A2=20?= =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=AF=B9like=E7=9A=84=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/weekend/SqlCriteriaHelper.java | 84 +++++++++++++++++-- .../mapper/weekend/SqlCriteriaHelperTest.java | 26 ++++++ 2 files changed, 101 insertions(+), 9 deletions(-) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java index ce0e70673..9416f6251 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java @@ -17,12 +17,8 @@ private SqlCriteriaHelper() { this.criteria = new Sqls.Criteria(); } - private SqlCriteriaHelper(Class clazz) { - this.criteria = new Sqls.Criteria(); - } - public static SqlCriteriaHelper custom(Class clazz) { - return new SqlCriteriaHelper(clazz); + return new SqlCriteriaHelper(); } /** @@ -173,7 +169,7 @@ public SqlCriteriaHelper andLessThanOrEqualTo(Fn fn, Object value) * @return */ public SqlCriteriaHelper andIn(Fn fn, Iterable values) { - if(Optional.ofNullable(values).isPresent()){ + if(Optional.ofNullable(values).isPresent() && values.iterator().hasNext()){ this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "in", "and")); } return this; @@ -187,7 +183,7 @@ public SqlCriteriaHelper andIn(Fn fn, Iterable values) { * @return */ public SqlCriteriaHelper andNotIn(Fn fn, Iterable values) { - if(Optional.ofNullable(values).isPresent()){ + if(Optional.ofNullable(values).isPresent() && values.iterator().hasNext()){ this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "not in", "and")); } return this; @@ -463,7 +459,7 @@ public SqlCriteriaHelper orLessThanOrEqualTo(Fn fn, String value) * @return */ public SqlCriteriaHelper orIn(Fn fn, Iterable values) { - if(Optional.ofNullable(values).isPresent()){ + if(Optional.ofNullable(values).isPresent() && values.iterator().hasNext()){ this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "in", "or")); } return this; @@ -477,7 +473,7 @@ public SqlCriteriaHelper orIn(Fn fn, Iterable values) { * @return */ public SqlCriteriaHelper orNotIn(Fn fn, Iterable values) { - if(Optional.ofNullable(values).isPresent()){ + if(Optional.ofNullable(values).isPresent() && values.iterator().hasNext()){ this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "not in", "or")); } return this; @@ -523,11 +519,47 @@ public SqlCriteriaHelper orNotBetween(Fn fn, Object value1, Object */ public SqlCriteriaHelper orLike(Fn fn, String value) { if(Optional.ofNullable(value).isPresent()){ + value = "%"+value+"%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "or")); } return this; } + + /** + * OR column LIKE %value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orLikeLeft(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = "%"+value; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "or")); + } + return this; + } + + + + + /** + * OR column LIKE value% + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orLikeRight(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = value+"%"; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "or")); + } + return this; + } + + /** * OR column NOT LIKE value * 当 value = null 则当前属性不参与查询 @@ -537,11 +569,45 @@ public SqlCriteriaHelper orLike(Fn fn, String value) { */ public SqlCriteriaHelper orNotLike(Fn fn, String value) { if(Optional.ofNullable(value).isPresent()){ + value = "%"+value+"%"; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "or")); + } + return this; + } + + + + /** + * OR column NOT LIKE %value + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orNotLikeLeft(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = "%"+value+"%"; + this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "or")); + } + return this; + } + + /** + * OR column NOT LIKE value% + * 当 value = null 则当前属性不参与查询 + * @param fn + * @param value + * @return + */ + public SqlCriteriaHelper orNotLikeRight(Fn fn, String value) { + if(Optional.ofNullable(value).isPresent()){ + value = value+"%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "or")); } return this; } + @Override public Sqls.Criteria getCriteria() { return criteria; diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java index 14b5c89fb..2af6308b8 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java @@ -7,6 +7,7 @@ import tk.mybatis.mapper.weekend.entity.Country; import tk.mybatis.mapper.weekend.mapper.CountryMapper; +import java.util.ArrayList; import java.util.List; /** @@ -84,4 +85,29 @@ public void like() { sqlSession.close(); } } + + /** + * in查询 空集合问题 + */ + @Test + public void list() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); + + List selectBySqlCriteriaHelper= mapper.selectByExample(new Example.Builder(Country.class) + .where(SqlCriteriaHelper.custom(Country.class) + .andIn(Country::getCountryname, new ArrayList()) + .orLike(Country::getCountryname, "A")).build()); + + List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) + .where(WeekendSqls.custom() + .andIn(Country::getCountryname, new ArrayList()) + .orLike(Country::getCountryname, "A")).build()); + //判断两个结果数组内容是否相同 + Assert.assertArrayEquals(selectBySqlCriteriaHelper.toArray(), selectByWeekendSqls.toArray()); + } finally { + sqlSession.close(); + } + } } From 3c0b3307011fad53f811e08d05147d94fc6c0d67 Mon Sep 17 00:00:00 2001 From: "Cheng.Wei" Date: Thu, 19 Mar 2020 00:33:46 +0800 Subject: [PATCH 021/109] Update SqlCriteriaHelper.java --- .../main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java index 9416f6251..ef2fb5604 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java @@ -586,7 +586,7 @@ public SqlCriteriaHelper orNotLike(Fn fn, String value) { */ public SqlCriteriaHelper orNotLikeLeft(Fn fn, String value) { if(Optional.ofNullable(value).isPresent()){ - value = "%"+value+"%"; + value = "%"+value; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "or")); } return this; From 8c816794ef283ce6d4f573267d0137976bedd79b Mon Sep 17 00:00:00 2001 From: tingwen <623643629@qq.com> Date: Sat, 26 Dec 2020 18:29:18 +0800 Subject: [PATCH 022/109] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Lombok=20=E7=9A=84@Su?= =?UTF-8?q?perBuilder=E3=80=81@NoArgsConstructor=E3=80=81@AllArgsConstruct?= =?UTF-8?q?or=20=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/generator/MapperPlugin.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index 4ca3dfdfe..734c791c3 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -39,6 +39,7 @@ * @author liuzh */ public class MapperPlugin extends FalseMethodPlugin { + private Set mappers = new HashSet(); private boolean caseSensitive = false; private boolean useMapperCommentGenerator = true; @@ -63,6 +64,11 @@ public class MapperPlugin extends FalseMethodPlugin { private boolean needsToString = false; //是否需要生成Accessors(chain = true)注解 private boolean needsAccessors = false; + private boolean needsBuilder = false; + private boolean needsSuperBuilder = false; + private boolean needsNoArgsConstructor = false; + private boolean needsAllArgsConstructor = false; + //是否需要生成EqualsAndHashCode注解 private boolean needsEqualsAndHashCode = false; //是否需要生成EqualsAndHashCode注解,并且“callSuper = true” @@ -154,6 +160,22 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i topLevelClass.addImportedType("lombok.experimental.Accessors"); topLevelClass.addAnnotation("@Accessors(chain = true)"); } + if (this.needsSuperBuilder) { + topLevelClass.addImportedType("lombok.experimental.SuperBuilder"); + topLevelClass.addAnnotation("@SuperBuilder"); + } + if (this.needsBuilder) { + topLevelClass.addImportedType("lombok.Builder"); + topLevelClass.addAnnotation("@Builder"); + } + if (this.needsNoArgsConstructor) { + topLevelClass.addImportedType("lombok.NoArgsConstructor"); + topLevelClass.addAnnotation("@NoArgsConstructor"); + } + if (this.needsAllArgsConstructor) { + topLevelClass.addImportedType("lombok.AllArgsConstructor"); + topLevelClass.addAnnotation("@AllArgsConstructor"); + } // lombok扩展结束 // region swagger扩展 if (this.needsSwagger) { @@ -403,6 +425,10 @@ public void setProperties(Properties properties) { String lombokEqualsAndHashCodeCallSuper = getProperty("lombokEqualsAndHashCodeCallSuper", "false"); this.needsEqualsAndHashCodeAndCallSuper = this.needsEqualsAndHashCode && "TRUE".equalsIgnoreCase(lombokEqualsAndHashCodeCallSuper); this.needsAccessors = lombok.contains("Accessors"); + this.needsSuperBuilder = lombok.contains("SuperBuilder"); + this.needsBuilder = !this.needsSuperBuilder && lombok.contains("Builder"); + this.needsNoArgsConstructor = lombok.contains("NoArgsConstructor"); + this.needsAllArgsConstructor = lombok.contains("AllArgsConstructor"); } //swagger扩展 String swagger = getProperty("swagger", "false"); From 84e33f7c9e11ae4b165637a08706d7ed766b89eb Mon Sep 17 00:00:00 2001 From: Liuzh Date: Fri, 5 Mar 2021 11:27:26 +0800 Subject: [PATCH 023/109] Create FUNDING.yml --- .github/FUNDING.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..330ffab34 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: ['https://mybatis.io/donates.html'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] From 4cb55c80b9f91bf73db61c718ca9eaac948ad59c Mon Sep 17 00:00:00 2001 From: 01398017 Date: Tue, 11 May 2021 17:11:36 +0800 Subject: [PATCH 024/109] =?UTF-8?q?issues=EF=BC=9AI3HP1W=20orderByDesc?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=98=AF=E5=80=92=E5=BA=8F=EF=BC=8C=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=8F=82=E4=B8=8Eorderby=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E9=83=BD=E5=80=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/tk/mybatis/mapper/entity/Example.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/entity/Example.java b/core/src/main/java/tk/mybatis/mapper/entity/Example.java index 1cc7c4e53..1e08e0cd8 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/Example.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/Example.java @@ -972,10 +972,10 @@ private void contactOrderByClause(String order, String... properties) { for (String property : properties) { String column; if ((column = propertyforOderBy(property)) != null) { - columns.append(",").append(column); + columns.append(",").append(column).append(order); } } - columns.append(order); + ; if (columns.length() > 0) { orderByClause.append(columns); } From 1aa5eff621642f63b4363e4b916c0064b340db78 Mon Sep 17 00:00:00 2001 From: taiyi Date: Mon, 29 Nov 2021 19:39:15 +0800 Subject: [PATCH 025/109] =?UTF-8?q?WeekendSqls=20or=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=8F=82=E6=95=B0=20String->Object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/tk/mybatis/mapper/weekend/WeekendSqls.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java index 99f7c270e..7ecbe4c5d 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java @@ -193,7 +193,7 @@ public WeekendSqls orEqualTo(String property, Object value) { return this; } - public WeekendSqls orEqualTo(Fn fn, String value) { + public WeekendSqls orEqualTo(Fn fn, Object value) { return this.orEqualTo(Reflections.fnToFieldName(fn), value); } @@ -202,7 +202,7 @@ public WeekendSqls orNotEqualTo(String property, Object value) { return this; } - public WeekendSqls orNotEqualTo(Fn fn, String value) { + public WeekendSqls orNotEqualTo(Fn fn, Object value) { return this.orNotEqualTo(Reflections.fnToFieldName(fn), value); } @@ -211,7 +211,7 @@ public WeekendSqls orGreaterThan(String property, Object value) { return this; } - public WeekendSqls orGreaterThan(Fn fn, String value) { + public WeekendSqls orGreaterThan(Fn fn, Object value) { return this.orGreaterThan(Reflections.fnToFieldName(fn), value); } @@ -220,7 +220,7 @@ public WeekendSqls orGreaterThanOrEqualTo(String property, Object value) { return this; } - public WeekendSqls orGreaterThanOrEqualTo(Fn fn, String value) { + public WeekendSqls orGreaterThanOrEqualTo(Fn fn, Object value) { return this.orGreaterThanOrEqualTo(Reflections.fnToFieldName(fn), value); } @@ -229,7 +229,7 @@ public WeekendSqls orLessThan(String property, Object value) { return this; } - public WeekendSqls orLessThan(Fn fn, String value) { + public WeekendSqls orLessThan(Fn fn, Object value) { return this.orLessThan(Reflections.fnToFieldName(fn), value); } @@ -238,7 +238,7 @@ public WeekendSqls orLessThanOrEqualTo(String property, Object value) { return this; } - public WeekendSqls orLessThanOrEqualTo(Fn fn, String value) { + public WeekendSqls orLessThanOrEqualTo(Fn fn, Object value) { return this.orLessThanOrEqualTo(Reflections.fnToFieldName(fn), value); } From 480f2200e4bc07d69b26a24e732c704d073bfdee Mon Sep 17 00:00:00 2001 From: abel533 Date: Sat, 26 Feb 2022 23:32:16 +0800 Subject: [PATCH 026/109] =?UTF-8?q?=E5=AE=8C=E5=96=84SqlCriteriaHelper?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/weekend/SqlCriteriaHelperTest.java | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java index 2af6308b8..46f627afb 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java @@ -23,15 +23,18 @@ public void ignore() { try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); - List selectBySqlCriteriaHelper= mapper.selectByExample(new Example.Builder(Country.class) - .where(SqlCriteriaHelper.custom(Country.class) - .andEqualTo(Country::getCountryname, null) - .andLike(Country::getCountryname, "China")).build()); - + List selectBySqlCriteriaHelper = mapper.selectByExample(new Example.Builder(Country.class) + .where(SqlCriteriaHelper.custom(Country.class) + .andEqualTo(Country::getCountryname, null) + .andLike(Country::getCountryname, "China")).build()); + Assert.assertNotNull(selectBySqlCriteriaHelper); + Assert.assertEquals(1, selectBySqlCriteriaHelper.size()); + /* 不支持忽略 null List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) .where(WeekendSqls.custom() .andEqualTo(Country::getCountryname, null) .andLike(Country::getCountrycode, "China")).build()); + */ } finally { sqlSession.close(); } @@ -48,14 +51,14 @@ public void required() { try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); - List selectBySqlCriteriaHelper= mapper.selectByExample(new Example.Builder(Country.class) - .where(SqlCriteriaHelper.custom(Country.class) - // required = true 则继续查询 - .andEqualTo(Country::getCountryname, null, true)).build()); - - List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) + List selectBySqlCriteriaHelper = mapper.selectByExample(new Example.Builder(Country.class) + .where(SqlCriteriaHelper.custom(Country.class) + // required = true 则继续查询 + .andEqualTo(Country::getCountryname, null, true)).build()); + Assert.assertEquals(0, selectBySqlCriteriaHelper.size()); + /*List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) .where(WeekendSqls.custom() - .andEqualTo(Country::getCountryname, null)).build()); + .andEqualTo(Country::getCountryname, null)).build());*/ } finally { sqlSession.close(); } @@ -70,17 +73,18 @@ public void like() { try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); - List selectBySqlCriteriaHelper= mapper.selectByExample(new Example.Builder(Country.class) - .where(SqlCriteriaHelper.custom(Country.class) - .andLike(Country::getCountryname, "Chin") - .orLike(Country::getCountryname, "A")).build()); - + List selectBySqlCriteriaHelper = mapper.selectByExample(new Example.Builder(Country.class) + .where(SqlCriteriaHelper.custom(Country.class) + .andLike(Country::getCountryname, "Chin") + .orLike(Country::getCountryname, "A")).build()); + Assert.assertEquals(18, selectBySqlCriteriaHelper.size()); + /* 不支持自动带 % List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) .where(WeekendSqls.custom() .andLike(Country::getCountryname, "Chin") .orLike(Country::getCountryname, "A")).build()); //判断两个结果数组内容是否相同 - Assert.assertArrayEquals(selectBySqlCriteriaHelper.toArray(), selectByWeekendSqls.toArray()); + Assert.assertArrayEquals(selectBySqlCriteriaHelper.toArray(), selectByWeekendSqls.toArray());*/ } finally { sqlSession.close(); } @@ -95,17 +99,21 @@ public void list() { try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); - List selectBySqlCriteriaHelper= mapper.selectByExample(new Example.Builder(Country.class) - .where(SqlCriteriaHelper.custom(Country.class) - .andIn(Country::getCountryname, new ArrayList()) - .orLike(Country::getCountryname, "A")).build()); - + List selectBySqlCriteriaHelper = mapper.selectByExample(new Example.Builder(Country.class) + .where(SqlCriteriaHelper.custom(Country.class) + .andIn(Country::getCountryname, new ArrayList()) + .orLike(Country::getCountryname, "A")).build()); + Assert.assertNotNull(selectBySqlCriteriaHelper); + Assert.assertEquals(17, selectBySqlCriteriaHelper.size()); + //WeekendSqls 不支持空集合 + /* List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) .where(WeekendSqls.custom() .andIn(Country::getCountryname, new ArrayList()) .orLike(Country::getCountryname, "A")).build()); + */ //判断两个结果数组内容是否相同 - Assert.assertArrayEquals(selectBySqlCriteriaHelper.toArray(), selectByWeekendSqls.toArray()); + //Assert.assertArrayEquals(selectBySqlCriteriaHelper.toArray(), selectByWeekendSqls.toArray()); } finally { sqlSession.close(); } From c9b19a71de42c7502191a1ff20260c6ac6e6d78b Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 27 Feb 2022 00:41:19 +0800 Subject: [PATCH 027/109] 4.2.0 --- README.md | 49 +++++++++++++++++++ all/dependencies/pom.xml | 2 +- all/mapper/pom.xml | 2 +- all/pom.xml | 10 ++-- base/pom.xml | 2 +- core/pom.xml | 2 +- extra/pom.xml | 4 +- generator/pom.xml | 4 +- pom.xml | 2 +- .../mapper-spring-boot-autoconfigure/pom.xml | 2 +- .../pom.xml | 2 +- .../mapper-spring-boot-sample-xml/pom.xml | 2 +- .../mapper-spring-boot-samples/pom.xml | 2 +- .../mapper-spring-boot-starter/pom.xml | 2 +- spring-boot-starter/pom.xml | 16 +++--- spring/pom.xml | 2 +- weekend/pom.xml | 4 +- 17 files changed, 79 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 0a1e82251..6541a00d6 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,55 @@ **通用 Mapper 支持 Mybatis-3.2.4 及以上版本。** +## 4.2.0 - 2022-2-26 发布 + +本次更新最大改动就是统一了所有模块的版本,所有版本都升级为 4.2.0,在之前本项目一共有3个版本号,本次升级前后的版本如下: + +- mapper, mapper-all, mapper-all-dependencies 从 4.1.5 升级为 4.2.0 +- mapper-core, mapper-base, mapper-extra, mapper-generator, mapper-spring, mapper-weekend 从 1.1.5 升级为 4.2.0 +- mapper-spring-boot-starter 相关模块从 2.1.5 升级为 4.2.0 + +本次更新是 2019年1月28日发布 4.1.5 之后的首次发布,此次更新的内容基本上都来自所有热心开发人员的PR,大部分PR都是功能增强或新功能。 + +- `WeekendSqls` or部分方法参数 String->Object taiyi* 2021/11/29 19:39 1aa5eff6 +- 改进对null的查询 改进对空集合的查询 改进对like的查询 Cheng.Wei* 2020/3/19 0:24 1523d57f +- 改进查询对null值的处理策略 Cheng.Wei* 2020/3/19 0:07 afb6ffc8 +- Update FieldHelper.java kong-ly* 2020/3/17 16:06 4a5675d6 +- 修复一个错误,该错误可能导致 `EntityHelper.entityTableMap` 被错误清空 glacier* 2020/4/1 18:29 8c57af04 +- 扩展一些根据属性及条件值删除的通用方法 jingkaihui* 2020/7/20 17:25 3bf2e1a0 +- 修复 `Example.Criteria` 未设置 `where` 条件查询时,带有逻辑删除注解的表报错问题,fixed #722 jingkaihui* 2020/7/20 15:31 570ef154 +- 修改生成的getter方法注释中@return 列名为@return 属性名 wanglei* 2018/1/24 11:04 b08258bc +- 更新地址 https://mybatis.io abel533 2020/7/27 21:52 ba417dc3 +- 扩展一些根据属性及条件值查询的通用方法 jingkaihui* 2019/10/19 22:14 bd101038 +- 添加日志输出异常和警告信息,fixed #IXNLU isea533 2019/6/18 22:03 1764748e +- 合并 pr #17 isea533 2019/5/30 21:53 8d7819e3 +- [新增] `Weekend`对象增加`excludeProperties、selectProperties、orderBy、withCountProperty` 支持lambda表达式写属性名 + 使用withXXXXX的命名方式链式设置属性 wugh 2019/5/30 14:41 3e25bb9b +- [bug修复] 修复`generateDefaultInstanceMethod`参数,生成的实体类的`defaultInstance`静态方式. 1.存在默认值为''::character varying问题 2.支持基本类型 + wugh 2019/5/30 13:58 cf3e40aa +- [新增] 生成实体类的时候,使用表注释创建类的注释 wugh 2019/5/30 11:28 b4acbf48 +- 增加`lombokEqualsAndHashCodeCallSuper`配置,当使用lombok扩展的`EqualsAndHashCode`注解时,可通过此配置(true)为此注解添加`“callSuper = true”` + ,这对于有继承父类的实体类,如增加支持动态表名时,有用。 calvinit 2019/2/14 13:52 ae901608 + +## 还会有 MyBatis 通用 Mapper5 吗? + +通用 Mapper 每次大的版本,基本上都是底层上的大变化,在使用通用 Mapper 的过程中,有很多人遇到过配置的问题,因为底层实现的方式,所以无法避免配置,而且随着功能的增加,配置也增加了不少。 + +为了从根本上简化通用方法的实现,从2018年就开始思考如何让实现和MyBatis的兼容性更好,让实现变的更简单,为了从 MyBatis 根本解决问题,给官方提过好几个 PR,在 2019年3月份给 MyBatis 提交的 +[pr#1391](https://github.com/mybatis/mybatis-3/pull/1391) 合并后(对应 3.5.1 版本,最低要求版本),终于能以更简单的方式来实现通用 Mapper 了。 + +由于此次变动太大,因此不打算对 **通用Mapper4** 进行任何改动,从头实现了一个新的项目,名字仍然没有新意的使用了 `mybatis-mapper`,这个项目也发布很久了,由于工作太忙,没精力像以前那样频繁更新, 所以一直没推广新版 +mybatis-mapper,如果你动手能力强,喜欢看源码,你也可以试试这个项目: + +- [GitHub](https://github.com/mybatis-mapper/mapper) +- [Gitee](https://gitee.com/mybatis-mapper/mapper) +- [文档: https://mapper.mybatis.io](https://mapper.mybatis.io/) +- [开发过程](https://mapper.mybatis.io/releases/1.0.0.html) +- [快速上手](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) + +另外,通用 Mapper 中的大量 PR 都是增加的新方法和代码生成器相关的注解,这些和核心无关,因此 mybaits-mapper 会提供独立的项目接收所有新增的通用方法, 和代码生成器相关的 lombok +注解完全不需要了,使用新版本中提供的代码生成器可以更方便的进行定制。 + ## [**快速入门 - MyBatis 为什么需要通用 Mapper ?**](https://blog.csdn.net/isea533/article/details/83045335) 简介: 在早期项目文档中有过类似主题的内容,但是最近我自己看文档的时候发现一个问题,文档虽然很详细,但是并不适合初次接触的人。为了方便第一次听说,第一次尝试的开发人员了解通用 Mapper,补充此文档。 diff --git a/all/dependencies/pom.xml b/all/dependencies/pom.xml index cf2996c21..e01282c9a 100644 --- a/all/dependencies/pom.xml +++ b/all/dependencies/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-all - 4.1.5 + 4.2.0 mapper-all-dependencies jar diff --git a/all/mapper/pom.xml b/all/mapper/pom.xml index a26c2e1aa..82c02ddb1 100644 --- a/all/mapper/pom.xml +++ b/all/mapper/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-all - 4.1.5 + 4.2.0 mapper jar diff --git a/all/pom.xml b/all/pom.xml index dceb17a29..081ab9e69 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -31,7 +31,7 @@ 3 mapper-all - 4.1.5 + 4.2.0 pom mapper-all @@ -42,10 +42,10 @@ dependencies - - 1.1.5 - 1.1.5 - + + 4.2.0 + 4.2.0 + diff --git a/base/pom.xml b/base/pom.xml index 63e72933d..9acedae15 100644 --- a/base/pom.xml +++ b/base/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 1.1.5 + 4.2.0 mapper-base jar diff --git a/core/pom.xml b/core/pom.xml index 8dc6ea81c..ccf19a523 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 1.1.5 + 4.2.0 mapper-core jar diff --git a/extra/pom.xml b/extra/pom.xml index 9cdeafce1..4bfc68101 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 1.1.5 + 4.2.0 mapper-extra jar @@ -38,7 +38,7 @@ 1.8 - 1.1.5 + 4.2.0 diff --git a/generator/pom.xml b/generator/pom.xml index 1653ef973..d8433b3d1 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 1.1.5 + 4.2.0 mapper-generator jar @@ -37,7 +37,7 @@ Mybatis 通用 Mapper 代码生成器 - 1.1.5 + 4.2.0 2.3.28 1.3.7 diff --git a/pom.xml b/pom.xml index 423169e80..90d57c701 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ 3 mapper-modules - 1.1.5 + 4.2.0 pom mapper-parent diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml index 3f3192e83..5cf3c7bb3 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 2.1.5 + 4.2.0 mapper-spring-boot-autoconfigure mapper-spring-boot-autoconfigure diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml index d2b19aad1..2bc34ca6f 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot-samples - 2.1.5 + 4.2.0 mapper-spring-boot-sample-annotation jar diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml index 387161401..b6ec79a87 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot-samples - 2.1.5 + 4.2.0 mapper-spring-boot-sample-xml jar diff --git a/spring-boot-starter/mapper-spring-boot-samples/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/pom.xml index 08649fa83..5118df6ac 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 2.1.5 + 4.2.0 mapper-spring-boot-samples pom diff --git a/spring-boot-starter/mapper-spring-boot-starter/pom.xml b/spring-boot-starter/mapper-spring-boot-starter/pom.xml index 9735662c9..e118fe6b4 100644 --- a/spring-boot-starter/mapper-spring-boot-starter/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-starter/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 2.1.5 + 4.2.0 mapper-spring-boot-starter mapper-spring-boot-starter diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml index 4fce2ceef..425493f83 100644 --- a/spring-boot-starter/pom.xml +++ b/spring-boot-starter/pom.xml @@ -32,7 +32,7 @@ 3 mapper-spring-boot - 2.1.5 + 4.2.0 pom mapper-spring-boot @@ -45,13 +45,13 @@ mapper-spring-boot-samples - - 1.1.5 - 1.1.5 - 3.4.6 - 1.3.2 - 2.1.1.RELEASE - + + 4.2.0 + 4.2.0 + 3.5.9 + 2.0.7 + 2.6.4 + diff --git a/spring/pom.xml b/spring/pom.xml index 92ca169c9..5e8281666 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 1.1.5 + 4.2.0 mapper-spring jar diff --git a/weekend/pom.xml b/weekend/pom.xml index 8af3ee2c1..8d538e8ed 100644 --- a/weekend/pom.xml +++ b/weekend/pom.xml @@ -32,7 +32,7 @@ 3 mapper-weekend - 1.1.5 + 4.2.0 weekend Mybatis通用Mapper扩展 - weekend @@ -54,7 +54,7 @@ 1.8 - 1.1.5 + 4.2.0 From cc2a2fbfc07c212be35060bae452530267887194 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 27 Feb 2022 00:58:36 +0800 Subject: [PATCH 028/109] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=A5=E5=BF=97=EF=BC=8C=E5=8F=91=E5=B8=834.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6541a00d6..fb59e4207 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ - [新增] 生成实体类的时候,使用表注释创建类的注释 wugh 2019/5/30 11:28 b4acbf48 - 增加`lombokEqualsAndHashCodeCallSuper`配置,当使用lombok扩展的`EqualsAndHashCode`注解时,可通过此配置(true)为此注解添加`“callSuper = true”` ,这对于有继承父类的实体类,如增加支持动态表名时,有用。 calvinit 2019/2/14 13:52 ae901608 +- `orderByDesc`只有最后一个字段是倒序,改为所有参与`orderby`的字段都倒序 Mr 轩少/V1.1.5-orderByDesc-fix +- 增加Lombok 的`@SuperBuilder、@NoArgsConstructor、@AllArgsConstructor` 注解 tingwen 2020/12/26 18:29 8c816794 ## 还会有 MyBatis 通用 Mapper5 吗? From 3120d10848663c94dabd8bf14164b4dd61f865d5 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 27 Feb 2022 14:30:50 +0800 Subject: [PATCH 029/109] =?UTF-8?q?=E8=A1=A5=E5=85=85gitee=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=86=85=E5=AE=B9=EF=BC=8C=E5=8F=91=E5=B8=834.2.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 ++++++++--- all/dependencies/pom.xml | 2 +- all/mapper/pom.xml | 2 +- all/pom.xml | 6 +++--- base/pom.xml | 2 +- core/pom.xml | 2 +- extra/pom.xml | 4 ++-- generator/pom.xml | 4 ++-- pom.xml | 2 +- .../mapper-spring-boot-autoconfigure/pom.xml | 2 +- .../mapper-spring-boot-sample-annotation/pom.xml | 2 +- .../mapper-spring-boot-sample-xml/pom.xml | 2 +- .../mapper-spring-boot-samples/pom.xml | 2 +- .../mapper-spring-boot-starter/pom.xml | 2 +- spring-boot-starter/pom.xml | 6 +++--- spring/pom.xml | 2 +- weekend/pom.xml | 4 ++-- 17 files changed, 31 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index fb59e4207..aa4372f89 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,14 @@ **通用 Mapper 支持 Mybatis-3.2.4 及以上版本。** -## 4.2.0 - 2022-2-26 发布 +## 4.2.1 - 2022-2-27 + +4.2.0 版本中缺少了 gitee 仓库中的两个合并请求,针对这部分代码,再次发布 4.2.1 版本。 + +- `orderByDesc`只有最后一个字段是倒序,改为所有参与`orderby`的字段都倒序 Mr 轩少/V1.1.5-orderByDesc-fix +- 增加Lombok 的`@SuperBuilder、@NoArgsConstructor、@AllArgsConstructor` 注解 tingwen 2020/12/26 18:29 8c816794 + +## 4.2.0 - 2022-2-26 本次更新最大改动就是统一了所有模块的版本,所有版本都升级为 4.2.0,在之前本项目一共有3个版本号,本次升级前后的版本如下: @@ -40,8 +47,6 @@ - [新增] 生成实体类的时候,使用表注释创建类的注释 wugh 2019/5/30 11:28 b4acbf48 - 增加`lombokEqualsAndHashCodeCallSuper`配置,当使用lombok扩展的`EqualsAndHashCode`注解时,可通过此配置(true)为此注解添加`“callSuper = true”` ,这对于有继承父类的实体类,如增加支持动态表名时,有用。 calvinit 2019/2/14 13:52 ae901608 -- `orderByDesc`只有最后一个字段是倒序,改为所有参与`orderby`的字段都倒序 Mr 轩少/V1.1.5-orderByDesc-fix -- 增加Lombok 的`@SuperBuilder、@NoArgsConstructor、@AllArgsConstructor` 注解 tingwen 2020/12/26 18:29 8c816794 ## 还会有 MyBatis 通用 Mapper5 吗? diff --git a/all/dependencies/pom.xml b/all/dependencies/pom.xml index e01282c9a..37ab57c01 100644 --- a/all/dependencies/pom.xml +++ b/all/dependencies/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-all - 4.2.0 + 4.2.1 mapper-all-dependencies jar diff --git a/all/mapper/pom.xml b/all/mapper/pom.xml index 82c02ddb1..7eeeca20c 100644 --- a/all/mapper/pom.xml +++ b/all/mapper/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-all - 4.2.0 + 4.2.1 mapper jar diff --git a/all/pom.xml b/all/pom.xml index 081ab9e69..e7e1cb166 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -31,7 +31,7 @@ 3 mapper-all - 4.2.0 + 4.2.1 pom mapper-all @@ -43,8 +43,8 @@ - 4.2.0 - 4.2.0 + 4.2.1 + 4.2.1 diff --git a/base/pom.xml b/base/pom.xml index 9acedae15..bb00594c2 100644 --- a/base/pom.xml +++ b/base/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.0 + 4.2.1 mapper-base jar diff --git a/core/pom.xml b/core/pom.xml index ccf19a523..19c67cfee 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.0 + 4.2.1 mapper-core jar diff --git a/extra/pom.xml b/extra/pom.xml index 4bfc68101..fbf2a211d 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.0 + 4.2.1 mapper-extra jar @@ -38,7 +38,7 @@ 1.8 - 4.2.0 + 4.2.1 diff --git a/generator/pom.xml b/generator/pom.xml index d8433b3d1..3febfa83a 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.0 + 4.2.1 mapper-generator jar @@ -37,7 +37,7 @@ Mybatis 通用 Mapper 代码生成器 - 4.2.0 + 4.2.1 2.3.28 1.3.7 diff --git a/pom.xml b/pom.xml index 90d57c701..27a03a2c9 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ 3 mapper-modules - 4.2.0 + 4.2.1 pom mapper-parent diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml index 5cf3c7bb3..ce16e92d6 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.0 + 4.2.1 mapper-spring-boot-autoconfigure mapper-spring-boot-autoconfigure diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml index 2bc34ca6f..ce03e290a 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot-samples - 4.2.0 + 4.2.1 mapper-spring-boot-sample-annotation jar diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml index b6ec79a87..bb54e9a35 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot-samples - 4.2.0 + 4.2.1 mapper-spring-boot-sample-xml jar diff --git a/spring-boot-starter/mapper-spring-boot-samples/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/pom.xml index 5118df6ac..d0262fe9a 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.0 + 4.2.1 mapper-spring-boot-samples pom diff --git a/spring-boot-starter/mapper-spring-boot-starter/pom.xml b/spring-boot-starter/mapper-spring-boot-starter/pom.xml index e118fe6b4..46e1886b8 100644 --- a/spring-boot-starter/mapper-spring-boot-starter/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-starter/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.0 + 4.2.1 mapper-spring-boot-starter mapper-spring-boot-starter diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml index 425493f83..6349aa18b 100644 --- a/spring-boot-starter/pom.xml +++ b/spring-boot-starter/pom.xml @@ -32,7 +32,7 @@ 3 mapper-spring-boot - 4.2.0 + 4.2.1 pom mapper-spring-boot @@ -46,8 +46,8 @@ - 4.2.0 - 4.2.0 + 4.2.1 + 4.2.1 3.5.9 2.0.7 2.6.4 diff --git a/spring/pom.xml b/spring/pom.xml index 5e8281666..8da4d0c60 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.0 + 4.2.1 mapper-spring jar diff --git a/weekend/pom.xml b/weekend/pom.xml index 8d538e8ed..5bef03f70 100644 --- a/weekend/pom.xml +++ b/weekend/pom.xml @@ -32,7 +32,7 @@ 3 mapper-weekend - 4.2.0 + 4.2.1 weekend Mybatis通用Mapper扩展 - weekend @@ -54,7 +54,7 @@ 1.8 - 4.2.0 + 4.2.1 From 1b43023fefa020f8b8bb92294b0078db5720f6e1 Mon Sep 17 00:00:00 2001 From: rse <119827+higashikaze@user.noreply.gitee.com> Date: Mon, 21 Mar 2022 11:49:33 +0800 Subject: [PATCH 030/109] =?UTF-8?q?=E7=94=9F=E6=88=90model=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0=E9=80=BB=E8=BE=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AD=97=E6=AE=B5=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/generator/MapperCommentGenerator.java | 14 ++++++++++++++ .../tk/mybatis/mapper/generator/MapperPlugin.java | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java index c29a754e3..97ce85103 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java @@ -38,6 +38,7 @@ import java.util.Set; public class MapperCommentGenerator implements CommentGenerator { + //开始的分隔符,例如mysql为`,sqlserver为[ private String beginningDelimiter = ""; //结束的分隔符,例如mysql为`,sqlserver为] @@ -46,6 +47,8 @@ public class MapperCommentGenerator implements CommentGenerator { private boolean forceAnnotation; //是否生成swagger注解 private boolean needsSwagger; + //逻辑删除字段 + private String logicDeleteColumn = ""; public MapperCommentGenerator() { super(); @@ -94,6 +97,10 @@ public void addConfigurationProperties(Properties properties) { if (StringUtility.stringHasValue(needsSwagger)) { this.needsSwagger = "TRUE".equalsIgnoreCase(needsSwagger); } + String logicDeleteColumn = properties.getProperty("logicDeleteColumn"); + if (StringUtility.stringHasValue(logicDeleteColumn)) { + this.logicDeleteColumn = logicDeleteColumn; + } } public String getDelimiterName(String name) { @@ -176,6 +183,12 @@ public void addFieldComment(Field field, IntrospectedTable introspectedTable, In } else if (forceAnnotation) { field.addAnnotation("@Column(name = \"" + getDelimiterName(column) + "\")"); } + + // 添加逻辑删除注解 + if (column.equals(this.logicDeleteColumn)) { + field.addAnnotation("@LogicDelete"); + } + if (introspectedColumn.isIdentity()) { if ("JDBC".equals(introspectedTable.getTableConfiguration().getGeneratedKey().getRuntimeSqlStatement())) { field.addAnnotation("@GeneratedValue(generator = \"JDBC\")"); @@ -188,6 +201,7 @@ public void addFieldComment(Field field, IntrospectedTable introspectedTable, In String sql = MessageFormat.format(introspectedTable.getTableConfiguration().getGeneratedKey().getRuntimeSqlStatement(), tableName, tableName.toUpperCase()); field.addAnnotation("@GeneratedValue(strategy = GenerationType.IDENTITY, generator = \"" + sql + "\")"); } + // region swagger注解 if (this.needsSwagger) { String remarks = introspectedColumn.getRemarks(); diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index 734c791c3..6ade04c5b 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -79,6 +79,9 @@ public class MapperPlugin extends FalseMethodPlugin { private boolean generateDefaultInstanceMethod = false; //是否生成swagger注解,包括 @ApiModel和@ApiModelProperty private boolean needsSwagger = false; + //是否逻辑删除 + private boolean logicDelete = false; + public String getDelimiterName(String name) { StringBuilder nameBuilder = new StringBuilder(); @@ -252,6 +255,13 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i topLevelClass.addField(columnField); } } + + if(this.logicDelete) + { + topLevelClass.addImportedType("tk.mybatis.mapper.annotation.LogicDelete"); + } + + if (generateDefaultInstanceMethod) { //注意基本类型和包装的index要一致,方便后面使用 List baseClassName = Arrays.asList("byte", "short", "char", "int", "long", "float", "double", "boolean"); @@ -446,6 +456,8 @@ public void setProperties(Properties properties) { } this.generateColumnConsts = getPropertyAsBoolean("generateColumnConsts"); this.generateDefaultInstanceMethod = getPropertyAsBoolean("generateDefaultInstanceMethod"); + + this.logicDelete = Boolean.parseBoolean(this.properties.getProperty("logicDelete")); } protected String getProperty(String key) { From 3736e530f24ded87666e34ec9f0289905bc6fd9e Mon Sep 17 00:00:00 2001 From: rse <119827+higashikaze@user.noreply.gitee.com> Date: Mon, 21 Mar 2022 13:56:00 +0800 Subject: [PATCH 031/109] =?UTF-8?q?=E5=85=BC=E5=AE=B9=20mybatis=20generato?= =?UTF-8?q?r=201.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generator/pom.xml | 2 +- .../mapper/generator/FalseMethodPlugin.java | 39 ------------------- .../generator/MapperCommentGenerator.java | 4 +- .../mapper/generator/MapperPlugin.java | 33 ++++++++++------ 4 files changed, 24 insertions(+), 54 deletions(-) diff --git a/generator/pom.xml b/generator/pom.xml index 3febfa83a..4c26110ae 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -39,7 +39,7 @@ 4.2.1 2.3.28 - 1.3.7 + 1.4.1 diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/FalseMethodPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/FalseMethodPlugin.java index ceea47bfb..96faf080e 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/FalseMethodPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/FalseMethodPlugin.java @@ -46,40 +46,6 @@ public boolean validate(List warnings) { } //下面所有return false的方法都不生成。这些都是基础的CRUD方法,使用通用Mapper实现 - @Override - public boolean clientDeleteByPrimaryKeyMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - return false; - } - - @Override - public boolean clientInsertMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - return false; - } - - @Override - public boolean clientInsertSelectiveMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - return false; - } - - @Override - public boolean clientSelectByPrimaryKeyMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - return false; - } - - @Override - public boolean clientUpdateByPrimaryKeySelectiveMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - return false; - } - - @Override - public boolean clientUpdateByPrimaryKeyWithBLOBsMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - return false; - } - - @Override - public boolean clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - return false; - } @Override public boolean clientDeleteByPrimaryKeyMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) { @@ -101,11 +67,6 @@ public boolean clientSelectAllMethodGenerated(Method method, Interface interfaze return false; } - @Override - public boolean clientSelectAllMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - return false; - } - @Override public boolean clientSelectByPrimaryKeyMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) { return false; diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java index c29a754e3..8b0e14113 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java @@ -177,7 +177,7 @@ public void addFieldComment(Field field, IntrospectedTable introspectedTable, In field.addAnnotation("@Column(name = \"" + getDelimiterName(column) + "\")"); } if (introspectedColumn.isIdentity()) { - if ("JDBC".equals(introspectedTable.getTableConfiguration().getGeneratedKey().getRuntimeSqlStatement())) { + if ("JDBC".equals(introspectedTable.getTableConfiguration().getGeneratedKey().get().getRuntimeSqlStatement())) { field.addAnnotation("@GeneratedValue(generator = \"JDBC\")"); } else { field.addAnnotation("@GeneratedValue(strategy = GenerationType.IDENTITY)"); @@ -185,7 +185,7 @@ public void addFieldComment(Field field, IntrospectedTable introspectedTable, In } else if (introspectedColumn.isSequenceColumn()) { //在 Oracle 中,如果需要是 SEQ_TABLENAME,那么可以配置为 select SEQ_{1} from dual String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); - String sql = MessageFormat.format(introspectedTable.getTableConfiguration().getGeneratedKey().getRuntimeSqlStatement(), tableName, tableName.toUpperCase()); + String sql = MessageFormat.format(introspectedTable.getTableConfiguration().getGeneratedKey().get().getRuntimeSqlStatement(), tableName, tableName.toUpperCase()); field.addAnnotation("@GeneratedValue(strategy = GenerationType.IDENTITY, generator = \"" + sql + "\")"); } // region swagger注解 diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index 734c791c3..a80f7ef25 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -29,6 +29,7 @@ import org.mybatis.generator.api.dom.java.*; import org.mybatis.generator.config.CommentGeneratorConfiguration; import org.mybatis.generator.config.Context; +import org.mybatis.generator.config.JDBCConnectionConfiguration; import org.mybatis.generator.internal.util.StringUtility; import java.util.*; @@ -96,12 +97,11 @@ public String getDelimiterName(String name) { * 生成的Mapper接口 * * @param interfaze - * @param topLevelClass * @param introspectedTable * @return */ @Override - public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) { //获取实体类 FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType()); //import接口 @@ -232,22 +232,22 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i } if (generateColumnConsts) { for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { - Field field = new Field(); + String fieldName = introspectedColumn.getActualColumnName().toUpperCase(); //$NON-NLS-1$ + FullyQualifiedJavaType fieldType = new FullyQualifiedJavaType(String.class.getName()); //$NON-NLS-1$ + Field field = new Field(fieldName, fieldType); field.setVisibility(JavaVisibility.PUBLIC); field.setStatic(true); field.setFinal(true); - field.setName(introspectedColumn.getActualColumnName().toUpperCase()); //$NON-NLS-1$ - field.setType(new FullyQualifiedJavaType(String.class.getName())); //$NON-NLS-1$ field.setInitializationString("\"" + introspectedColumn.getJavaProperty() + "\""); context.getCommentGenerator().addClassComment(topLevelClass, introspectedTable); topLevelClass.addField(field); //增加字段名常量,用于pageHelper - Field columnField = new Field(); + String columnFieldName = "DB_" + introspectedColumn.getActualColumnName().toUpperCase(); //$NON-NLS-1$ + FullyQualifiedJavaType columnFieldType = new FullyQualifiedJavaType(String.class.getName()); //$NON-NLS-1$ + Field columnField = new Field(columnFieldName, columnFieldType); columnField.setVisibility(JavaVisibility.PUBLIC); columnField.setStatic(true); columnField.setFinal(true); - columnField.setName("DB_" + introspectedColumn.getActualColumnName().toUpperCase()); //$NON-NLS-1$ - columnField.setType(new FullyQualifiedJavaType(String.class.getName())); //$NON-NLS-1$ columnField.setInitializationString("\"" + introspectedColumn.getActualColumnName() + "\""); topLevelClass.addField(columnField); } @@ -257,13 +257,12 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i List baseClassName = Arrays.asList("byte", "short", "char", "int", "long", "float", "double", "boolean"); List wrapperClassName = Arrays.asList("Byte", "Short", "Character", "Integer", "Long", "Float", "Double", "Boolean"); List otherClassName = Arrays.asList("String", "BigDecimal", "BigInteger"); - Method defaultMethod = new Method(); + Method defaultMethod = new Method("defaultInstance"); //增加方法注释 defaultMethod.addJavaDocLine("/**"); defaultMethod.addJavaDocLine(" * 带默认值的实例"); defaultMethod.addJavaDocLine("*/"); defaultMethod.setStatic(true); - defaultMethod.setName("defaultInstance"); defaultMethod.setVisibility(JavaVisibility.PUBLIC); defaultMethod.setReturnType(topLevelClass.getType()); defaultMethod.addBodyLine(String.format("%s instance = new %s();", topLevelClass.getType().getShortName(), topLevelClass.getType().getShortName())); @@ -390,10 +389,20 @@ public void setContext(Context context) { commentCfg.setConfigurationType(MapperCommentGenerator.class.getCanonicalName()); context.setCommentGeneratorConfiguration(commentCfg); } + + JDBCConnectionConfiguration jdbcConnectionConfiguration = null; + try { + java.lang.reflect.Field jdbcConnectionConfigurationField = Context.class.getDeclaredField("jdbcConnectionConfiguration"); + jdbcConnectionConfigurationField.setAccessible(true); + jdbcConnectionConfiguration = (JDBCConnectionConfiguration) jdbcConnectionConfigurationField.get(context); + } catch (Exception e) { + e.printStackTrace(); + } + //支持oracle获取注释#114 - context.getJdbcConnectionConfiguration().addProperty("remarksReporting", "true"); + jdbcConnectionConfiguration.addProperty("remarksReporting", "true"); //支持mysql获取注释 - context.getJdbcConnectionConfiguration().addProperty("useInformationSchema", "true"); + jdbcConnectionConfiguration.addProperty("useInformationSchema", "true"); } @Override From 606f0268b1554dd83c746bc4dfb25c77af7d27db Mon Sep 17 00:00:00 2001 From: abel533 Date: Wed, 6 Apr 2022 11:16:37 +0800 Subject: [PATCH 032/109] ## 4.2.2-SNAPSHOT - 2022-04-06 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 parent 依赖版本 - 升级 mybatis 为 3.5.9 - 升级 hsqldb 为 2.5.2 - 升级 jps 依赖,使用 2.2 (GAV全变了) - 修改 test 中的 log4j 为 logback - 格式化代码 --- .github/FUNDING.yml | 2 +- .github/workflows/pull-request.yml | 16 + .github/workflows/release.yml | 29 + .travis.yml | 8 - README.md | 43 +- all/dependencies/README.md | 4 +- all/dependencies/pom.xml | 2 +- all/mapper/pom.xml | 4 +- all/pom.xml | 97 +-- base/pom.xml | 6 +- .../mapper/provider/SpecialProvider.java | 1 - .../provider/base/BaseInsertProvider.java | 4 +- .../java/tk/mybatis/mapper/base/BaseTest.java | 19 +- .../java/tk/mybatis/mapper/base/CreateDB.sql | 560 ++++++++----- .../delete/DeleteByPrimaryKeyMapperTest.java | 2 +- .../tk/mybatis/mapper/base/genid/CreateDB.sql | 18 +- .../mapper/base/genid/InsertGenIdTest.java | 14 +- .../mapper/base/genid/SimpleGenId.java | 2 +- .../mapper/base/genid/mybatis-config.xml | 8 +- .../tk/mybatis/mapper/base/mybatis-config.xml | 8 +- .../mapper/cache/CountryCacheRefMapper.java | 2 +- .../mapper/cache/CountryCacheRefMapper.xml | 4 +- .../cache/CountryCacheWithXmlMapper.java | 2 +- .../cache/CountryCacheWithXmlMapper.xml | 4 +- .../mapper/cache/mybatis-config-cache.xml | 11 +- .../defaultenumtypehandler/CreateDB.sql | 17 +- .../DefaultEnumTypeHandlerTest.java | 10 +- .../DictTypeHandler.java | 2 +- .../defaultenumtypehandler/LockDictEnum.java | 2 +- .../defaultenumtypehandler/StateDictEnum.java | 2 +- .../mapper/defaultenumtypehandler/User.java | 6 +- .../mybatis-config-defaultenumtypehandler.xml | 8 +- .../mapper/generatedvalue/CreateDB.sql | 27 +- .../mybatis-config-keysql-mysql.xml | 13 +- .../mybatis/mapper/hsqldb/HsqldbMapper.java | 2 +- .../mybatis/mapper/hsqldb/HsqldbProvider.java | 11 +- .../mapper/issues/_216_datetime/CreateDB.sql | 17 +- .../issues/_216_datetime/DateTimeTest.java | 6 +- .../issues/_216_datetime/TimeModel2.java | 6 +- .../issues/_216_datetime/TimeModel3.java | 6 +- .../mybatis-config-timestamp.xml | 8 +- .../tk/mybatis/mapper/keysql/CreateDB.sql | 27 +- .../keysql/mybatis-config-keysql-mysql.xml | 13 +- .../mapper/mapper/CachedCountryMapper.java | 2 +- .../mybatis/mapper/model/BaseLogicDelete.java | 3 +- .../test/country/TestInsertSelective.java | 2 +- .../test/country/TestSelectByPrimaryKey.java | 2 +- .../test/country/TestUpdateByPrimaryKey.java | 4 +- .../test/country2/TestInsertSelective.java | 2 +- .../test/example/TestExampleBuilder.java | 60 +- .../test/example/TestSelectByExample.java | 9 +- .../example/TestUpdateByExampleSelective.java | 4 +- .../tk/mybatis/mapper/test/jdbc/TestJDBC.java | 4 +- .../mapper/test/logic/TestLogicDelete.java | 2 +- .../mapper/test/othres/TestDelimiter.java | 10 +- .../mapper/test/transientc/TestTransient.java | 2 +- .../mybatis/mapper/test/user/TestBasic.java | 4 +- .../tk/mybatis/mapper/test/user/TestMap.java | 8 +- .../mybatis/mapper/typehandler/Address.java | 4 +- .../typehandler/AddressTypeHandler.java | 8 +- .../mybatis/mapper/typehandler/CreateDB.sql | 17 +- .../mapper/typehandler/TypeHandlerTest.java | 10 +- .../mapper/typehandler/TypeHandlerTest2.java | 10 +- .../tk/mybatis/mapper/typehandler/User2.java | 6 +- .../mybatis-config-typehandler.xml | 11 +- .../mybatis-config-typehandler2.xml | 11 +- .../tk/mybatis/mapper/version/CreateDB.sql | 24 +- .../tk/mybatis/mapper/version/UserInt.java | 1 - .../mybatis/mapper/version/VersionTest.java | 1 - .../mapper/version/mybatis-config-version.xml | 11 +- .../test/resources/CachedCountryMapper.xml | 4 +- base/src/test/resources/CreateDB.sql | 745 ++++++++++++------ base/src/test/resources/log4j.properties | 35 - base/src/test/resources/logback.xml | 10 + base/src/test/resources/mybatis-java.xml | 8 +- core/README.md | 20 +- core/pom.xml | 4 +- .../tk/mybatis/mapper/annotation/Order.java | 2 + .../mybatis/mapper/code/IdentityDialect.java | 2 +- .../java/tk/mybatis/mapper/entity/Config.java | 10 +- .../tk/mybatis/mapper/entity/EntityField.java | 2 +- .../tk/mybatis/mapper/entity/EntityTable.java | 29 +- .../tk/mybatis/mapper/entity/Example.java | 48 +- .../java/tk/mybatis/mapper/genid/GenId.java | 6 +- .../mapper/mapperhelper/FieldHelper.java | 13 +- .../mapper/mapperhelper/MapperHelper.java | 24 +- .../mapper/mapperhelper/MapperTemplate.java | 10 +- .../mapperhelper/SelectKeyGenerator.java | 6 +- .../mapper/mapperhelper/SqlHelper.java | 6 +- .../resolve/DefaultEntityResolve.java | 10 +- .../java/tk/mybatis/mapper/util/MsUtil.java | 2 +- .../java/tk/mybatis/mapper/util/OGNL.java | 8 +- .../mybatis/mapper/util/SimpleTypeUtil.java | 10 +- .../mybatis/mapper/util/SqlReservedWords.java | 7 +- .../java/tk/mybatis/mapper/util/Sqls.java | 6 +- .../mybatis/mapper/annotation/ColumnTest.java | 4 +- .../mapper/annotation/ColumnTypeTest.java | 12 +- .../tk/mybatis/mapper/annotation/IdTest.java | 8 +- .../mybatis/mapper/annotation/KeySqlTest.java | 12 +- .../mapper/annotation/NameStyleTest.java | 14 +- .../mapper/annotation/RegisterMapperTest.java | 8 +- .../mapper/annotation/VersionTest.java | 6 +- .../mapper/mapperhelper/FieldHelperTest.java | 4 +- extra/README.md | 10 +- extra/pom.xml | 5 +- .../aggregation/AggregateCondition.java | 10 +- .../delete/DeleteByPropertyMapper.java | 14 +- .../delete/DeletePropertyProvider.java | 14 +- .../dialect/oracle/InsertListMapper.java | 1 + .../dialect/oracle/OracleProvider.java | 22 +- .../additional/idlist/IdListProvider.java | 8 +- .../select/SelectByPropertyMapper.java | 19 +- .../select/SelectPropertyProvider.java | 15 +- .../update/differ/UpdateByDifferProvider.java | 6 +- ...pdateByPrimaryKeySelectiveForceMapper.java | 3 +- ...ateByPrimaryKeySelectiveForceProvider.java | 8 +- .../mybatis/mapper/additional/BaseTest.java | 19 +- .../tk/mybatis/mapper/additional/CreateDB.sql | 560 ++++++++----- .../aggregation/AggregationMapperTest.java | 8 +- .../additional/aggregation/CreateDB.sql | 27 +- .../mapper/additional/aggregation/User.java | 6 +- .../additional/aggregation/mybatis-config.xml | 8 +- .../mapper/additional/delete/Course.java | 2 +- .../mapper/additional/delete/CreateDB.sql | 25 +- .../additional/delete/mybatis-config.xml | 8 +- .../additional/dialect/oracle/CreateDB.sql | 51 +- .../additional/dialect/oracle/OracleTest.java | 10 +- .../dialect/oracle/mybatis-config.xml | 12 +- .../additional/idlist/mybatis-config.xml | 8 +- .../mapper/additional/insertlist/CreateDB.sql | 9 +- .../mapper/additional/insertlist/User.java | 6 +- .../additional/insertlist/mybatis-config.xml | 8 +- .../mapper/additional/mybatis-config.xml | 8 +- .../mapper/additional/select/CreateDB.sql | 23 +- .../additional/select/mybatis-config.xml | 8 +- .../differ/UpdateByDifferMapperTest.java | 4 +- .../update/differ/mybatis-config.xml | 8 +- .../update/force/CountryIntMapper.java | 2 +- .../additional/update/force/CreateDB.sql | 12 +- .../UpdateByPrimaryKeySelectiveForceTest.java | 8 +- .../update/force/mybatis-config.xml | 8 +- extra/src/test/resources/log4j.properties | 35 - extra/src/test/resources/logback.xml | 10 + generator/README.md | 21 +- generator/pom.xml | 6 +- .../mapper/generator/TemplateFilePlugin.java | 18 +- .../FreemarkerTemplateFormatter.java | 2 +- .../mapper/generator/model/ColumnField.java | 36 +- .../mapper/generator/model/TableClass.java | 12 +- .../src/main/resources/generator/test-all.ftl | 156 ++-- .../src/main/resources/generator/test-one.ftl | 132 ++-- .../mybatis/mapper/generator/Generator.java | 7 +- generator/src/test/resources/CreateDB.sql | 87 +- .../src/test/resources/generatorConfig.xml | 8 +- pom.xml | 9 +- spring-boot-starter/README.md | 28 +- .../mapper-spring-boot-autoconfigure/pom.xml | 2 +- .../ConfigurationCustomizer.java | 37 +- .../MapperAutoConfiguration.java | 40 +- .../autoconfigure/MybatisProperties.java | 360 ++++----- .../mapper/autoconfigure/SpringBootVFS.java | 70 +- .../pom.xml | 2 +- .../tk/mybatis/sample/domain/Country.java | 2 +- .../src/main/resources/import.sql | 558 ++++++++----- .../mapper-spring-boot-sample-xml/pom.xml | 2 +- .../tk/mybatis/sample/domain/Country.java | 2 +- .../src/main/resources/import.sql | 558 ++++++++----- .../mybatis/sample/mapper/CountryMapper.xml | 3 +- .../mapper-spring-boot-samples/pom.xml | 2 +- .../mapper-spring-boot-starter/pom.xml | 2 +- spring-boot-starter/pom.xml | 19 +- spring/README.md | 20 +- spring/pom.xml | 2 +- .../mybatis/spring/annotation/MapperScan.java | 26 +- .../annotation/MapperScannerRegistrar.java | 4 +- .../spring/mapper/ClassPathMapperScanner.java | 12 +- .../spring/mapper/MapperFactoryBean.java | 27 +- .../mapper/MapperScannerConfigurer.java | 26 +- .../tk/mybatis/mapper/annotation/Country.java | 4 +- .../annotation/SpringAnnotationTest.java | 18 +- .../mybatis/mapper/configuration/Country.java | 4 +- .../mybatis/mapper/configuration/CreateDB.sql | 560 ++++++++----- .../configuration/SpringConfigTest.java | 1 + .../java/tk/mybatis/mapper/xml/Country.java | 4 +- .../java/tk/mybatis/mapper/xml/CreateDB.sql | 560 ++++++++----- spring/src/test/resources/log4j.properties | 35 - spring/src/test/resources/logback.xml | 10 + weekend/README.md | 3 +- weekend/pom.xml | 7 +- .../mapper/weekend/SqlCriteriaHelper.java | 183 +++-- .../weekend/reflection/Reflections.java | 2 +- .../mybatis/mapper/weekend/MybatisHelper.java | 3 +- .../mapper/weekend/SqlCriteriaHelperTest.java | 24 +- .../mapper/weekend/UserMapperTest.java | 21 +- .../mapper/weekend/entity/Country.java | 2 +- .../mybatis/mapper/weekend/entity/User.java | 2 +- weekend/src/test/resources/CreateDB.sql | 562 ++++++++----- weekend/src/test/resources/log4j.properties | 36 - weekend/src/test/resources/logback.xml | 10 + weekend/src/test/resources/mybatis-java.xml | 8 +- 200 files changed, 4709 insertions(+), 3056 deletions(-) create mode 100644 .github/workflows/pull-request.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml delete mode 100644 base/src/test/resources/log4j.properties create mode 100644 base/src/test/resources/logback.xml delete mode 100644 extra/src/test/resources/log4j.properties create mode 100644 extra/src/test/resources/logback.xml delete mode 100644 spring/src/test/resources/log4j.properties create mode 100644 spring/src/test/resources/logback.xml delete mode 100644 weekend/src/test/resources/log4j.properties create mode 100644 weekend/src/test/resources/logback.xml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 330ffab34..fffdb3c06 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username -custom: ['https://mybatis.io/donates.html'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] +custom: [ 'https://mybatis.io/donates.html' ] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 000000000..1a0aa842f --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,16 @@ +name: Maven verify +on: + pull_request: + types: [ opened, reopened, edited ] +jobs: + mvn_verify: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Maven Central Repository + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + - name: Run the Maven verify phase + run: mvn --batch-mode --update-snapshots -P dev verify \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..37ac4d42f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: Publish package to the Maven Central Repository +on: + push: + tags: [ "*" ] + branches: + - master +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Maven Central Repository + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - id: install-secret-key + name: Install gpg secret key + run: | + cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import + gpg --list-secret-keys --keyid-format LONG + - name: Publish package + env: + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + run: mvn --batch-mode -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} -P release clean deploy \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 96f3fe8ae..000000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: java - -sudo: false - -dist: precise - -jdk: - - oraclejdk8 diff --git a/README.md b/README.md index aa4372f89..d71fe8b5d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # MyBatis 通用 Mapper4 -[![Build Status](https://travis-ci.org/abel533/Mapper.svg?branch=master)](https://travis-ci.org/abel533/Mapper) [![Maven central](https://maven-badges.herokuapp.com/maven-central/tk.mybatis/mapper/badge.svg)](https://maven-badges.herokuapp.com/maven-central/tk.mybatis/mapper) 通用Mapper都可以极大的方便开发人员。可以随意的按照自己的需要选择通用方法,还可以很方便的开发自己的通用方法。 @@ -11,6 +10,15 @@ **通用 Mapper 支持 Mybatis-3.2.4 及以上版本。** +## 4.2.2-SNAPSHOT - 2022-04-06 + +- 更新 parent 依赖版本 +- 升级 mybatis 为 3.5.9 +- 升级 hsqldb 为 2.5.2 +- 升级 jps 依赖,使用 2.2 (GAV全变了) +- 修改 test 中的 log4j 为 logback +- 格式化代码 + ## 4.2.1 - 2022-2-27 4.2.0 版本中缺少了 gitee 仓库中的两个合并请求,针对这部分代码,再次发布 4.2.1 版本。 @@ -79,7 +87,7 @@ mybatis-mapper,如果你动手能力强,喜欢看源码,你也可以试试 ## 项目文档 -- [文档 - Gitee](https://gitee.com/free/Mapper/wikis/Home) +- [文档 - Gitee](https://gitee.com/free/Mapper/wikis/Home) - [文档 - GitHub](https://github.com/abel533/Mapper/wiki) @@ -90,28 +98,27 @@ mybatis-mapper,如果你动手能力强,喜欢看源码,你也可以试试 - [更新日志 - GitHub](https://github.com/abel533/Mapper/wiki/changelog) ## 作者信息 - - MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) - - 作者博客:http://blog.csdn.net/isea533 - - 作者邮箱: abel533@gmail.com - - 如需加群,请通过 https://mybatis.io 首页按钮加群。 - - 推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper) - + +MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) + +作者博客:http://blog.csdn.net/isea533 + +作者邮箱: abel533@gmail.com + +如需加群,请通过 https://mybatis.io 首页按钮加群。 + +推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper) + ## 作者新书:《MyBatis 从入门到精通》 ![MyBatis 从入门到精通](https://github.com/mybatis-book/book/raw/master/book.png) ### 简介 -本书中从一个简单的 MyBatis 查询入手,搭建起学习 MyBatis 的基础开发环境。 -通过全面的示例代码和测试讲解了在 MyBatis XML 方式和注解方式中进行增、删、改、查操作的基本用法,介绍了动态 SQL 在不同方面的应用以及在使用过程中的最佳实践方案。 -针对 MyBatis 高级映射、存储过程和类型处理器提供了丰富的示例,通过自下而上的方法使读者更好地理解和掌握MyBatis 的高级用法,同时针对 MyBatis 的代码生成器提供了详细的配置介绍。 -此外,本书还提供了缓存配置、插件开发、Spring、Spring Boot 集成的详细内容。 -最后通过介绍 Git 和 GitHub 让读者了解MyBatis 开源项目,通过对 MyBatis 源码和测试用例的讲解让读者更好掌握 MyBatis。 +本书中从一个简单的 MyBatis 查询入手,搭建起学习 MyBatis 的基础开发环境。 通过全面的示例代码和测试讲解了在 MyBatis XML 方式和注解方式中进行增、删、改、查操作的基本用法,介绍了动态 SQL +在不同方面的应用以及在使用过程中的最佳实践方案。 针对 MyBatis 高级映射、存储过程和类型处理器提供了丰富的示例,通过自下而上的方法使读者更好地理解和掌握MyBatis 的高级用法,同时针对 MyBatis +的代码生成器提供了详细的配置介绍。 此外,本书还提供了缓存配置、插件开发、Spring、Spring Boot 集成的详细内容。 最后通过介绍 Git 和 GitHub 让读者了解MyBatis 开源项目,通过对 MyBatis +源码和测试用例的讲解让读者更好掌握 MyBatis。 ### 购买地址: diff --git a/all/dependencies/README.md b/all/dependencies/README.md index fbe72c2dc..d6df996f6 100644 --- a/all/dependencies/README.md +++ b/all/dependencies/README.md @@ -16,7 +16,7 @@ 引入后会自动引入其他依赖。 -可以通过在 pom 中增加下面对应的属性来修改依赖的版本号: +可以通过在 pom 中增加下面对应的属性来修改依赖的版本号: ```xml @@ -28,4 +28,4 @@ ``` ->上面具体版本号只是示例,默认不需要自己设置。 \ No newline at end of file +> 上面具体版本号只是示例,默认不需要自己设置。 \ No newline at end of file diff --git a/all/dependencies/pom.xml b/all/dependencies/pom.xml index 37ab57c01..a9101e244 100644 --- a/all/dependencies/pom.xml +++ b/all/dependencies/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-all - 4.2.1 + 4.2.2-SNAPSHOT mapper-all-dependencies jar diff --git a/all/mapper/pom.xml b/all/mapper/pom.xml index 7eeeca20c..884845856 100644 --- a/all/mapper/pom.xml +++ b/all/mapper/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-all - 4.2.1 + 4.2.2-SNAPSHOT mapper jar @@ -40,7 +40,7 @@ javax.persistence - persistence-api + javax.persistence-api tk.mybatis diff --git a/all/pom.xml b/all/pom.xml index e7e1cb166..9f1a2d254 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -28,63 +28,64 @@ tk.mybatis mapper-parent - 3 + 8 + mapper-all - 4.2.1 + 4.2.2-SNAPSHOT pom mapper-all Mybatis 通用 Mapper3 适配 - - + + mapper dependencies - - 4.2.1 - 4.2.1 - + + 4.2.2-SNAPSHOT + 4.2.2-SNAPSHOT + - - - - tk.mybatis - mapper-core - ${mapper-module.version} - compile - - - tk.mybatis - mapper-base - ${mapper-module.version} - compile - - - tk.mybatis - mapper-extra - ${mapper-module.version} - compile - - - tk.mybatis - mapper-spring - ${mapper-module.version} - compile - - - tk.mybatis - mapper-weekend - ${mapper-weekend.version} - compile - - - tk.mybatis - mapper-generator - ${mapper-module.version} - compile - - - + + + + tk.mybatis + mapper-core + ${mapper-module.version} + compile + + + tk.mybatis + mapper-base + ${mapper-module.version} + compile + + + tk.mybatis + mapper-extra + ${mapper-module.version} + compile + + + tk.mybatis + mapper-spring + ${mapper-module.version} + compile + + + tk.mybatis + mapper-weekend + ${mapper-weekend.version} + compile + + + tk.mybatis + mapper-generator + ${mapper-module.version} + compile + + + diff --git a/base/pom.xml b/base/pom.xml index bb00594c2..ea178f0eb 100644 --- a/base/pom.xml +++ b/base/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.1 + 4.2.2-SNAPSHOT mapper-base jar @@ -41,9 +41,9 @@ javax.persistence - persistence-api + javax.persistence-api - + tk.mybatis mapper-core diff --git a/base/src/main/java/tk/mybatis/mapper/provider/SpecialProvider.java b/base/src/main/java/tk/mybatis/mapper/provider/SpecialProvider.java index 121152003..f9fb6bec8 100644 --- a/base/src/main/java/tk/mybatis/mapper/provider/SpecialProvider.java +++ b/base/src/main/java/tk/mybatis/mapper/provider/SpecialProvider.java @@ -30,7 +30,6 @@ import tk.mybatis.mapper.mapperhelper.MapperHelper; import tk.mybatis.mapper.mapperhelper.MapperTemplate; import tk.mybatis.mapper.mapperhelper.SqlHelper; -import tk.mybatis.mapper.util.StringUtil; import java.util.Set; diff --git a/base/src/main/java/tk/mybatis/mapper/provider/base/BaseInsertProvider.java b/base/src/main/java/tk/mybatis/mapper/provider/base/BaseInsertProvider.java index be2cf58ea..7d42856a2 100644 --- a/base/src/main/java/tk/mybatis/mapper/provider/base/BaseInsertProvider.java +++ b/base/src/main/java/tk/mybatis/mapper/provider/base/BaseInsertProvider.java @@ -132,7 +132,7 @@ public String insertSelective(MappedStatement ms) { return sql.toString(); } - private void processKey(StringBuilder sql, Class entityClass, MappedStatement ms, Set columnList){ + private void processKey(StringBuilder sql, Class entityClass, MappedStatement ms, Set columnList) { //Identity列只能有一个 Boolean hasIdentityKey = false; //先处理cache或bind节点 @@ -153,7 +153,7 @@ private void processKey(StringBuilder sql, Class entityClass, MappedStatement //插入selectKey SelectKeyHelper.newSelectKeyMappedStatement(ms, column, entityClass, isBEFORE(), getIDENTITY(column)); hasIdentityKey = true; - } else if(column.getGenIdClass() != null){ + } else if (column.getGenIdClass() != null) { sql.append(" { - private Long time; + private Long time; private Integer seq; @Override diff --git a/base/src/test/java/tk/mybatis/mapper/base/genid/mybatis-config.xml b/base/src/test/java/tk/mybatis/mapper/base/genid/mybatis-config.xml index e1b8888a7..298cd565b 100644 --- a/base/src/test/java/tk/mybatis/mapper/base/genid/mybatis-config.xml +++ b/base/src/test/java/tk/mybatis/mapper/base/genid/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/base/src/test/java/tk/mybatis/mapper/base/mybatis-config.xml b/base/src/test/java/tk/mybatis/mapper/base/mybatis-config.xml index a657f7baa..077255e1d 100644 --- a/base/src/test/java/tk/mybatis/mapper/base/mybatis-config.xml +++ b/base/src/test/java/tk/mybatis/mapper/base/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheRefMapper.java b/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheRefMapper.java index 57620e7b9..bd6e2570c 100644 --- a/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheRefMapper.java +++ b/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheRefMapper.java @@ -6,7 +6,7 @@ /** * 这个例子中,在 XML 配置了缓存,这里使用注解引用 XML 中的缓存配置 - * + *

* namespace 有两种配置方法,参考下面两行注解 */ @CacheNamespaceRef(CountryCacheRefMapper.class) diff --git a/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheRefMapper.xml b/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheRefMapper.xml index 552c4dc6d..bc5277a37 100644 --- a/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheRefMapper.xml +++ b/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheRefMapper.xml @@ -31,6 +31,8 @@ diff --git a/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheWithXmlMapper.java b/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheWithXmlMapper.java index 75c4f3ad7..94a5927a6 100644 --- a/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheWithXmlMapper.java +++ b/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheWithXmlMapper.java @@ -6,7 +6,7 @@ /** * 这个例子中,接口定义了缓存,对应的 XML 中引用这里的缓存 - * + *

* TODO MyBatis 有 Bug,这种方式目前行不通 */ @CacheNamespace diff --git a/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheWithXmlMapper.xml b/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheWithXmlMapper.xml index 5623738ba..05a4b12ee 100644 --- a/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheWithXmlMapper.xml +++ b/base/src/test/java/tk/mybatis/mapper/cache/CountryCacheWithXmlMapper.xml @@ -32,6 +32,8 @@ diff --git a/base/src/test/java/tk/mybatis/mapper/cache/mybatis-config-cache.xml b/base/src/test/java/tk/mybatis/mapper/cache/mybatis-config-cache.xml index e3f6a3ac2..1a9effe7a 100644 --- a/base/src/test/java/tk/mybatis/mapper/cache/mybatis-config-cache.xml +++ b/base/src/test/java/tk/mybatis/mapper/cache/mybatis-config-cache.xml @@ -30,11 +30,12 @@ - + - + @@ -42,9 +43,9 @@ - - - + + + diff --git a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/CreateDB.sql b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/CreateDB.sql index 7772e15f4..643eabd30 100644 --- a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/CreateDB.sql +++ b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/CreateDB.sql @@ -1,11 +1,14 @@ drop table user if exists; -create table user ( - id integer NOT NULL PRIMARY KEY, - name varchar(32), - lock integer, - state integer +create table user +( + id integer NOT NULL PRIMARY KEY, + name varchar(32), + lock integer, + state integer ); -INSERT INTO user (id, name, lock, state) VALUES (1, 'abel533', 2, 1); -INSERT INTO user (id, name, lock, state) VALUES (2, 'isea533', 1, 2); \ No newline at end of file +INSERT INTO user (id, name, lock, state) +VALUES (1, 'abel533', 2, 1); +INSERT INTO user (id, name, lock, state) +VALUES (2, 'isea533', 1, 2); \ No newline at end of file diff --git a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/DefaultEnumTypeHandlerTest.java b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/DefaultEnumTypeHandlerTest.java index 895070514..8d7a9f777 100644 --- a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/DefaultEnumTypeHandlerTest.java +++ b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/DefaultEnumTypeHandlerTest.java @@ -13,7 +13,7 @@ /** * @author liuzh */ -public class DefaultEnumTypeHandlerTest extends BaseTest{ +public class DefaultEnumTypeHandlerTest extends BaseTest { @Override protected Config getConfig() { @@ -33,7 +33,7 @@ protected Reader getSqlFileAsReader() throws IOException { } @Test - public void testSelect(){ + public void testSelect() { SqlSession sqlSession = getSqlSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); @@ -59,7 +59,7 @@ public void testSelect(){ } @Test - public void testInsert(){ + public void testInsert() { SqlSession sqlSession = getSqlSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); @@ -82,7 +82,7 @@ public void testInsert(){ } @Test - public void testUpdate(){ + public void testUpdate() { SqlSession sqlSession = getSqlSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); @@ -105,7 +105,7 @@ public void testUpdate(){ } @Test - public void testDelete(){ + public void testDelete() { SqlSession sqlSession = getSqlSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); diff --git a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/DictTypeHandler.java b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/DictTypeHandler.java index 2d52e09ab..e5915e886 100644 --- a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/DictTypeHandler.java +++ b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/DictTypeHandler.java @@ -14,7 +14,7 @@ public class DictTypeHandler extends BaseTypeHandler { private final Class type; - private final Dict[] enums; + private final Dict[] enums; public DictTypeHandler(Class type) { if (type == null) { diff --git a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/LockDictEnum.java b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/LockDictEnum.java index a75c03855..5cfee6a6c 100644 --- a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/LockDictEnum.java +++ b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/LockDictEnum.java @@ -9,7 +9,7 @@ public enum LockDictEnum implements Dict { private int value; - private LockDictEnum(int value){ + private LockDictEnum(int value) { this.value = value; } diff --git a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/StateDictEnum.java b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/StateDictEnum.java index 8ced2e0d1..ee0a5bfa7 100644 --- a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/StateDictEnum.java +++ b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/StateDictEnum.java @@ -9,7 +9,7 @@ public enum StateDictEnum implements Dict { private int value; - private StateDictEnum(int value){ + private StateDictEnum(int value) { this.value = value; } diff --git a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/User.java b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/User.java index 38880ef88..2e57b441e 100644 --- a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/User.java +++ b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/User.java @@ -9,9 +9,9 @@ public class User implements Serializable { private static final long serialVersionUID = 1L; @Id - private Integer id; - private String name; - private LockDictEnum lock; + private Integer id; + private String name; + private LockDictEnum lock; private StateDictEnum state; public Integer getId() { diff --git a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/mybatis-config-defaultenumtypehandler.xml b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/mybatis-config-defaultenumtypehandler.xml index e192aed7d..51ef16c91 100644 --- a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/mybatis-config-defaultenumtypehandler.xml +++ b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/mybatis-config-defaultenumtypehandler.xml @@ -29,7 +29,7 @@ - + @@ -38,9 +38,9 @@ - - - + + + diff --git a/base/src/test/java/tk/mybatis/mapper/generatedvalue/CreateDB.sql b/base/src/test/java/tk/mybatis/mapper/generatedvalue/CreateDB.sql index 6f41c06af..60e93ba6e 100644 --- a/base/src/test/java/tk/mybatis/mapper/generatedvalue/CreateDB.sql +++ b/base/src/test/java/tk/mybatis/mapper/generatedvalue/CreateDB.sql @@ -1,21 +1,26 @@ -SET FOREIGN_KEY_CHECKS=0; +SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for user -- ---------------------------- DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( -`id` int(11) NOT NULL, -`name` varchar(50) DEFAULT NULL, -PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `user` +( + `id` int(11) NOT NULL, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8; -- ---------------------------- -- Table structure for user_auto_increment -- ---------------------------- DROP TABLE IF EXISTS `user_auto_increment`; -CREATE TABLE `user_auto_increment` ( -`id` int(11) NOT NULL AUTO_INCREMENT, -`name` varchar(32) DEFAULT NULL, -PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8; \ No newline at end of file +CREATE TABLE `user_auto_increment` +( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(32) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + AUTO_INCREMENT = 29 + DEFAULT CHARSET = utf8; \ No newline at end of file diff --git a/base/src/test/java/tk/mybatis/mapper/generatedvalue/mybatis-config-keysql-mysql.xml b/base/src/test/java/tk/mybatis/mapper/generatedvalue/mybatis-config-keysql-mysql.xml index 97aeab62b..4e5f76994 100644 --- a/base/src/test/java/tk/mybatis/mapper/generatedvalue/mybatis-config-keysql-mysql.xml +++ b/base/src/test/java/tk/mybatis/mapper/generatedvalue/mybatis-config-keysql-mysql.xml @@ -29,11 +29,12 @@ - + - + @@ -41,10 +42,10 @@ - - - - + + + + diff --git a/base/src/test/java/tk/mybatis/mapper/hsqldb/HsqldbMapper.java b/base/src/test/java/tk/mybatis/mapper/hsqldb/HsqldbMapper.java index bfb36c7a1..6314fdfbb 100644 --- a/base/src/test/java/tk/mybatis/mapper/hsqldb/HsqldbMapper.java +++ b/base/src/test/java/tk/mybatis/mapper/hsqldb/HsqldbMapper.java @@ -45,6 +45,6 @@ public interface HsqldbMapper { * @param limit * @return */ - @SelectProvider(type=HsqldbProvider.class,method = "dynamicSQL") + @SelectProvider(type = HsqldbProvider.class, method = "dynamicSQL") List selectPage(@Param("entity") T object, @Param("offset") int offset, @Param("limit") int limit); } diff --git a/base/src/test/java/tk/mybatis/mapper/hsqldb/HsqldbProvider.java b/base/src/test/java/tk/mybatis/mapper/hsqldb/HsqldbProvider.java index 395dc6d55..7c52ca135 100644 --- a/base/src/test/java/tk/mybatis/mapper/hsqldb/HsqldbProvider.java +++ b/base/src/test/java/tk/mybatis/mapper/hsqldb/HsqldbProvider.java @@ -45,6 +45,7 @@ public HsqldbProvider(Class mapperClass, MapperHelper mapperHelper) { /** * 分页查询 + * * @param ms * @return */ @@ -68,19 +69,19 @@ public SqlNode selectPage(MappedStatement ms) { StaticTextSqlNode columnNode = new StaticTextSqlNode((first ? "" : " AND ") + column.getColumn() + " = #{entity." + column.getProperty() + "} "); if (column.getJavaType().equals(String.class)) { - ifNodes.add(new IfSqlNode(columnNode, "entity."+column.getProperty() + " != null and " + "entity."+column.getProperty() + " != '' ")); + ifNodes.add(new IfSqlNode(columnNode, "entity." + column.getProperty() + " != null and " + "entity." + column.getProperty() + " != '' ")); } else { - ifNodes.add(new IfSqlNode(columnNode, "entity."+column.getProperty() + " != null ")); + ifNodes.add(new IfSqlNode(columnNode, "entity." + column.getProperty() + " != null ")); } first = false; } //增加entity判断 - IfSqlNode ifSqlNode = new IfSqlNode(new MixedSqlNode(ifNodes),"entity!=null"); + IfSqlNode ifSqlNode = new IfSqlNode(new MixedSqlNode(ifNodes), "entity!=null"); //将if添加到 sqlNodes.add(new WhereSqlNode(ms.getConfiguration(), ifSqlNode)); //处理分页 - sqlNodes.add(new IfSqlNode(new StaticTextSqlNode(" LIMIT #{limit}"),"offset==0")); - sqlNodes.add(new IfSqlNode(new StaticTextSqlNode(" LIMIT #{limit} OFFSET #{offset} "),"offset>0")); + sqlNodes.add(new IfSqlNode(new StaticTextSqlNode(" LIMIT #{limit}"), "offset==0")); + sqlNodes.add(new IfSqlNode(new StaticTextSqlNode(" LIMIT #{limit} OFFSET #{offset} "), "offset>0")); return new MixedSqlNode(sqlNodes); } } diff --git a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/CreateDB.sql b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/CreateDB.sql index f0c7d7dc9..05dc9a7eb 100644 --- a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/CreateDB.sql +++ b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/CreateDB.sql @@ -1,11 +1,14 @@ drop table test_timestamp if exists; -create table test_timestamp ( - id integer NOT NULL PRIMARY KEY, - test_date DATE, - test_time TIME, - test_datetime DATETIME -- 和 TIMESTAMP 相同 +create table test_timestamp +( + id integer NOT NULL PRIMARY KEY, + test_date DATE, + test_time TIME, + test_datetime DATETIME -- 和 TIMESTAMP 相同 ); -INSERT INTO test_timestamp (id, test_date, test_time, test_datetime) VALUES (1, DATE '2018-01-01', TIME '12:11:00',TIMESTAMP '2018-01-01 12:00:00'); -INSERT INTO test_timestamp (id, test_date, test_time, test_datetime) VALUES (2, DATE '2018-11-11', TIME '01:59:11',TIMESTAMP '2018-02-12 17:58:12'); \ No newline at end of file +INSERT INTO test_timestamp (id, test_date, test_time, test_datetime) +VALUES (1, DATE '2018-01-01', TIME '12:11:00', TIMESTAMP '2018-01-01 12:00:00'); +INSERT INTO test_timestamp (id, test_date, test_time, test_datetime) +VALUES (2, DATE '2018-11-11', TIME '01:59:11', TIMESTAMP '2018-02-12 17:58:12'); \ No newline at end of file diff --git a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/DateTimeTest.java b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/DateTimeTest.java index 36be073ad..59c27f0f4 100644 --- a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/DateTimeTest.java +++ b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/DateTimeTest.java @@ -24,17 +24,17 @@ protected Reader getSqlFileAsReader() throws IOException { return toReader(DateTimeTest.class.getResource("CreateDB.sql")); } - private String toDate(Date date){ + private String toDate(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(date); } - private String toTime(Date date){ + private String toTime(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); return sdf.format(date); } - private String toDatetime(Date date){ + private String toDatetime(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.format(date); } diff --git a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel2.java b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel2.java index 9aeda543a..a45538f3c 100644 --- a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel2.java +++ b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel2.java @@ -13,9 +13,9 @@ public class TimeModel2 implements Serializable { private static final long serialVersionUID = 1L; @Id - private Integer id; - private Date testDate; - private Date testTime; + private Integer id; + private Date testDate; + private Date testTime; private Timestamp testDatetime; public Integer getId() { diff --git a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel3.java b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel3.java index 3a8a0ba5a..424aec9f2 100644 --- a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel3.java +++ b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel3.java @@ -17,11 +17,11 @@ public class TimeModel3 implements Serializable { @Id private Integer id; @ColumnType(jdbcType = JdbcType.DATE) - private Date testDate; + private Date testDate; @ColumnType(jdbcType = JdbcType.TIME) - private Date testTime; + private Date testTime; @ColumnType(jdbcType = JdbcType.TIMESTAMP) - private Date testDatetime; + private Date testDatetime; public Integer getId() { return id; diff --git a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/mybatis-config-timestamp.xml b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/mybatis-config-timestamp.xml index 7c6af53d8..6a7d56e8d 100644 --- a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/mybatis-config-timestamp.xml +++ b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/mybatis-config-timestamp.xml @@ -30,7 +30,7 @@ - + @@ -38,9 +38,9 @@ - - - + + + diff --git a/base/src/test/java/tk/mybatis/mapper/keysql/CreateDB.sql b/base/src/test/java/tk/mybatis/mapper/keysql/CreateDB.sql index 6f41c06af..60e93ba6e 100644 --- a/base/src/test/java/tk/mybatis/mapper/keysql/CreateDB.sql +++ b/base/src/test/java/tk/mybatis/mapper/keysql/CreateDB.sql @@ -1,21 +1,26 @@ -SET FOREIGN_KEY_CHECKS=0; +SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for user -- ---------------------------- DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( -`id` int(11) NOT NULL, -`name` varchar(50) DEFAULT NULL, -PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `user` +( + `id` int(11) NOT NULL, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8; -- ---------------------------- -- Table structure for user_auto_increment -- ---------------------------- DROP TABLE IF EXISTS `user_auto_increment`; -CREATE TABLE `user_auto_increment` ( -`id` int(11) NOT NULL AUTO_INCREMENT, -`name` varchar(32) DEFAULT NULL, -PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8; \ No newline at end of file +CREATE TABLE `user_auto_increment` +( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(32) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + AUTO_INCREMENT = 29 + DEFAULT CHARSET = utf8; \ No newline at end of file diff --git a/base/src/test/java/tk/mybatis/mapper/keysql/mybatis-config-keysql-mysql.xml b/base/src/test/java/tk/mybatis/mapper/keysql/mybatis-config-keysql-mysql.xml index dc2cba01c..a398d41dd 100644 --- a/base/src/test/java/tk/mybatis/mapper/keysql/mybatis-config-keysql-mysql.xml +++ b/base/src/test/java/tk/mybatis/mapper/keysql/mybatis-config-keysql-mysql.xml @@ -29,11 +29,12 @@ - + - + @@ -41,10 +42,10 @@ - - - - + + + + diff --git a/base/src/test/java/tk/mybatis/mapper/mapper/CachedCountryMapper.java b/base/src/test/java/tk/mybatis/mapper/mapper/CachedCountryMapper.java index 16b19a8ab..eaa18a73b 100644 --- a/base/src/test/java/tk/mybatis/mapper/mapper/CachedCountryMapper.java +++ b/base/src/test/java/tk/mybatis/mapper/mapper/CachedCountryMapper.java @@ -32,6 +32,6 @@ * Created by liuzh on 2014/11/19. */ //@CacheNamespace -public interface CachedCountryMapper extends Mapper,HsqldbMapper { +public interface CachedCountryMapper extends Mapper, HsqldbMapper { int selectCache(int id); } diff --git a/base/src/test/java/tk/mybatis/mapper/model/BaseLogicDelete.java b/base/src/test/java/tk/mybatis/mapper/model/BaseLogicDelete.java index 8b1fe6782..15f2c5c7f 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/BaseLogicDelete.java +++ b/base/src/test/java/tk/mybatis/mapper/model/BaseLogicDelete.java @@ -1,10 +1,11 @@ package tk.mybatis.mapper.model; +import tk.mybatis.mapper.annotation.LogicDelete; + import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import tk.mybatis.mapper.annotation.LogicDelete; public class BaseLogicDelete { diff --git a/base/src/test/java/tk/mybatis/mapper/test/country/TestInsertSelective.java b/base/src/test/java/tk/mybatis/mapper/test/country/TestInsertSelective.java index 8c19b6ca1..fc90c8897 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/country/TestInsertSelective.java +++ b/base/src/test/java/tk/mybatis/mapper/test/country/TestInsertSelective.java @@ -117,7 +117,7 @@ public void testDynamicInsertSelectiveNull() { Assert.assertEquals(1, list.size()); //默认值 Assert.assertNotNull(list.get(0).getCountrycode()); - Assert.assertEquals("HH",list.get(0).getCountrycode()); + Assert.assertEquals("HH", list.get(0).getCountrycode()); //删除插入的数据,以免对其他测试产生影响 Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086)); } finally { diff --git a/base/src/test/java/tk/mybatis/mapper/test/country/TestSelectByPrimaryKey.java b/base/src/test/java/tk/mybatis/mapper/test/country/TestSelectByPrimaryKey.java index 17ecbec1c..671639cf0 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/country/TestSelectByPrimaryKey.java +++ b/base/src/test/java/tk/mybatis/mapper/test/country/TestSelectByPrimaryKey.java @@ -89,7 +89,7 @@ public void testDynamicSelectByPrimaryKeyZero() { try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Assert.assertNull(mapper.selectByPrimaryKey(new Country())); - Assert.assertNull(mapper.selectByPrimaryKey(new HashMap())); + Assert.assertNull(mapper.selectByPrimaryKey(new HashMap())); Assert.assertNull(mapper.selectByPrimaryKey(-10)); Assert.assertNull(mapper.selectByPrimaryKey(0)); Assert.assertNull(mapper.selectByPrimaryKey(1000)); diff --git a/base/src/test/java/tk/mybatis/mapper/test/country/TestUpdateByPrimaryKey.java b/base/src/test/java/tk/mybatis/mapper/test/country/TestUpdateByPrimaryKey.java index a73fef2f9..d55ce67bd 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/country/TestUpdateByPrimaryKey.java +++ b/base/src/test/java/tk/mybatis/mapper/test/country/TestUpdateByPrimaryKey.java @@ -85,7 +85,7 @@ public void testDynamicUpdateByPrimaryKey() { country = mapper.selectByPrimaryKey(174); Assert.assertNotNull(country); Assert.assertEquals(174, (int) country.getId()); - Assert.assertEquals("美国",country.getCountryname()); + Assert.assertEquals("美国", country.getCountryname()); Assert.assertNull(country.getCountrycode()); } finally { sqlSession.close(); @@ -101,7 +101,7 @@ public void testDynamicUpdateByPrimaryKeyNotFoundKeyProperties() { try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); - Assert.assertEquals(0, mapper.updateByPrimaryKey(new Key())); + Assert.assertEquals(0, mapper.updateByPrimaryKey(new Key())); Key key = new Key(); key.setId(174); diff --git a/base/src/test/java/tk/mybatis/mapper/test/country2/TestInsertSelective.java b/base/src/test/java/tk/mybatis/mapper/test/country2/TestInsertSelective.java index af6d133ef..f2f2be33a 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/country2/TestInsertSelective.java +++ b/base/src/test/java/tk/mybatis/mapper/test/country2/TestInsertSelective.java @@ -123,7 +123,7 @@ public void testDynamicInsertSelectiveNull() { Assert.assertEquals(1, list.size()); //默认值 Assert.assertNotNull(list.get(0).getCountrycode()); - Assert.assertEquals("HH",list.get(0).getCountrycode()); + Assert.assertEquals("HH", list.get(0).getCountrycode()); //删除插入的数据,以免对其他测试产生影响 Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086)); } finally { diff --git a/base/src/test/java/tk/mybatis/mapper/test/example/TestExampleBuilder.java b/base/src/test/java/tk/mybatis/mapper/test/example/TestExampleBuilder.java index e868e4310..1e1999335 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/example/TestExampleBuilder.java +++ b/base/src/test/java/tk/mybatis/mapper/test/example/TestExampleBuilder.java @@ -143,10 +143,11 @@ public void testIn() { sqlSession.close(); } } + /* - * @description: 单个where组合查询测试 - * 直接把example的构造放到selectByExample()函数里 - * */ + * @description: 单个where组合查询测试 + * 直接把example的构造放到selectByExample()函数里 + * */ @Test public void testWhereCompound0() { SqlSession sqlSession = MybatisHelper.getSqlSession(); @@ -154,13 +155,13 @@ public void testWhereCompound0() { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); List countries = mapper.selectByExample( Example.builder(Country.class) - .where(Sqls.custom() - .andEqualTo("countryname", "China") - .andEqualTo("id", 35) - .orIn("id", new ArrayList(Arrays.asList(35, 183))) - .orLike("countryname","Ye%") - ) - .build()); + .where(Sqls.custom() + .andEqualTo("countryname", "China") + .andEqualTo("id", 35) + .orIn("id", new ArrayList(Arrays.asList(35, 183))) + .orLike("countryname", "Ye%") + ) + .build()); Country country35 = countries.get(2); Assert.assertEquals(Integer.valueOf(35), country35.getId()); Assert.assertEquals("China", country35.getCountryname()); @@ -191,9 +192,9 @@ public void testWhereCompound1() { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = Example.builder(Country.class) .where(Sqls.custom() - .andBetween("id", 35, 50) - .orLessThan("id", 40) - .orIsNull("countryname") + .andBetween("id", 35, 50) + .orLessThan("id", 40) + .orIsNull("countryname") ) .build(); List countries = mapper.selectByExample(example); @@ -202,9 +203,10 @@ public void testWhereCompound1() { sqlSession.close(); } } + /* - * @description: 多个where连接的查询语句测试 - * */ + * @description: 多个where连接的查询语句测试 + * */ @Test public void testWhereAndWhereCompound() { SqlSession sqlSession = MybatisHelper.getSqlSession(); @@ -212,11 +214,11 @@ public void testWhereAndWhereCompound() { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = Example.builder(Country.class) .where(Sqls.custom() - .andEqualTo("countryname", "China") - .andEqualTo("id", 35) + .andEqualTo("countryname", "China") + .andEqualTo("id", 35) ) .andWhere(Sqls.custom() - .andEqualTo("id", 183) + .andEqualTo("id", 183) ) .build(); List countries = mapper.selectByExample(example); @@ -263,19 +265,19 @@ public void testMultiWhereCompound() { Example example = Example.builder(Country.class) .selectDistinct() .where(Sqls.custom() - .andEqualTo("countryname", "China") - .andEqualTo("id", 35) + .andEqualTo("countryname", "China") + .andEqualTo("id", 35) ) .orWhere(Sqls.custom() - .andBetween("countryname", 'C', 'H') - .andNotLike("countryname", "Co%") + .andBetween("countryname", 'C', 'H') + .andNotLike("countryname", "Co%") ) .andWhere(Sqls.custom() - .andLessThan("id", "100") - .orGreaterThan("id", "55") + .andLessThan("id", "100") + .orGreaterThan("id", "55") ) .orWhere(Sqls.custom() - .andEqualTo("countryname", "Cook Is.") + .andEqualTo("countryname", "Cook Is.") ) .orderByAsc("id", "countryname") .orderByDesc("countrycode") @@ -290,9 +292,9 @@ public void testMultiWhereCompound() { } /* - * @description: 测试order by - * orderBy()默认为Asc(升序),与orderByAsc()一样 - * */ + * @description: 测试order by + * orderBy()默认为Asc(升序),与orderByAsc()一样 + * */ @Test public void testOrderBy() { SqlSession sqlSession = MybatisHelper.getSqlSession(); @@ -303,7 +305,7 @@ public void testOrderBy() { .orderBy("id").orderByAsc("countryname").orderByDesc("countrycode") .build(); List countries = mapper.selectByExample(example); - for (Country country :countries) { + for (Country country : countries) { System.out.println(country.getId() + " " + country.getCountryname() + " " + country.getCountrycode()); } Assert.assertEquals(6, countries.size()); diff --git a/base/src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java b/base/src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java index 774f548c5..cfdcb7e93 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java +++ b/base/src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java @@ -48,13 +48,14 @@ public class TestSelectByExample { @Rule public ExpectedException exception = ExpectedException.none(); + @Test public void testSelectByExample() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); - example.createCriteria().andGreaterThan("id", 100).andLessThan("id",151); + example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151); example.or().andLessThan("id", 41); List countries = mapper.selectByExample(example); //查询总数 @@ -84,7 +85,7 @@ public void testSelectByExampleForUpdate() { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.setForUpdate(true); - example.createCriteria().andGreaterThan("id", 100).andLessThan("id",151); + example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151); example.or().andLessThan("id", 41); List countries = mapper.selectByExample(example); //查询总数 @@ -153,7 +154,7 @@ public void testSelectByExample2() { Example example = new Example(Country.class); example.createCriteria().andLike("countryname", "A%"); example.or().andGreaterThan("id", 100); - example. setDistinct(true); + example.setDistinct(true); List countries = mapper.selectByExample(example); //查询总数 Assert.assertEquals(true, countries.size() > 83); @@ -287,7 +288,7 @@ public void testSelectPropertisCheckCorrect() { Example example = new Example(Country.class); example.selectProperties(new String[]{"countryname"}); example.createCriteria().andEqualTo("id", 35); - List country1= mapper.selectByExample(example); + List country1 = mapper.selectByExample(example); Assert.assertEquals(null, country1.get(0).getId()); Assert.assertEquals("China", country1.get(0).getCountryname()); Assert.assertEquals(null, country1.get(0).getCountrycode()); diff --git a/base/src/test/java/tk/mybatis/mapper/test/example/TestUpdateByExampleSelective.java b/base/src/test/java/tk/mybatis/mapper/test/example/TestUpdateByExampleSelective.java index a3acda231..3cf892aac 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/example/TestUpdateByExampleSelective.java +++ b/base/src/test/java/tk/mybatis/mapper/test/example/TestUpdateByExampleSelective.java @@ -51,7 +51,7 @@ public void testUpdateByExampleSelective() { Assert.assertEquals(83, count); example = new Example(Country.class); - example.createCriteria().andEqualTo("countryname","天朝"); + example.createCriteria().andEqualTo("countryname", "天朝"); count = mapper.selectCountByExample(example); Assert.assertEquals(83, count); } finally { @@ -75,7 +75,7 @@ public void testUpdateByExampleSelective2() { Assert.assertEquals(true, count > 83); example = new Example(Country.class); - example.createCriteria().andEqualTo("countryname","天朝"); + example.createCriteria().andEqualTo("countryname", "天朝"); count = mapper.selectCountByExample(example); Assert.assertEquals(true, count > 83); } finally { diff --git a/base/src/test/java/tk/mybatis/mapper/test/jdbc/TestJDBC.java b/base/src/test/java/tk/mybatis/mapper/test/jdbc/TestJDBC.java index f97448c92..b6671db8a 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/jdbc/TestJDBC.java +++ b/base/src/test/java/tk/mybatis/mapper/test/jdbc/TestJDBC.java @@ -35,7 +35,7 @@ */ public class TestJDBC { -// @Test + // @Test public void testJDBC() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { @@ -52,7 +52,7 @@ public void testJDBC() { } } -// @Test + // @Test public void testJDBC2() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { diff --git a/base/src/test/java/tk/mybatis/mapper/test/logic/TestLogicDelete.java b/base/src/test/java/tk/mybatis/mapper/test/logic/TestLogicDelete.java index b0ced90b8..dc5ff52be 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/logic/TestLogicDelete.java +++ b/base/src/test/java/tk/mybatis/mapper/test/logic/TestLogicDelete.java @@ -60,7 +60,7 @@ public void testLogicDelete() { TbUser tbUser = new TbUser(); tbUser.setUsername("test"); - Assert.assertEquals(2, mapper.select(tbUser).size()); + Assert.assertEquals(2, mapper.select(tbUser).size()); // 物理删除2条已经为逻辑删除状态的数据 Assert.assertEquals(2, mapper.delete(tbUser)); diff --git a/base/src/test/java/tk/mybatis/mapper/test/othres/TestDelimiter.java b/base/src/test/java/tk/mybatis/mapper/test/othres/TestDelimiter.java index 373556146..76885fdae 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/othres/TestDelimiter.java +++ b/base/src/test/java/tk/mybatis/mapper/test/othres/TestDelimiter.java @@ -39,24 +39,24 @@ public class TestDelimiter { public static final Pattern DELIMITER = Pattern.compile("^[`\\[\"]?(.*?)[`\\]\"]?$"); @Test - public void test(){ + public void test() { Matcher matcher = DELIMITER.matcher("normal"); - if(matcher.find()){ + if (matcher.find()) { Assert.assertEquals("normal", matcher.group(1)); } matcher = DELIMITER.matcher("`mysql`"); - if(matcher.find()){ + if (matcher.find()) { Assert.assertEquals("mysql", matcher.group(1)); } matcher = DELIMITER.matcher("[sqlserver]"); - if(matcher.find()){ + if (matcher.find()) { Assert.assertEquals("sqlserver", matcher.group(1)); } matcher = DELIMITER.matcher("\"oracle\""); - if(matcher.find()){ + if (matcher.find()) { Assert.assertEquals("oracle", matcher.group(1)); } } diff --git a/base/src/test/java/tk/mybatis/mapper/test/transientc/TestTransient.java b/base/src/test/java/tk/mybatis/mapper/test/transientc/TestTransient.java index a38b3a913..4e5502a92 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/transientc/TestTransient.java +++ b/base/src/test/java/tk/mybatis/mapper/test/transientc/TestTransient.java @@ -83,7 +83,7 @@ public void testDynamicUpdateByPrimaryKey() { country = mapper.selectByPrimaryKey(174); Assert.assertNotNull(country); Assert.assertEquals(174, (int) country.getId()); - Assert.assertEquals("美国",country.getCountryname()); + Assert.assertEquals("美国", country.getCountryname()); Assert.assertNull(country.getCountrycode()); } finally { sqlSession.close(); diff --git a/base/src/test/java/tk/mybatis/mapper/test/user/TestBasic.java b/base/src/test/java/tk/mybatis/mapper/test/user/TestBasic.java index 7829f05e4..11512605a 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/user/TestBasic.java +++ b/base/src/test/java/tk/mybatis/mapper/test/user/TestBasic.java @@ -58,7 +58,7 @@ public void testInsert() { userInfo.setEmail("abel533@gmail.com"); Collection collection = sqlSession.getConfiguration().getMappedStatements(); for (Object o : collection) { - if(o instanceof MappedStatement){ + if (o instanceof MappedStatement) { MappedStatement ms = (MappedStatement) o; if (ms.getId().contains("UserInfoMapper.insert")) { System.out.println(ms.getId()); @@ -71,7 +71,7 @@ public void testInsert() { Assert.assertNotNull(userInfo.getId()); Assert.assertTrue((int) userInfo.getId() >= 6); - Assert.assertEquals(1,mapper.deleteByPrimaryKey(userInfo)); + Assert.assertEquals(1, mapper.deleteByPrimaryKey(userInfo)); } finally { sqlSession.rollback(); sqlSession.close(); diff --git a/base/src/test/java/tk/mybatis/mapper/test/user/TestMap.java b/base/src/test/java/tk/mybatis/mapper/test/user/TestMap.java index 903f4b06a..a6d876581 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/user/TestMap.java +++ b/base/src/test/java/tk/mybatis/mapper/test/user/TestMap.java @@ -56,9 +56,9 @@ public void testInsert() { Assert.assertEquals(1, mapper.insert(userInfoMap)); Assert.assertNotNull(userInfoMap.getId()); - Assert.assertEquals(6, (int)userInfoMap.getId()); + Assert.assertEquals(6, (int) userInfoMap.getId()); - Assert.assertEquals(1,mapper.deleteByPrimaryKey(userInfoMap)); + Assert.assertEquals(1, mapper.deleteByPrimaryKey(userInfoMap)); } finally { sqlSession.close(); } @@ -124,7 +124,7 @@ public void testUpdateByPrimaryKey() { userInfoMap = mapper.selectByPrimaryKey(userInfoMap); Assert.assertNull(userInfoMap.getUserType()); - Assert.assertEquals("liuzh",userInfoMap.getRealName()); + Assert.assertEquals("liuzh", userInfoMap.getRealName()); } finally { sqlSession.close(); } @@ -147,7 +147,7 @@ public void testUpdateByPrimaryKeySelective() { userInfoMap = mapper.selectByPrimaryKey(1); Assert.assertEquals("1", userInfoMap.getUserType()); - Assert.assertEquals("liuzh",userInfoMap.getRealName()); + Assert.assertEquals("liuzh", userInfoMap.getRealName()); } finally { sqlSession.close(); } diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/Address.java b/base/src/test/java/tk/mybatis/mapper/typehandler/Address.java index e3ddad57f..5307d782f 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/Address.java +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/Address.java @@ -29,10 +29,10 @@ public void setCity(String city) { @Override public String toString() { StringBuilder builder = new StringBuilder(); - if(province != null && province.length() > 0){ + if (province != null && province.length() > 0) { builder.append(province); } - if(city != null && city.length() > 0){ + if (city != null && city.length() > 0) { builder.append("/").append(city); } return builder.toString(); diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/AddressTypeHandler.java b/base/src/test/java/tk/mybatis/mapper/typehandler/AddressTypeHandler.java index 7f1b79f78..8e5af9d3d 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/AddressTypeHandler.java +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/AddressTypeHandler.java @@ -17,16 +17,16 @@ public void setNonNullParameter(PreparedStatement ps, int i, Address parameter, ps.setString(i, parameter.toString()); } - private Address convertToAddress(String addressStr){ - if(addressStr == null || addressStr.length() == 0){ + private Address convertToAddress(String addressStr) { + if (addressStr == null || addressStr.length() == 0) { return null; } String[] strings = addressStr.split("/"); Address address = new Address(); - if(strings.length > 0 && strings[0].length() > 0){ + if (strings.length > 0 && strings[0].length() > 0) { address.setProvince(strings[0]); } - if(strings.length > 1 && strings[1].length() > 0){ + if (strings.length > 1 && strings[1].length() > 0) { address.setCity(strings[1]); } return address; diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/CreateDB.sql b/base/src/test/java/tk/mybatis/mapper/typehandler/CreateDB.sql index 85a261aec..aca7aa30c 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/CreateDB.sql +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/CreateDB.sql @@ -1,11 +1,14 @@ drop table user if exists; -create table user ( - id integer NOT NULL PRIMARY KEY, - name varchar(32), - address varchar(64), - state integer +create table user +( + id integer NOT NULL PRIMARY KEY, + name varchar(32), + address varchar(64), + state integer ); -INSERT INTO user (id, name, address, state) VALUES (1, 'abel533', 'Hebei/Shijiazhuang', 1); -INSERT INTO user (id, name, address, state) VALUES (2, 'isea533', 'Hebei/Handan', 0); \ No newline at end of file +INSERT INTO user (id, name, address, state) +VALUES (1, 'abel533', 'Hebei/Shijiazhuang', 1); +INSERT INTO user (id, name, address, state) +VALUES (2, 'isea533', 'Hebei/Handan', 0); \ No newline at end of file diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/TypeHandlerTest.java b/base/src/test/java/tk/mybatis/mapper/typehandler/TypeHandlerTest.java index 921df4d60..8c41410e1 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/TypeHandlerTest.java +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/TypeHandlerTest.java @@ -13,7 +13,7 @@ /** * @author liuzh */ -public class TypeHandlerTest extends BaseTest{ +public class TypeHandlerTest extends BaseTest { @Override protected Config getConfig() { @@ -33,7 +33,7 @@ protected Reader getSqlFileAsReader() throws IOException { } @Test - public void testSelect(){ + public void testSelect() { SqlSession sqlSession = getSqlSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); @@ -61,7 +61,7 @@ public void testSelect(){ } @Test - public void testInsert(){ + public void testInsert() { SqlSession sqlSession = getSqlSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); @@ -88,7 +88,7 @@ public void testInsert(){ } @Test - public void testUpdate(){ + public void testUpdate() { SqlSession sqlSession = getSqlSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); @@ -113,7 +113,7 @@ public void testUpdate(){ } @Test - public void testDelete(){ + public void testDelete() { SqlSession sqlSession = getSqlSession(); try { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/TypeHandlerTest2.java b/base/src/test/java/tk/mybatis/mapper/typehandler/TypeHandlerTest2.java index 2eeb60a59..895e41a94 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/TypeHandlerTest2.java +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/TypeHandlerTest2.java @@ -13,7 +13,7 @@ /** * @author liuzh */ -public class TypeHandlerTest2 extends BaseTest{ +public class TypeHandlerTest2 extends BaseTest { @Override protected Config getConfig() { @@ -33,7 +33,7 @@ protected Reader getSqlFileAsReader() throws IOException { } @Test - public void testSelect(){ + public void testSelect() { SqlSession sqlSession = getSqlSession(); try { User2Mapper userMapper = sqlSession.getMapper(User2Mapper.class); @@ -61,7 +61,7 @@ public void testSelect(){ } @Test - public void testInsert(){ + public void testInsert() { SqlSession sqlSession = getSqlSession(); try { User2Mapper userMapper = sqlSession.getMapper(User2Mapper.class); @@ -88,7 +88,7 @@ public void testInsert(){ } @Test - public void testUpdate(){ + public void testUpdate() { SqlSession sqlSession = getSqlSession(); try { User2Mapper userMapper = sqlSession.getMapper(User2Mapper.class); @@ -113,7 +113,7 @@ public void testUpdate(){ } @Test - public void testDelete(){ + public void testDelete() { SqlSession sqlSession = getSqlSession(); try { User2Mapper userMapper = sqlSession.getMapper(User2Mapper.class); diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/User2.java b/base/src/test/java/tk/mybatis/mapper/typehandler/User2.java index b6d72631e..fdb6287fd 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/User2.java +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/User2.java @@ -12,10 +12,10 @@ public class User2 implements Serializable { private static final long serialVersionUID = 1L; @Id - private Integer id; - private String name; + private Integer id; + private String name; @Column - private Address address; + private Address address; private StateEnum state; public Address getAddress() { diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/mybatis-config-typehandler.xml b/base/src/test/java/tk/mybatis/mapper/typehandler/mybatis-config-typehandler.xml index 15e2ceafb..8ed23fc9c 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/mybatis-config-typehandler.xml +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/mybatis-config-typehandler.xml @@ -29,11 +29,12 @@ - + - + @@ -41,9 +42,9 @@ - - - + + + diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/mybatis-config-typehandler2.xml b/base/src/test/java/tk/mybatis/mapper/typehandler/mybatis-config-typehandler2.xml index 4d187564d..1bd492506 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/mybatis-config-typehandler2.xml +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/mybatis-config-typehandler2.xml @@ -29,11 +29,12 @@ - + - + @@ -42,9 +43,9 @@ - - - + + + diff --git a/base/src/test/java/tk/mybatis/mapper/version/CreateDB.sql b/base/src/test/java/tk/mybatis/mapper/version/CreateDB.sql index 40aa914a2..741f79e25 100644 --- a/base/src/test/java/tk/mybatis/mapper/version/CreateDB.sql +++ b/base/src/test/java/tk/mybatis/mapper/version/CreateDB.sql @@ -1,19 +1,23 @@ drop table user_timestamp if exists; -CREATE TABLE user_timestamp ( -id int NOT NULL, -join_date TIMESTAMP DEFAULT NULL, -PRIMARY KEY (id) +CREATE TABLE user_timestamp +( + id int NOT NULL, + join_date TIMESTAMP DEFAULT NULL, + PRIMARY KEY (id) ); -insert into user_timestamp values(999, TIMESTAMP '2019-01-01 01:01:11'); +insert into user_timestamp +values (999, TIMESTAMP '2019-01-01 01:01:11'); drop table user_int if exists; -CREATE TABLE user_int ( -id int NOT NULL, -age int DEFAULT NULL, -PRIMARY KEY (id) +CREATE TABLE user_int +( + id int NOT NULL, + age int DEFAULT NULL, + PRIMARY KEY (id) ); -insert into user_int values(999, 30); \ No newline at end of file +insert into user_int +values (999, 30); \ No newline at end of file diff --git a/base/src/test/java/tk/mybatis/mapper/version/UserInt.java b/base/src/test/java/tk/mybatis/mapper/version/UserInt.java index 86ed5a608..6ab7261bc 100644 --- a/base/src/test/java/tk/mybatis/mapper/version/UserInt.java +++ b/base/src/test/java/tk/mybatis/mapper/version/UserInt.java @@ -4,7 +4,6 @@ import javax.persistence.Id; import javax.persistence.Table; -import java.sql.Timestamp; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/version/VersionTest.java b/base/src/test/java/tk/mybatis/mapper/version/VersionTest.java index d99d282b9..757386855 100644 --- a/base/src/test/java/tk/mybatis/mapper/version/VersionTest.java +++ b/base/src/test/java/tk/mybatis/mapper/version/VersionTest.java @@ -3,7 +3,6 @@ import org.apache.ibatis.session.SqlSession; import org.junit.Test; import tk.mybatis.mapper.base.BaseTest; -import tk.mybatis.mapper.entity.Example; import java.io.IOException; import java.io.Reader; diff --git a/base/src/test/java/tk/mybatis/mapper/version/mybatis-config-version.xml b/base/src/test/java/tk/mybatis/mapper/version/mybatis-config-version.xml index 9e04e4da2..32b50f1a3 100644 --- a/base/src/test/java/tk/mybatis/mapper/version/mybatis-config-version.xml +++ b/base/src/test/java/tk/mybatis/mapper/version/mybatis-config-version.xml @@ -29,11 +29,12 @@ - + - + @@ -41,9 +42,9 @@ - - - + + + diff --git a/base/src/test/resources/CachedCountryMapper.xml b/base/src/test/resources/CachedCountryMapper.xml index 3babe808e..4d24dbbca 100644 --- a/base/src/test/resources/CachedCountryMapper.xml +++ b/base/src/test/resources/CachedCountryMapper.xml @@ -30,6 +30,8 @@ diff --git a/base/src/test/resources/CreateDB.sql b/base/src/test/resources/CreateDB.sql index 1f13e9a0a..b7eb2ef1e 100644 --- a/base/src/test/resources/CreateDB.sql +++ b/base/src/test/resources/CreateDB.sql @@ -1,296 +1,517 @@ drop table country if exists; -create table country ( - id integer NOT NULL PRIMARY KEY, - countryname varchar(32), - countrycode VARCHAR(2) DEFAULT 'HH', - version INTEGER DEFAULT 1 NOT NULL +create table country +( + id integer NOT NULL PRIMARY KEY, + countryname varchar(32), + countrycode VARCHAR(2) DEFAULT 'HH', + version INTEGER DEFAULT 1 NOT NULL ); -create table country2 ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, - countryname varchar(32), - countrycode varchar(2) DEFAULT 'HH' +create table country2 +( + id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, + countryname varchar(32), + countrycode varchar(2) DEFAULT 'HH' ); -create table country_t ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, - countryname varchar(32) +create table country_t +( + id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, + countryname varchar(32) ); -create table country_jdbc ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, - countryname varchar(128), - countrycode varchar(2) +create table country_jdbc +( + id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, + countryname varchar(128), + countrycode varchar(2) ); -create table country_i ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, - countryname varchar(128), - countrycode varchar(2) DEFAULT 'HH' +create table country_i +( + id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, + countryname varchar(128), + countrycode varchar(2) DEFAULT 'HH' ); --用户信息表 -create table user_info ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, - username varchar(32) NOT NULL, - password varchar(32) DEFAULT '12345678', - usertype varchar(2), - enabled integer, - realname varchar(50), - qq varchar(12), - email varchar(100), - address varchar(200), - tel varchar(30) +create table user_info +( + id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, + username varchar(32) NOT NULL, + password varchar(32) DEFAULT '12345678', + usertype varchar(2), + enabled integer, + realname varchar(50), + qq varchar(12), + email varchar(100), + address varchar(200), + tel varchar(30) ); --用户信息表 -create table user_info_map ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, - user_name varchar(32) NOT NULL, - password varchar(32) DEFAULT '12345678', - user_type varchar(2), - real_name varchar(50) +create table user_info_map +( + id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, + user_name varchar(32) NOT NULL, + password varchar(32) DEFAULT '12345678', + user_type varchar(2), + real_name varchar(50) ); -insert into user_info (id,username,password,usertype) values (1,'test1','12345678','1'); -insert into user_info (id,username,password,usertype) values (2,'test2','aaaa','2'); -insert into user_info (id,username,password,usertype) values (3,'test3','bbbb','1'); -insert into user_info (id,username,password,usertype) values (4,'test4','cccc','2'); -insert into user_info (id,username,password,usertype) values (5,'test5','dddd','1'); +insert into user_info (id, username, password, usertype) +values (1, 'test1', '12345678', '1'); +insert into user_info (id, username, password, usertype) +values (2, 'test2', 'aaaa', '2'); +insert into user_info (id, username, password, usertype) +values (3, 'test3', 'bbbb', '1'); +insert into user_info (id, username, password, usertype) +values (4, 'test4', 'cccc', '2'); +insert into user_info (id, username, password, usertype) +values (5, 'test5', 'dddd', '1'); -insert into user_info_map (id,user_name,password,user_type) values (1,'test1','12345678','1'); -insert into user_info_map (id,user_name,password,user_type) values (2,'test2','aaaa','2'); -insert into user_info_map (id,user_name,password,user_type) values (3,'test3','bbbb','1'); -insert into user_info_map (id,user_name,password,user_type) values (4,'test4','cccc','2'); -insert into user_info_map (id,user_name,password,user_type) values (5,'test5','dddd','1'); +insert into user_info_map (id, user_name, password, user_type) +values (1, 'test1', '12345678', '1'); +insert into user_info_map (id, user_name, password, user_type) +values (2, 'test2', 'aaaa', '2'); +insert into user_info_map (id, user_name, password, user_type) +values (3, 'test3', 'bbbb', '1'); +insert into user_info_map (id, user_name, password, user_type) +values (4, 'test4', 'cccc', '2'); +insert into user_info_map (id, user_name, password, user_type) +values (5, 'test5', 'dddd', '1'); --用户登录表,logid和username联合主键 -create table user_login ( - logid integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL, - username varchar(32) NOT NULL, - logindate DATETIME, - loginip varchar(16), - PRIMARY KEY (logid,username) +create table user_login +( + logid integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL, + username varchar(32) NOT NULL, + logindate DATETIME, + loginip varchar(16), + PRIMARY KEY (logid, username) ); -insert into user_login (logid,username,logindate,loginip) values (1,'test1','2014-10-11 12:00:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (2,'test1','2014-10-21 12:00:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (3,'test1','2014-10-21 14:00:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (4,'test1','2014-11-21 11:20:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (5,'test1','2014-11-21 13:00:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (6,'test2','2014-11-21 12:00:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (7,'test2','2014-11-21 12:00:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (8,'test3','2014-11-21 12:00:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (9,'test4','2014-11-21 12:00:00','192.168.1.123'); -insert into user_login (logid,username,logindate,loginip) values (10,'test5','2014-11-21 12:00:00','192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (1, 'test1', '2014-10-11 12:00:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (2, 'test1', '2014-10-21 12:00:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (3, 'test1', '2014-10-21 14:00:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (4, 'test1', '2014-11-21 11:20:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (5, 'test1', '2014-11-21 13:00:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (6, 'test2', '2014-11-21 12:00:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (7, 'test2', '2014-11-21 12:00:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (8, 'test3', '2014-11-21 12:00:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (9, 'test4', '2014-11-21 12:00:00', '192.168.1.123'); +insert into user_login (logid, username, logindate, loginip) +values (10, 'test5', '2014-11-21 12:00:00', '192.168.1.123'); -INSERT INTO country (id, countryname, countrycode, version) VALUES (1, 'Angola', 'AO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (2, 'Afghanistan', 'AF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (3, 'Albania', 'AL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (4, 'Algeria', 'DZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (5, 'Andorra', 'AD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (6, 'Anguilla', 'AI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (7, 'Antigua and Barbuda', 'AG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (8, 'Argentina', 'AR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (9, 'Armenia', 'AM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (10, 'Australia', 'AU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (11, 'Austria', 'AT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (12, 'Azerbaijan', 'AZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (13, 'Bahamas', 'BS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (14, 'Bahrain', 'BH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (15, 'Bangladesh', 'BD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (16, 'Barbados', 'BB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (17, 'Belarus', 'BY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (18, 'Belgium', 'BE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (19, 'Belize', 'BZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (20, 'Benin', 'BJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (21, 'Bermuda Is.', 'BM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (22, 'Bolivia', 'BO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (23, 'Botswana', 'BW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (24, 'Brazil', 'BR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (25, 'Brunei', 'BN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (26, 'Bulgaria', 'BG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (27, 'Burkina-faso', 'BF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (28, 'Burma', 'MM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (29, 'Burundi', 'BI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (30, 'Cameroon', 'CM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (31, 'Canada', 'CA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (32, 'Central African Republic', 'CF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (33, 'Chad', 'TD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (34, 'Chile', 'CL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (35, 'China', 'CN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (36, 'Colombia', 'CO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (37, 'Congo', 'CG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (38, 'Cook Is.', 'CK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (39, 'Costa Rica', 'CR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (40, 'Cuba', 'CU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (41, 'Cyprus', 'CY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (42, 'Czech Republic', 'CZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (43, 'Denmark', 'DK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (44, 'Djibouti', 'DJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (45, 'Dominica Rep.', 'DO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (46, 'Ecuador', 'EC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (47, 'Egypt', 'EG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (48, 'EI Salvador', 'SV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (49, 'Estonia', 'EE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (50, 'Ethiopia', 'ET', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (51, 'Fiji', 'FJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (52, 'Finland', 'FI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (53, 'France', 'FR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (54, 'French Guiana', 'GF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (55, 'Gabon', 'GA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (56, 'Gambia', 'GM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (57, 'Georgia', 'GE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (58, 'Germany', 'DE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (59, 'Ghana', 'GH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (60, 'Gibraltar', 'GI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (61, 'Greece', 'GR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (62, 'Grenada', 'GD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (63, 'Guam', 'GU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (64, 'Guatemala', 'GT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (65, 'Guinea', 'GN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (66, 'Guyana', 'GY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (67, 'Haiti', 'HT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (68, 'Honduras', 'HN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (69, 'Hongkong', 'HK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (70, 'Hungary', 'HU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (71, 'Iceland', 'IS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (72, 'India', 'IN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (73, 'Indonesia', 'ID', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (74, 'Iran', 'IR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (75, 'Iraq', 'IQ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (76, 'Ireland', 'IE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (77, 'Israel', 'IL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (78, 'Italy', 'IT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (79, 'Jamaica', 'JM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (80, 'Japan', 'JP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (81, 'Jordan', 'JO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (83, 'Kazakstan', 'KZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (84, 'Kenya', 'KE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (85, 'Korea', 'KR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (86, 'Kuwait', 'KW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (87, 'Kyrgyzstan', 'KG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (88, 'Laos', 'LA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (89, 'Latvia', 'LV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (90, 'Lebanon', 'LB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (91, 'Lesotho', 'LS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (92, 'Liberia', 'LR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (93, 'Libya', 'LY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (94, 'Liechtenstein', 'LI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (95, 'Lithuania', 'LT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (96, 'Luxembourg', 'LU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (97, 'Macao', 'MO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (98, 'Madagascar', 'MG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (99, 'Malawi', 'MW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (100, 'Malaysia', 'MY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (101, 'Maldives', 'MV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (102, 'Mali', 'ML', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (103, 'Malta', 'MT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (104, 'Mauritius', 'MU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (105, 'Mexico', 'MX', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (106, 'Moldova, Republic of', 'MD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (107, 'Monaco', 'MC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (108, 'Mongolia', 'MN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (109, 'Montserrat Is', 'MS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (110, 'Morocco', 'MA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (111, 'Mozambique', 'MZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (112, 'Namibia', 'NA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (113, 'Nauru', 'NR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (114, 'Nepal', 'NP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (115, 'Netherlands', 'NL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (116, 'New Zealand', 'NZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (117, 'Nicaragua', 'NI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (118, 'Niger', 'NE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (119, 'Nigeria', 'NG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (120, 'North Korea', 'KP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (121, 'Norway', 'NO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (122, 'Oman', 'OM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (123, 'Pakistan', 'PK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (124, 'Panama', 'PA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (125, 'Papua New Cuinea', 'PG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (126, 'Paraguay', 'PY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (127, 'Peru', 'PE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (128, 'Philippines', 'PH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (129, 'Poland', 'PL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (130, 'French Polynesia', 'PF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (131, 'Portugal', 'PT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (132, 'Puerto Rico', 'PR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (133, 'Qatar', 'QA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (134, 'Romania', 'RO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (135, 'Russia', 'RU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (136, 'Saint Lueia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (137, 'Saint Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (138, 'San Marino', 'SM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (139, 'Sao Tome and Principe', 'ST', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (140, 'Saudi Arabia', 'SA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (141, 'Senegal', 'SN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (142, 'Seychelles', 'SC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (143, 'Sierra Leone', 'SL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (144, 'Singapore', 'SG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (145, 'Slovakia', 'SK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (146, 'Slovenia', 'SI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (147, 'Solomon Is', 'SB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (148, 'Somali', 'SO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (149, 'South Africa', 'ZA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (150, 'Spain', 'ES', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (151, 'Sri Lanka', 'LK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (152, 'St.Lucia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (153, 'St.Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (154, 'Sudan', 'SD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (155, 'Suriname', 'SR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (156, 'Swaziland', 'SZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (157, 'Sweden', 'SE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (158, 'Switzerland', 'CH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (159, 'Syria', 'SY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (160, 'Taiwan', 'TW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (161, 'Tajikstan', 'TJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (162, 'Tanzania', 'TZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (163, 'Thailand', 'TH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (164, 'Togo', 'TG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (165, 'Tonga', 'TO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (166, 'Trinidad and Tobago', 'TT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (167, 'Tunisia', 'TN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (168, 'Turkey', 'TR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (169, 'Turkmenistan', 'TM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (170, 'Uganda', 'UG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (171, 'Ukraine', 'UA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (172, 'United Arab Emirates', 'AE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (173, 'United Kiongdom', 'GB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (174, 'United States of America', 'US', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (175, 'Uruguay', 'UY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (176, 'Uzbekistan', 'UZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (177, 'Venezuela', 'VE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (178, 'Vietnam', 'VN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (179, 'Yemen', 'YE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (180, 'Yugoslavia', 'YU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (181, 'Zimbabwe', 'ZW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (182, 'Zaire', 'ZR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (183, 'Zambia', 'ZM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (1, 'Angola', 'AO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (2, 'Afghanistan', 'AF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (3, 'Albania', 'AL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (4, 'Algeria', 'DZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (5, 'Andorra', 'AD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (6, 'Anguilla', 'AI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (7, 'Antigua and Barbuda', 'AG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (8, 'Argentina', 'AR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (9, 'Armenia', 'AM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (10, 'Australia', 'AU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (11, 'Austria', 'AT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (12, 'Azerbaijan', 'AZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (13, 'Bahamas', 'BS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (14, 'Bahrain', 'BH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (15, 'Bangladesh', 'BD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (16, 'Barbados', 'BB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (17, 'Belarus', 'BY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (18, 'Belgium', 'BE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (19, 'Belize', 'BZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (20, 'Benin', 'BJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (21, 'Bermuda Is.', 'BM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (22, 'Bolivia', 'BO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (23, 'Botswana', 'BW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (24, 'Brazil', 'BR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (25, 'Brunei', 'BN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (26, 'Bulgaria', 'BG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (27, 'Burkina-faso', 'BF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (28, 'Burma', 'MM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (29, 'Burundi', 'BI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (30, 'Cameroon', 'CM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (31, 'Canada', 'CA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (32, 'Central African Republic', 'CF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (33, 'Chad', 'TD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (34, 'Chile', 'CL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (35, 'China', 'CN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (36, 'Colombia', 'CO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (37, 'Congo', 'CG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (38, 'Cook Is.', 'CK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (39, 'Costa Rica', 'CR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (40, 'Cuba', 'CU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (41, 'Cyprus', 'CY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (42, 'Czech Republic', 'CZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (43, 'Denmark', 'DK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (44, 'Djibouti', 'DJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (45, 'Dominica Rep.', 'DO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (46, 'Ecuador', 'EC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (47, 'Egypt', 'EG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (48, 'EI Salvador', 'SV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (49, 'Estonia', 'EE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (50, 'Ethiopia', 'ET', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (51, 'Fiji', 'FJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (52, 'Finland', 'FI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (53, 'France', 'FR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (54, 'French Guiana', 'GF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (55, 'Gabon', 'GA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (56, 'Gambia', 'GM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (57, 'Georgia', 'GE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (58, 'Germany', 'DE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (59, 'Ghana', 'GH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (60, 'Gibraltar', 'GI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (61, 'Greece', 'GR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (62, 'Grenada', 'GD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (63, 'Guam', 'GU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (64, 'Guatemala', 'GT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (65, 'Guinea', 'GN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (66, 'Guyana', 'GY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (67, 'Haiti', 'HT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (68, 'Honduras', 'HN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (69, 'Hongkong', 'HK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (70, 'Hungary', 'HU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (71, 'Iceland', 'IS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (72, 'India', 'IN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (73, 'Indonesia', 'ID', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (74, 'Iran', 'IR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (75, 'Iraq', 'IQ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (76, 'Ireland', 'IE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (77, 'Israel', 'IL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (78, 'Italy', 'IT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (79, 'Jamaica', 'JM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (80, 'Japan', 'JP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (81, 'Jordan', 'JO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (83, 'Kazakstan', 'KZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (84, 'Kenya', 'KE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (85, 'Korea', 'KR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (86, 'Kuwait', 'KW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (87, 'Kyrgyzstan', 'KG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (88, 'Laos', 'LA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (89, 'Latvia', 'LV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (90, 'Lebanon', 'LB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (91, 'Lesotho', 'LS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (92, 'Liberia', 'LR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (93, 'Libya', 'LY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (94, 'Liechtenstein', 'LI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (95, 'Lithuania', 'LT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (96, 'Luxembourg', 'LU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (97, 'Macao', 'MO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (98, 'Madagascar', 'MG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (99, 'Malawi', 'MW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (100, 'Malaysia', 'MY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (101, 'Maldives', 'MV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (102, 'Mali', 'ML', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (103, 'Malta', 'MT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (104, 'Mauritius', 'MU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (105, 'Mexico', 'MX', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (106, 'Moldova, Republic of', 'MD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (107, 'Monaco', 'MC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (108, 'Mongolia', 'MN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (109, 'Montserrat Is', 'MS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (110, 'Morocco', 'MA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (111, 'Mozambique', 'MZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (112, 'Namibia', 'NA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (113, 'Nauru', 'NR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (114, 'Nepal', 'NP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (115, 'Netherlands', 'NL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (116, 'New Zealand', 'NZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (117, 'Nicaragua', 'NI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (118, 'Niger', 'NE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (119, 'Nigeria', 'NG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (120, 'North Korea', 'KP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (121, 'Norway', 'NO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (122, 'Oman', 'OM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (123, 'Pakistan', 'PK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (124, 'Panama', 'PA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (125, 'Papua New Cuinea', 'PG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (126, 'Paraguay', 'PY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (127, 'Peru', 'PE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (128, 'Philippines', 'PH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (129, 'Poland', 'PL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (130, 'French Polynesia', 'PF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (131, 'Portugal', 'PT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (132, 'Puerto Rico', 'PR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (133, 'Qatar', 'QA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (134, 'Romania', 'RO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (135, 'Russia', 'RU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (136, 'Saint Lueia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (137, 'Saint Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (138, 'San Marino', 'SM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (139, 'Sao Tome and Principe', 'ST', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (140, 'Saudi Arabia', 'SA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (141, 'Senegal', 'SN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (142, 'Seychelles', 'SC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (143, 'Sierra Leone', 'SL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (144, 'Singapore', 'SG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (145, 'Slovakia', 'SK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (146, 'Slovenia', 'SI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (147, 'Solomon Is', 'SB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (148, 'Somali', 'SO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (149, 'South Africa', 'ZA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (150, 'Spain', 'ES', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (151, 'Sri Lanka', 'LK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (152, 'St.Lucia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (153, 'St.Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (154, 'Sudan', 'SD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (155, 'Suriname', 'SR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (156, 'Swaziland', 'SZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (157, 'Sweden', 'SE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (158, 'Switzerland', 'CH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (159, 'Syria', 'SY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (160, 'Taiwan', 'TW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (161, 'Tajikstan', 'TJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (162, 'Tanzania', 'TZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (163, 'Thailand', 'TH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (164, 'Togo', 'TG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (165, 'Tonga', 'TO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (166, 'Trinidad and Tobago', 'TT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (167, 'Tunisia', 'TN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (168, 'Turkey', 'TR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (169, 'Turkmenistan', 'TM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (170, 'Uganda', 'UG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (171, 'Ukraine', 'UA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (172, 'United Arab Emirates', 'AE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (173, 'United Kiongdom', 'GB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (174, 'United States of America', 'US', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (175, 'Uruguay', 'UY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (176, 'Uzbekistan', 'UZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (177, 'Venezuela', 'VE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (178, 'Vietnam', 'VN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (179, 'Yemen', 'YE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (180, 'Yugoslavia', 'YU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (181, 'Zimbabwe', 'ZW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (182, 'Zaire', 'ZR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (183, 'Zambia', 'ZM', 1); - -insert into country_t (id, countryname) values(174,'United States of America'); +insert into country_t (id, countryname) +values (174, 'United States of America'); --用户信息表 -create table tb_user ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, - username varchar(32) NOT NULL, - password varchar(32) DEFAULT '12345678', - is_valid integer +create table tb_user +( + id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, + username varchar(32) NOT NULL, + password varchar(32) DEFAULT '12345678', + is_valid integer ); -insert into tb_user (id,username,password,is_valid) values (1,'test1','12345678',1); -insert into tb_user (id,username,password,is_valid) values (2,'test2','aaaa',1); -insert into tb_user (id,username,password,is_valid) values (3,'test3','bbbb',1); -insert into tb_user (id,username,password,is_valid) values (4,'test4','cccc',1); -insert into tb_user (id,username,password,is_valid) values (5,'test5','dddd',0); -insert into tb_user (id,username,password,is_valid) values (6,'test6','eeee',0); -insert into tb_user (id,username,password,is_valid) values (7,'test7','ffff',0); -insert into tb_user (id,username,password,is_valid) values (8,'test','gggg',1); -insert into tb_user (id,username,password,is_valid) values (9,'test','gggg',0); \ No newline at end of file +insert into tb_user (id, username, password, is_valid) +values (1, 'test1', '12345678', 1); +insert into tb_user (id, username, password, is_valid) +values (2, 'test2', 'aaaa', 1); +insert into tb_user (id, username, password, is_valid) +values (3, 'test3', 'bbbb', 1); +insert into tb_user (id, username, password, is_valid) +values (4, 'test4', 'cccc', 1); +insert into tb_user (id, username, password, is_valid) +values (5, 'test5', 'dddd', 0); +insert into tb_user (id, username, password, is_valid) +values (6, 'test6', 'eeee', 0); +insert into tb_user (id, username, password, is_valid) +values (7, 'test7', 'ffff', 0); +insert into tb_user (id, username, password, is_valid) +values (8, 'test', 'gggg', 1); +insert into tb_user (id, username, password, is_valid) +values (9, 'test', 'gggg', 0); \ No newline at end of file diff --git a/base/src/test/resources/log4j.properties b/base/src/test/resources/log4j.properties deleted file mode 100644 index b56b8a94e..000000000 --- a/base/src/test/resources/log4j.properties +++ /dev/null @@ -1,35 +0,0 @@ -# -# The MIT License (MIT) -# -# Copyright (c) 2014-2017 abel533@gmail.com -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -log4j.rootLogger=INFO, stdout - -log4j.logger.tk.mybatis.mapper=DEBUG -log4j.logger.org.apache.ibatis=DEBUG - -log4j.logger.tk.mybatis.mapper.common = TRACE - -### Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n \ No newline at end of file diff --git a/base/src/test/resources/logback.xml b/base/src/test/resources/logback.xml new file mode 100644 index 000000000..3b71bf41f --- /dev/null +++ b/base/src/test/resources/logback.xml @@ -0,0 +1,10 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + \ No newline at end of file diff --git a/base/src/test/resources/mybatis-java.xml b/base/src/test/resources/mybatis-java.xml index 34f51f438..8f028a361 100644 --- a/base/src/test/resources/mybatis-java.xml +++ b/base/src/test/resources/mybatis-java.xml @@ -32,7 +32,7 @@ - + @@ -49,9 +49,9 @@ --> - - - + + + @@ -131,7 +138,8 @@ Country代码: 最新版本 ``` -具体用法可以参考:[MyBatis-Spring-Boot](https://github.com/abel533/MyBatis-Spring-Boot) + +具体用法可以参考:[MyBatis-Spring-Boot](https://github.com/abel533/MyBatis-Spring-Boot) ## 引入 Jar 包,下载地址: @@ -145,7 +153,7 @@ http://repo1.maven.org/maven2/javax/persistence/persistence-api/1.0/ ## [更新日志](http://git.oschina.net/free/Mapper/blob/master/wiki/Changelog.md) -##作者信息 +## 作者信息 MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) diff --git a/core/pom.xml b/core/pom.xml index 19c67cfee..4d836f009 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.1 + 4.2.2-SNAPSHOT mapper-core jar @@ -41,7 +41,7 @@ javax.persistence - persistence-api + javax.persistence-api diff --git a/core/src/main/java/tk/mybatis/mapper/annotation/Order.java b/core/src/main/java/tk/mybatis/mapper/annotation/Order.java index 6bf7afeda..bd85d916c 100644 --- a/core/src/main/java/tk/mybatis/mapper/annotation/Order.java +++ b/core/src/main/java/tk/mybatis/mapper/annotation/Order.java @@ -15,12 +15,14 @@ public @interface Order { /** * 升降序 + * * @return */ String value() default "ASC"; /** * 优先级, 值小的优先 + * * @return */ int priority() default 1; diff --git a/core/src/main/java/tk/mybatis/mapper/code/IdentityDialect.java b/core/src/main/java/tk/mybatis/mapper/code/IdentityDialect.java index 91a38e9a1..5abb60380 100644 --- a/core/src/main/java/tk/mybatis/mapper/code/IdentityDialect.java +++ b/core/src/main/java/tk/mybatis/mapper/code/IdentityDialect.java @@ -66,7 +66,7 @@ public static IdentityDialect getDatabaseDialect(String database) { returnValue = DB2_MF; } else if ("Informix".equalsIgnoreCase(database)) { returnValue = INFORMIX; - } else if("".equals(database)){ + } else if ("".equals(database)) { return DEFAULT; } return returnValue; diff --git a/core/src/main/java/tk/mybatis/mapper/entity/Config.java b/core/src/main/java/tk/mybatis/mapper/entity/Config.java index 62c8891a1..dbf11dbf1 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/Config.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/Config.java @@ -44,16 +44,16 @@ public class Config { public static final String PREFIX = "mapper"; private List mappers = new ArrayList(); - private String IDENTITY; + private String IDENTITY; private boolean BEFORE; - private String seqFormat; - private String catalog; - private String schema; + private String seqFormat; + private String catalog; + private String schema; //校验调用Example方法时,Example(entityClass)和Mapper是否一致 private boolean checkExampleEntityClass; //使用简单类型 //3.5.0 后默认值改为 true - private boolean useSimpleType = true; + private boolean useSimpleType = true; /** * @since 3.5.0 */ diff --git a/core/src/main/java/tk/mybatis/mapper/entity/EntityField.java b/core/src/main/java/tk/mybatis/mapper/entity/EntityField.java index 0e5981bdc..e899df829 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/EntityField.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/EntityField.java @@ -128,7 +128,7 @@ public Object getValue(Object object) throws IllegalAccessException, InvocationT if (getter != null) { result = getter.invoke(object); } else if (field != null) { - if(!field.isAccessible()){ + if (!field.isAccessible()) { field.setAccessible(true); } result = field.get(object); diff --git a/core/src/main/java/tk/mybatis/mapper/entity/EntityTable.java b/core/src/main/java/tk/mybatis/mapper/entity/EntityTable.java index bb83495b8..6be558ddf 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/EntityTable.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/EntityTable.java @@ -87,7 +87,7 @@ public ResultMap getResultMap(Configuration configuration) { String column = entityColumn.getColumn(); //去掉可能存在的分隔符 Matcher matcher = DELIMITER.matcher(column); - if(matcher.find()){ + if (matcher.find()) { column = matcher.group(1); } ResultMapping.Builder builder = new ResultMapping.Builder(configuration, entityColumn.getProperty(), column, entityColumn.getJavaType()); @@ -96,7 +96,7 @@ public ResultMap getResultMap(Configuration configuration) { } if (entityColumn.getTypeHandler() != null) { try { - builder.typeHandler(getInstance(entityColumn.getJavaType(),entityColumn.getTypeHandler())); + builder.typeHandler(getInstance(entityColumn.getJavaType(), entityColumn.getTypeHandler())); } catch (Exception e) { throw new MapperException(e); } @@ -125,6 +125,7 @@ public void initPropertyMap() { /** * 实例化TypeHandler + * * @param javaTypeClass * @param typeHandlerClass * @return @@ -132,22 +133,22 @@ public void initPropertyMap() { @SuppressWarnings("unchecked") public TypeHandler getInstance(Class javaTypeClass, Class typeHandlerClass) { if (javaTypeClass != null) { - try { - Constructor c = typeHandlerClass.getConstructor(Class.class); - return (TypeHandler) c.newInstance(javaTypeClass); - } catch (NoSuchMethodException ignored) { - // ignored - } catch (Exception e) { - throw new TypeException("Failed invoking constructor for handler " + typeHandlerClass, e); - } + try { + Constructor c = typeHandlerClass.getConstructor(Class.class); + return (TypeHandler) c.newInstance(javaTypeClass); + } catch (NoSuchMethodException ignored) { + // ignored + } catch (Exception e) { + throw new TypeException("Failed invoking constructor for handler " + typeHandlerClass, e); + } } try { - Constructor c = typeHandlerClass.getConstructor(); - return (TypeHandler) c.newInstance(); + Constructor c = typeHandlerClass.getConstructor(); + return (TypeHandler) c.newInstance(); } catch (Exception e) { - throw new TypeException("Unable to find a usable constructor for " + typeHandlerClass, e); + throw new TypeException("Unable to find a usable constructor for " + typeHandlerClass, e); } - } + } public String getBaseSelect() { return baseSelect; diff --git a/core/src/main/java/tk/mybatis/mapper/entity/Example.java b/core/src/main/java/tk/mybatis/mapper/entity/Example.java index 1e08e0cd8..982464db3 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/Example.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/Example.java @@ -61,11 +61,11 @@ public class Example implements IDynamicTableName { protected Class entityClass; - protected EntityTable table; + protected EntityTable table; //属性和列对应 protected Map propertyMap; //动态表名 - protected String tableName; + protected String tableName; protected OrderBy ORDERBY; @@ -228,8 +228,8 @@ public Map getPropertyMap() { public static class OrderBy { //属性和列对应 protected Map propertyMap; - private Example example; - private Boolean isProperty; + private Example example; + private Boolean isProperty; public OrderBy(Example example, Map propertyMap) { this.example = example; @@ -280,13 +280,13 @@ public OrderBy asc() { } protected abstract static class GeneratedCriteria { - protected List criteria; + protected List criteria; //字段是否必须存在 - protected boolean exists; + protected boolean exists; //值是否不能为空 - protected boolean notNull; + protected boolean notNull; //连接条件 - protected String andOr; + protected String andOr; //属性和列对应 protected Map propertyMap; @@ -495,7 +495,7 @@ public Criteria andCondition(String condition, Object value) { * @Date 2015年7月17日 下午12:48:08 */ public Criteria andEqualTo(Object param) { - if(param == null){ + if (param == null) { return (Criteria) this; } MetaObject metaObject = MetaObjectUtil.forObject(param); @@ -823,25 +823,25 @@ public boolean isSingleValue() { } public static class Builder { - private final Class entityClass; - protected EntityTable table; + private final Class entityClass; + protected EntityTable table; //属性和列对应 - protected Map propertyMap; - private StringBuilder orderByClause; - private boolean distinct; - private boolean exists; - private boolean notNull; - private boolean forUpdate; + protected Map propertyMap; + private StringBuilder orderByClause; + private boolean distinct; + private boolean exists; + private boolean notNull; + private boolean forUpdate; //查询字段 - private Set selectColumns; + private Set selectColumns; //排除的查询字段 - private Set excludeColumns; - private String countColumn; - private List sqlsCriteria; + private Set excludeColumns; + private String countColumn; + private List sqlsCriteria; //动态表名 - private List exampleCriterias; + private List exampleCriterias; //动态表名 - private String tableName; + private String tableName; public Builder(Class entityClass) { this(entityClass, true); @@ -975,7 +975,7 @@ private void contactOrderByClause(String order, String... properties) { columns.append(",").append(column).append(order); } } - ; + ; if (columns.length() > 0) { orderByClause.append(columns); } diff --git a/core/src/main/java/tk/mybatis/mapper/genid/GenId.java b/core/src/main/java/tk/mybatis/mapper/genid/GenId.java index b8753edef..7610d77da 100644 --- a/core/src/main/java/tk/mybatis/mapper/genid/GenId.java +++ b/core/src/main/java/tk/mybatis/mapper/genid/GenId.java @@ -2,11 +2,11 @@ /** * 不提供具体的实现,这里提供一个思路。
- * + *

* 在 Spring 集成环境中,可以通过配置静态方式获取 Spring 的 context 对象。
- * + *

* 如果使用 vesta(https://gitee.com/robertleepeak/vesta-id-generator) 来生成 ID,假设已经提供了 vesta 的 idService。
- * + *

* 那么可以在实现中获取该类,然后生成 Id 返回,示例代码如下: * *

diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java
index 7a4557d71..4868fc84b 100644
--- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java
+++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java
@@ -104,16 +104,17 @@ public static List getAll(Class entityClass) {
         }
         return all;
     }
-    
+
     /**
      * 判断是否已经包含同名的field
+     *
      * @param fieldList
      * @param filedName
      * @return
      */
     private static boolean containFiled(List fieldList, String filedName) {
-        for(EntityField field: fieldList) {
-            if(field.getName().equals(filedName)) {
+        for (EntityField field : fieldList) {
+            if (field.getName().equals(filedName)) {
                 return true;
             }
         }
@@ -193,7 +194,7 @@ private List _getFields(Class entityClass, List fie
                 //排除静态字段,解决bug#2
                 if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) {
                     //如果父类中包含与子类同名field,则跳过处理,允许子类进行覆盖
-                    if(FieldHelper.containFiled(fieldList,field.getName())) {
+                    if (FieldHelper.containFiled(fieldList, field.getName())) {
                         continue;
                     }
                     if (level.intValue() != 0) {
@@ -320,8 +321,8 @@ private void _getFields(Class entityClass, List fieldList, Map mapperClass = getMapperClass(msId);
-                if(mapperClass.isInterface() && hasRegisterMapper(mapperClass)){
+                if (mapperClass.isInterface() && hasRegisterMapper(mapperClass)) {
                     mapperTemplate = getMapperTemplateByMsId(msId);
                 }
-            } catch (Exception e){
+            } catch (Exception e) {
                 log.warn("特殊情况: " + e);
             }
         }
@@ -208,7 +208,7 @@ public MapperTemplate isMapperMethod(String msId) {
      * @param msId
      * @return
      */
-    public MapperTemplate getMapperTemplateByMsId(String msId){
+    public MapperTemplate getMapperTemplateByMsId(String msId) {
         for (Map.Entry, MapperTemplate> entry : registerMapper.entrySet()) {
             if (entry.getValue().supportMethod(msId)) {
                 return entry.getValue();
@@ -239,14 +239,14 @@ public boolean isExtendCommonMapper(Class mapperInterface) {
      * @param mapperInterface
      * @return
      */
-    private boolean hasRegisterMapper(Class mapperInterface){
+    private boolean hasRegisterMapper(Class mapperInterface) {
         //如果一个都没匹配上,很可能是还没有注册 mappers,此时通过 @RegisterMapper 注解进行判断
         Class[] interfaces = mapperInterface.getInterfaces();
         boolean hasRegisterMapper = false;
         if (interfaces != null && interfaces.length > 0) {
             for (Class anInterface : interfaces) {
                 //自动注册标记了 @RegisterMapper 的接口
-                if(anInterface.isAnnotationPresent(RegisterMapper.class)){
+                if (anInterface.isAnnotationPresent(RegisterMapper.class)) {
                     hasRegisterMapper = true;
                     //如果已经注册过,就避免在反复调用下面会迭代的方法
                     if (!registerMapper.containsKey(anInterface)) {
@@ -254,7 +254,7 @@ private boolean hasRegisterMapper(Class mapperInterface){
                     }
                 }
                 //如果父接口的父接口存在注解,也可以注册
-                else if(hasRegisterMapper(anInterface)){
+                else if (hasRegisterMapper(anInterface)) {
                     hasRegisterMapper = true;
                 }
             }
@@ -300,9 +300,9 @@ public void processConfiguration(Configuration configuration, Class mapperInt
      *
      * @param ms
      */
-    public void processMappedStatement(MappedStatement ms){
+    public void processMappedStatement(MappedStatement ms) {
         MapperTemplate mapperTemplate = isMapperMethod(ms.getId());
-        if(mapperTemplate != null && ms.getSqlSource() instanceof ProviderSqlSource) {
+        if (mapperTemplate != null && ms.getSqlSource() instanceof ProviderSqlSource) {
             setSqlSource(ms, mapperTemplate);
         }
     }
@@ -323,17 +323,17 @@ public Config getConfig() {
      */
     public void setConfig(Config config) {
         this.config = config;
-        if(config.getResolveClass() != null){
+        if (config.getResolveClass() != null) {
             try {
                 EntityHelper.setResolve(config.getResolveClass().newInstance());
             } catch (Exception e) {
                 log.error("创建 " + config.getResolveClass().getCanonicalName()
-                    + " 实例失败,请保证该类有默认的构造方法!", e);
+                        + " 实例失败,请保证该类有默认的构造方法!", e);
                 throw new MapperException("创建 " + config.getResolveClass().getCanonicalName()
                         + " 实例失败,请保证该类有默认的构造方法!", e);
             }
         }
-        if(config.getMappers() != null && config.getMappers().size() > 0){
+        if (config.getMappers() != null && config.getMappers().size() > 0) {
             for (Class mapperClass : config.getMappers()) {
                 registerMapper(mapperClass);
             }
diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java
index df949b615..195c8333f 100644
--- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java
+++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java
@@ -58,11 +58,11 @@
  * @author liuzh
  */
 public abstract class MapperTemplate {
-    private static final XMLLanguageDriver     languageDriver = new XMLLanguageDriver();
-    protected            Map   methodMap      = new ConcurrentHashMap();
-    protected            Map> entityClassMap = new ConcurrentHashMap>();
-    protected            Class              mapperClass;
-    protected            MapperHelper          mapperHelper;
+    private static final XMLLanguageDriver languageDriver = new XMLLanguageDriver();
+    protected Map methodMap = new ConcurrentHashMap();
+    protected Map> entityClassMap = new ConcurrentHashMap>();
+    protected Class mapperClass;
+    protected MapperHelper mapperHelper;
 
     public MapperTemplate(Class mapperClass, MapperHelper mapperHelper) {
         this.mapperClass = mapperClass;
diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SelectKeyGenerator.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SelectKeyGenerator.java
index 68de7d4c0..ddc335de3 100644
--- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SelectKeyGenerator.java
+++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SelectKeyGenerator.java
@@ -42,7 +42,7 @@
 public class SelectKeyGenerator implements KeyGenerator {
 
     public static final String SELECT_KEY_SUFFIX = "!selectKey";
-    private boolean         executeBefore;
+    private boolean executeBefore;
     private MappedStatement keyStatement;
 
     public SelectKeyGenerator(MappedStatement keyStatement, boolean executeBefore) {
@@ -123,9 +123,9 @@ private void handleMultipleProperties(String[] keyProperties,
 
     private void setValue(MetaObject metaParam, String property, Object value) {
         if (metaParam.hasSetter(property)) {
-            if(metaParam.hasGetter(property)){
+            if (metaParam.hasGetter(property)) {
                 Object defaultValue = metaParam.getValue(property);
-                if(defaultValue != null){
+                if (defaultValue != null) {
                     return;
                 }
             }
diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java
index 2378e17c4..1094a60ea 100644
--- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java
+++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java
@@ -379,7 +379,7 @@ public static String insertIntoTable(Class entityClass, String defaultTableNa
      *
      * @param entityClass
      * @param defaultTableName
-     * @param parameterName 动态表名的参数名
+     * @param parameterName    动态表名的参数名
      * @return
      */
     public static String insertIntoTable(Class entityClass, String defaultTableName, String parameterName) {
@@ -493,7 +493,7 @@ public static String updateSetColumns(Class entityClass, String entityName, b
                     sql.append(" entityClass, String
                 logicDeleteColumn = column;
             }
             if (!column.isId() && column.isUpdatable()) {
-                if(column.getEntityField().isAnnotationPresent(Version.class)){
+                if (column.getEntityField().isAnnotationPresent(Version.class)) {
                     //ignore
                 } else if (column == logicDeleteColumn) {
                     sql.append(logicDeleteColumnEqualsValue(column, false)).append(",");
diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java
index 61981c8e2..f4751eed3 100644
--- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java
+++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java
@@ -172,7 +172,7 @@ protected void processField(EntityTable entityTable, EntityField field, Config c
      */
     protected void processOrderBy(EntityTable entityTable, EntityField field, EntityColumn entityColumn) {
         String orderBy = "";
-        if(field.isAnnotationPresent(OrderBy.class)){
+        if (field.isAnnotationPresent(OrderBy.class)) {
             orderBy = field.getAnnotation(OrderBy.class).value();
             if ("".equals(orderBy)) {
                 orderBy = "ASC";
@@ -264,17 +264,17 @@ protected void processKeySql(EntityTable entityTable, EntityColumn entityColumn,
         } else if (keySql.dialect() == IdentityDialect.DEFAULT) {
             entityColumn.setIdentity(true);
             entityColumn.setOrder(ORDER.AFTER);
-        }  else if (keySql.dialect() != IdentityDialect.NULL) {
+        } else if (keySql.dialect() != IdentityDialect.NULL) {
             //自动增长
             entityColumn.setIdentity(true);
             entityColumn.setOrder(ORDER.AFTER);
             entityColumn.setGenerator(keySql.dialect().getIdentityRetrievalStatement());
-        } else if (StringUtil.isNotEmpty(keySql.sql())){
+        } else if (StringUtil.isNotEmpty(keySql.sql())) {
 
             entityColumn.setIdentity(true);
             entityColumn.setOrder(keySql.order());
             entityColumn.setGenerator(keySql.sql());
-        } else if (keySql.genSql() != GenSql.NULL.class){
+        } else if (keySql.genSql() != GenSql.NULL.class) {
             entityColumn.setIdentity(true);
             entityColumn.setOrder(keySql.order());
             try {
@@ -284,7 +284,7 @@ protected void processKeySql(EntityTable entityTable, EntityColumn entityColumn,
                 log.error("实例化 GenSql 失败: " + e, e);
                 throw new MapperException("实例化 GenSql 失败: " + e, e);
             }
-        } else if(keySql.genId() != GenId.NULL.class){
+        } else if (keySql.genId() != GenId.NULL.class) {
             entityColumn.setIdentity(false);
             entityColumn.setGenIdClass(keySql.genId());
         } else {
diff --git a/core/src/main/java/tk/mybatis/mapper/util/MsUtil.java b/core/src/main/java/tk/mybatis/mapper/util/MsUtil.java
index 7b164c35c..350d7eafe 100644
--- a/core/src/main/java/tk/mybatis/mapper/util/MsUtil.java
+++ b/core/src/main/java/tk/mybatis/mapper/util/MsUtil.java
@@ -51,7 +51,7 @@ public static Class getMapperClass(String msId) {
         String mapperClassStr = msId.substring(0, msId.lastIndexOf("."));
         //由于一个接口中的每个方法都会进行下面的操作,因此缓存
         Class mapperClass = (Class) CLASS_CACHE.getObject(mapperClassStr);
-        if(mapperClass != null){
+        if (mapperClass != null) {
             return mapperClass;
         }
         ClassLoader[] classLoader = getClassLoaders();
diff --git a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java
index 6100f98a8..1cb9ba5a2 100644
--- a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java
+++ b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java
@@ -97,8 +97,8 @@ public static boolean notAllNullParameterCheck(Object parameter, String fields)
      * @param error
      * @return
      */
-    public static boolean notEmptyCollectionCheck(Object parameter, String error){
-        if(parameter == null || (parameter instanceof Collection && ((Collection) parameter).size() == 0)){
+    public static boolean notEmptyCollectionCheck(Object parameter, String error) {
+        if (parameter == null || (parameter instanceof Collection && ((Collection) parameter).size() == 0)) {
             throw new IllegalArgumentException(error);
         }
         return true;
@@ -121,7 +121,7 @@ public static boolean exampleHasAtLeastOneCriteriaCheck(Object parameter) {
                 } else {
                     Method getter = parameter.getClass().getDeclaredMethod("getOredCriteria");
                     Object list = getter.invoke(parameter);
-                    if(list != null && list instanceof List && ((List) list).size() > 0){
+                    if (list != null && list instanceof List && ((List) list).size() > 0) {
                         return true;
                     }
                 }
@@ -239,7 +239,7 @@ public static String andNotLogicDelete(Object parameter) {
             Example example = (Example) parameter;
             Map propertyMap = example.getPropertyMap();
 
-            for (Map.Entry entry: propertyMap.entrySet()) {
+            for (Map.Entry entry : propertyMap.entrySet()) {
                 EntityColumn column = entry.getValue();
                 if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) {
                     // 未逻辑删除的条件
diff --git a/core/src/main/java/tk/mybatis/mapper/util/SimpleTypeUtil.java b/core/src/main/java/tk/mybatis/mapper/util/SimpleTypeUtil.java
index df50bb8a8..00c5f111c 100644
--- a/core/src/main/java/tk/mybatis/mapper/util/SimpleTypeUtil.java
+++ b/core/src/main/java/tk/mybatis/mapper/util/SimpleTypeUtil.java
@@ -37,7 +37,7 @@
  * 参考 org.apache.ibatis.type.SimpleTypeRegistry
  */
 public class SimpleTypeUtil {
-    public static final  String[]      JAVA8_DATE_TIME = {
+    public static final String[] JAVA8_DATE_TIME = {
             "java.time.Instant",
             "java.time.LocalDateTime",
             "java.time.LocalDate",
@@ -81,14 +81,14 @@ public class SimpleTypeUtil {
      *
      * @param clazz
      */
-    public static void registerSimpleType(Class clazz){
+    public static void registerSimpleType(Class clazz) {
         SIMPLE_TYPE_SET.add(clazz);
     }
 
     /**
      * 注册 8 种基本类型
      */
-    public static void registerPrimitiveTypes(){
+    public static void registerPrimitiveTypes() {
         registerSimpleType(boolean.class);
         registerSimpleType(byte.class);
         registerSimpleType(short.class);
@@ -104,8 +104,8 @@ public static void registerPrimitiveTypes(){
      *
      * @param classes
      */
-    public static void registerSimpleType(String classes){
-        if(StringUtil.isNotEmpty(classes)){
+    public static void registerSimpleType(String classes) {
+        if (StringUtil.isNotEmpty(classes)) {
             String[] cls = classes.split(",");
             for (String c : cls) {
                 try {
diff --git a/core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java b/core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java
index 43d4a0a0f..7559203b2 100644
--- a/core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java
+++ b/core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java
@@ -31,19 +31,18 @@
  * Since different databases have different reserved words, this list is
  * inclusive of many different databases - so it may include words that are not
  * reserved in some databases.
- * 
+ *
  * 

This list is based on the list from Drupal Handbook: * http://drupal.org/node/141051 With additions for DB2 - * + * * @author Jeff Butler - * */ public class SqlReservedWords { private static Set RESERVED_WORDS; static { - String[] words = { "A", //$NON-NLS-1$ + String[] words = {"A", //$NON-NLS-1$ "ABORT", //$NON-NLS-1$ "ABS", //$NON-NLS-1$ "ABSOLUTE", //$NON-NLS-1$ diff --git a/core/src/main/java/tk/mybatis/mapper/util/Sqls.java b/core/src/main/java/tk/mybatis/mapper/util/Sqls.java index 77f5f0c45..7a055fb63 100644 --- a/core/src/main/java/tk/mybatis/mapper/util/Sqls.java +++ b/core/src/main/java/tk/mybatis/mapper/util/Sqls.java @@ -168,6 +168,7 @@ public Sqls orNotLike(String property, String value) { public static class Criteria { private String andOr; private List criterions; + public Criteria() { this.criterions = new ArrayList(2); } @@ -227,16 +228,17 @@ public Object getSecondValue() { } public Object[] getValues() { - if (value !=null) { + if (value != null) { if (secondValue != null) { return new Object[]{value, secondValue}; } else { - return new Object[] {value}; + return new Object[]{value}; } } else { return new Object[]{}; } } + public String getCondition() { return condition; } diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTest.java index 4c138cb81..e9bcf308e 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTest.java @@ -26,7 +26,7 @@ public class ColumnTest { private Configuration configuration; @Before - public void beforeTest(){ + public void beforeTest() { config = new Config(); config.setStyle(Style.normal); @@ -39,7 +39,7 @@ class UserColumn { } @Test - public void testColumn(){ + public void testColumn() { EntityHelper.initEntityNameMap(UserColumn.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserColumn.class); Assert.assertNotNull(entityTable); diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTypeTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTypeTest.java index 51a915186..21d9a18f8 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTypeTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTypeTest.java @@ -27,7 +27,7 @@ public class ColumnTypeTest { private Configuration configuration; @Before - public void beforeTest(){ + public void beforeTest() { config = new Config(); config.setStyle(Style.normal); @@ -40,7 +40,7 @@ class UserColumn { } @Test - public void testColumn(){ + public void testColumn() { EntityHelper.initEntityNameMap(UserColumn.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserColumn.class); Assert.assertNotNull(entityTable); @@ -79,7 +79,7 @@ class UserJdbcTypeVarchar { } @Test - public void testJdbcTypeVarchar(){ + public void testJdbcTypeVarchar() { EntityHelper.initEntityNameMap(UserJdbcTypeVarchar.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserJdbcTypeVarchar.class); Assert.assertNotNull(entityTable); @@ -119,7 +119,7 @@ class UserJdbcTypeBlob { } @Test - public void testJdbcTypeBlob(){ + public void testJdbcTypeBlob() { EntityHelper.initEntityNameMap(UserJdbcTypeBlob.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserJdbcTypeBlob.class); Assert.assertNotNull(entityTable); @@ -159,7 +159,7 @@ class UserTypehandler { } @Test - public void testTypehandler(){ + public void testTypehandler() { EntityHelper.initEntityNameMap(UserTypehandler.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserTypehandler.class); Assert.assertNotNull(entityTable); @@ -198,7 +198,7 @@ class UserAll { } @Test - public void testAll(){ + public void testAll() { EntityHelper.initEntityNameMap(UserAll.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserAll.class); Assert.assertNotNull(entityTable); diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/IdTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/IdTest.java index f9f345991..c4cc9473a 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/IdTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/IdTest.java @@ -26,7 +26,7 @@ public class IdTest { private Configuration configuration; @Before - public void beforeTest(){ + public void beforeTest() { config = new Config(); config.setStyle(Style.normal); @@ -39,7 +39,7 @@ class UserSingleId { } @Test - public void testSingleId(){ + public void testSingleId() { EntityHelper.initEntityNameMap(UserSingleId.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserSingleId.class); Assert.assertNotNull(entityTable); @@ -58,7 +58,7 @@ public void testSingleId(){ Assert.assertEquals(" AND name = #{name}", SqlHelper.wherePKColumns(UserSingleId.class)); } - class UserCompositeKeys { + class UserCompositeKeys { @Id private String name; @@ -67,7 +67,7 @@ class UserCompositeKeys { } @Test - public void testCompositeKeys(){ + public void testCompositeKeys() { EntityHelper.initEntityNameMap(UserCompositeKeys.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserCompositeKeys.class); Assert.assertNotNull(entityTable); diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/KeySqlTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/KeySqlTest.java index 1eb61d644..923cc24c6 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/KeySqlTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/KeySqlTest.java @@ -24,7 +24,7 @@ public class KeySqlTest { private Configuration configuration; @Before - public void beforeTest(){ + public void beforeTest() { config = new Config(); config.setStyle(Style.normal); @@ -37,7 +37,7 @@ class UserJDBC { } @Test - public void testUseGeneratedKeys(){ + public void testUseGeneratedKeys() { EntityHelper.initEntityNameMap(UserJDBC.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserJDBC.class); Assert.assertNotNull(entityTable); @@ -57,7 +57,7 @@ class UserDialect { } @Test - public void testDialect(){ + public void testDialect() { EntityHelper.initEntityNameMap(UserDialect.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserDialect.class); Assert.assertNotNull(entityTable); @@ -78,7 +78,7 @@ class UserSql { } @Test - public void testSql(){ + public void testSql() { EntityHelper.initEntityNameMap(UserSql.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserSql.class); Assert.assertNotNull(entityTable); @@ -99,7 +99,7 @@ class UserAll { } @Test - public void testAll(){ + public void testAll() { EntityHelper.initEntityNameMap(UserAll.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserAll.class); Assert.assertNotNull(entityTable); @@ -119,7 +119,7 @@ class UserAll2 { } @Test - public void testAll2(){ + public void testAll2() { EntityHelper.initEntityNameMap(UserAll2.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserAll2.class); Assert.assertNotNull(entityTable); diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/NameStyleTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/NameStyleTest.java index 6c3a83c09..81ed8d779 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/NameStyleTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/NameStyleTest.java @@ -25,7 +25,7 @@ public class NameStyleTest { private Configuration configuration; @Before - public void beforeTest(){ + public void beforeTest() { config = new Config(); config.setStyle(Style.normal); @@ -38,7 +38,7 @@ class UserCamelhump { } @Test - public void testCamelhump(){ + public void testCamelhump() { EntityHelper.initEntityNameMap(UserCamelhump.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhump.class); Assert.assertNotNull(entityTable); @@ -78,7 +78,7 @@ class UserCamelhumpAndUppercase { } @Test - public void testCamelhumpAndUppercase(){ + public void testCamelhumpAndUppercase() { EntityHelper.initEntityNameMap(UserCamelhumpAndUppercase.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhumpAndUppercase.class); Assert.assertNotNull(entityTable); @@ -118,7 +118,7 @@ class UserCamelhumpAndLowercase { } @Test - public void testCamelhumpAndLowercase(){ + public void testCamelhumpAndLowercase() { EntityHelper.initEntityNameMap(UserCamelhumpAndLowercase.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhumpAndLowercase.class); Assert.assertNotNull(entityTable); @@ -158,7 +158,7 @@ class UserNormal { } @Test - public void testNormal(){ + public void testNormal() { EntityHelper.initEntityNameMap(UserNormal.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserNormal.class); Assert.assertNotNull(entityTable); @@ -198,7 +198,7 @@ class UserUppercase { } @Test - public void testUppercase(){ + public void testUppercase() { EntityHelper.initEntityNameMap(UserUppercase.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserUppercase.class); Assert.assertNotNull(entityTable); @@ -238,7 +238,7 @@ class UserLowercase { } @Test - public void testLowercase(){ + public void testLowercase() { EntityHelper.initEntityNameMap(UserLowercase.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserLowercase.class); Assert.assertNotNull(entityTable); diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/RegisterMapperTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/RegisterMapperTest.java index 987454ed6..88816f2a0 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/RegisterMapperTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/RegisterMapperTest.java @@ -18,7 +18,7 @@ public class RegisterMapperTest { private Configuration configuration; @Before - public void beforeTest(){ + public void beforeTest() { config = new Config(); config.setStyle(Style.normal); @@ -35,7 +35,7 @@ interface UserMapper extends MapperHashRegisterMapper { } @Test - public void testHashRegisterMapper(){ + public void testHashRegisterMapper() { MapperHelper mapperHelper = new MapperHelper(); Assert.assertTrue(mapperHelper.isExtendCommonMapper(UserMapper.class)); } @@ -45,7 +45,7 @@ interface RoleMapper { } @Test - public void testRoleMapper(){ + public void testRoleMapper() { MapperHelper mapperHelper = new MapperHelper(); Assert.assertFalse(mapperHelper.isExtendCommonMapper(RoleMapper.class)); } @@ -56,7 +56,7 @@ interface RoleMapper2 { } @Test - public void testRoleMapper2(){ + public void testRoleMapper2() { MapperHelper mapperHelper = new MapperHelper(); Assert.assertFalse(mapperHelper.isExtendCommonMapper(RoleMapper2.class)); } diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/VersionTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/VersionTest.java index f940a88d9..3fd78fecb 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/VersionTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/VersionTest.java @@ -24,7 +24,7 @@ public class VersionTest { private Configuration configuration; @Before - public void beforeTest(){ + public void beforeTest() { config = new Config(); config.setStyle(Style.normal); @@ -37,7 +37,7 @@ class UserVersion { } @Test - public void testVersion(){ + public void testVersion() { EntityHelper.initEntityNameMap(UserVersion.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserVersion.class); Assert.assertNotNull(entityTable); @@ -62,7 +62,7 @@ class UserVersionError { } @Test(expected = VersionException.class) - public void testVersionError(){ + public void testVersionError() { EntityHelper.initEntityNameMap(UserVersionError.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserVersionError.class); Assert.assertNotNull(entityTable); diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/FieldHelperTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/FieldHelperTest.java index 4bb035505..1ede75248 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/FieldHelperTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/FieldHelperTest.java @@ -19,7 +19,7 @@ static class User { } @Test - public void testUser(){ + public void testUser() { List fieldList = FieldHelper.getFields(User.class); Assert.assertEquals(2, fieldList.size()); Assert.assertEquals("id", fieldList.get(0).getName()); @@ -32,7 +32,7 @@ static class Admin { } @Test - public void testComplex(){ + public void testComplex() { List fieldList = FieldHelper.getFields(Admin.class); Assert.assertEquals(2, fieldList.size()); Assert.assertEquals("admin", fieldList.get(0).getName()); diff --git a/extra/README.md b/extra/README.md index aa967cd17..8030960ed 100644 --- a/extra/README.md +++ b/extra/README.md @@ -10,14 +10,14 @@ - 支持批量插入的数据库都可以使用,例如 mysql,h2 等 - `tk.mybatis.mapper.additional.insert.InsertListMapper` + `tk.mybatis.mapper.additional.insert.InsertListMapper` - SQL 形如 `insert table(xxx) values (xxx), (xxx) ...` + SQL 形如 `insert table(xxx) values (xxx), (xxx) ...` - Oracle特殊批量插入 - `tk.mybatis.mapper.additional.dialect.oracle.InsertListMapper` + `tk.mybatis.mapper.additional.dialect.oracle.InsertListMapper` - SQL 形如 + SQL 形如 ```sql INSERT ALL INTO demo_country ( country_id,country_name,country_code ) VALUES ( ?,?,? ) @@ -26,7 +26,7 @@ SELECT 1 FROM DUAL ``` - **由于语法限制,暂不支持序列.** + **由于语法限制,暂不支持序列.** ### UpdateByPrimaryKeySelectiveForceMapper diff --git a/extra/pom.xml b/extra/pom.xml index fbf2a211d..9c14d6313 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.1 + 4.2.2-SNAPSHOT mapper-extra jar @@ -38,7 +38,8 @@ 1.8 - 4.2.1 + 4.2.2-SNAPSHOT + 2.5.2 diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/aggregation/AggregateCondition.java b/extra/src/main/java/tk/mybatis/mapper/additional/aggregation/AggregateCondition.java index a73ce72ac..66ff08fee 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/aggregation/AggregateCondition.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/aggregation/AggregateCondition.java @@ -15,14 +15,14 @@ * @author liuzh */ public class AggregateCondition implements Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; // 聚合属性 - private String aggregateProperty; - private String aggregateAliasName; + private String aggregateProperty; + private String aggregateAliasName; // groupBy 查询列 - private List groupByProperties; + private List groupByProperties; // 聚合函数 - private AggregateType aggregateType; + private AggregateType aggregateType; public AggregateCondition() { this(null, AggregateType.COUNT, null); diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapper.java index 6175ddf27..3fbbf95a5 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapper.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeleteByPropertyMapper.java @@ -6,8 +6,6 @@ import tk.mybatis.mapper.annotation.RegisterMapper; import tk.mybatis.mapper.weekend.Fn; -import java.util.List; - /** * @param 不能为空 * @author jingkaihui @@ -19,8 +17,8 @@ public interface DeleteByPropertyMapper { /** * 根据实体中的属性删除,条件使用等号 * - * @param fn 属性 - * @param value 属性值 + * @param fn 属性 + * @param value 属性值 * @return */ @DeleteProvider(type = DeletePropertyProvider.class, method = "dynamicSQL") @@ -29,8 +27,8 @@ public interface DeleteByPropertyMapper { /** * 根据实体中的属性删除,条件使用 in * - * @param fn 属性 - * @param value 属性值 + * @param fn 属性 + * @param value 属性值 * @return */ @DeleteProvider(type = DeletePropertyProvider.class, method = "dynamicSQL") @@ -39,9 +37,9 @@ public interface DeleteByPropertyMapper { /** * 根据属性及对应值进行删除,删除条件使用 between * - * @param fn 属性 + * @param fn 属性 * @param begin 开始值 - * @param end 开始值 + * @param end 开始值 * @return */ @SelectProvider(type = DeletePropertyProvider.class, method = "dynamicSQL") diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeletePropertyProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeletePropertyProvider.java index 949886860..8e476b9c6 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeletePropertyProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/delete/DeletePropertyProvider.java @@ -3,7 +3,6 @@ import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.mapping.SqlCommandType; import tk.mybatis.mapper.MapperException; -import tk.mybatis.mapper.additional.select.SelectPropertyProvider; import tk.mybatis.mapper.entity.EntityColumn; import tk.mybatis.mapper.entity.EntityTable; import tk.mybatis.mapper.mapperhelper.EntityHelper; @@ -63,7 +62,7 @@ public String deleteByProperty(MappedStatement ms) { return sql.toString(); } - /** + /** * 根据属性删除,条件使用等号 * * @param ms @@ -87,10 +86,10 @@ public String deleteInByProperty(MappedStatement ms) { String entityClassName = entityClass.getName(); String sqlSegment = "${@" + propertyHelper + "@getColumnByProperty(@java.lang.Class@forName(\"" + entityClassName + "\")," - + "@tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))} in" - + "\n" - + "#{obj}\n" - + "\n"; + + "@tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))} in" + + "\n" + + "#{obj}\n" + + "\n"; sql.append(sqlSegment); // 逻辑删除的未删除查询条件 sql.append(SqlHelper.whereLogicDelete(entityClass, false)); @@ -133,8 +132,9 @@ public String deleteBetweenByProperty(MappedStatement ms) { /** * 根据实体Class和属性名获取对应的表字段名 + * * @param entityClass 实体Class对象 - * @param property 属性名 + * @param property 属性名 * @return */ public static String getColumnByProperty(Class entityClass, String property) { diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/InsertListMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/InsertListMapper.java index 8f6964439..a0b70b53b 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/InsertListMapper.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/InsertListMapper.java @@ -33,6 +33,7 @@ *

Oracle批量插入 *

支持@{@link KeySql#genId()},不支持@{@link KeySql#sql()} *

因INSERT ALL语法不支持序列,可手工获取序列并设置至Entity或绑定触发器 + * * @author qrqhuangcy * @date 2018-11-16 */ diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/OracleProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/OracleProvider.java index 9b121dfc5..951ba369a 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/OracleProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/OracleProvider.java @@ -24,20 +24,20 @@ public OracleProvider(Class mapperClass, MapperHelper mapperHelper) { * * INSERT ALL * - * INTO demo_country - * country_id,country_name,country_code, - * VALUES - * - * - * #{record.countryId},#{record.countryName},#{record.countryCode}, - * + * INTO demo_country + * country_id,country_name,country_code, + * VALUES + * + * + * #{record.countryId},#{record.countryName},#{record.countryCode}, + * * * SELECT 1 FROM DUAL - * + * * @param ms * @return */ - public String insertList(MappedStatement ms){ + public String insertList(MappedStatement ms) { final Class entityClass = getEntityClass(ms); //开始拼sql StringBuilder sql = new StringBuilder(); @@ -46,7 +46,7 @@ public String insertList(MappedStatement ms){ sql.append("INSERT ALL\n"); sql.append("\n"); - String tableName = SqlHelper.getDynamicTableName(entityClass, tableName(entityClass),"list[0]"); + String tableName = SqlHelper.getDynamicTableName(entityClass, tableName(entityClass), "list[0]"); String columns = SqlHelper.insertColumns(entityClass, false, false, false); sql.append(" INTO ").append(tableName).append(" ").append(columns).append("\n"); sql.append(" VALUES "); @@ -56,7 +56,7 @@ public String insertList(MappedStatement ms){ Set columnList = EntityHelper.getColumns(entityClass); //单独增加对 genId 方式的支持 for (EntityColumn column : columnList) { - if(column.getGenIdClass() != null){ + if (column.getGenIdClass() != null) { sql.append(" mapperClass, MapperHelper mapperHelper) { * @param list * @param errorMsg */ - public static void notEmpty(List list, String errorMsg){ - if(list == null || list.size() == 0){ + public static void notEmpty(List list, String errorMsg) { + if (list == null || list.size() == 0) { throw new MapperException(errorMsg); } } @@ -97,11 +97,11 @@ public String selectByIdList(MappedStatement ms) { * @param sql * @param entityClass */ - private void appendWhereIdList(StringBuilder sql, Class entityClass, boolean notEmpty){ + private void appendWhereIdList(StringBuilder sql, Class entityClass, boolean notEmpty) { Set columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); - if(notEmpty){ + if (notEmpty) { sql.append(""); } diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java index c1e3243dc..4fa9a49f2 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java @@ -11,7 +11,6 @@ * 根据属性查询接口 * * @param 不能为空 - * * @author jingkaihui * @date 2019/10/11 */ @@ -21,8 +20,8 @@ public interface SelectByPropertyMapper { /** * 根据属性及对应值进行查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 * - * @param fn 查询属性 - * @param value 属性值 + * @param fn 查询属性 + * @param value 属性值 * @return */ @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") @@ -31,7 +30,7 @@ public interface SelectByPropertyMapper { /** * 根据属性及对应值进行查询,有多个返回值,查询条件使用等号 * - * @param fn 查询属性 + * @param fn 查询属性 * @param value 属性值 * @return */ @@ -41,7 +40,7 @@ public interface SelectByPropertyMapper { /** * 根据属性及对应值进行查询,查询条件使用 in * - * @param fn 查询属性 + * @param fn 查询属性 * @param values 属性值集合,集合不能空 * @return */ @@ -51,9 +50,9 @@ public interface SelectByPropertyMapper { /** * 根据属性及对应值进行查询,查询条件使用 between * - * @param fn 查询属性 + * @param fn 查询属性 * @param begin 开始值 - * @param end 开始值 + * @param end 开始值 * @return */ @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") @@ -62,7 +61,7 @@ public interface SelectByPropertyMapper { /** * 根据属性及对应值进行查询,检查是否存在对应记录,查询条件使用等号 * - * @param fn 查询属性 + * @param fn 查询属性 * @param value 属性值 * @return */ @@ -72,8 +71,8 @@ public interface SelectByPropertyMapper { /** * 根据属性及对应值进行查询,统计符合条件的记录数,查询条件使用等号 * - * @param fn 查询属性 - * @param value 属性值 + * @param fn 查询属性 + * @param value 属性值 * @return */ @SelectProvider(type = SelectPropertyProvider.class, method = "dynamicSQL") diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java index 57fb529b9..2586614fb 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java @@ -25,7 +25,8 @@ public SelectPropertyProvider(Class mapperClass, MapperHelper mapperHelper) { super(mapperClass, mapperHelper); } - /**Ba + /** + * Ba * 根据属性查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 * * @param ms @@ -115,10 +116,10 @@ public String selectInByProperty(MappedStatement ms) { String propertyHelper = SelectPropertyProvider.class.getName(); String sqlSegment = "${@" + propertyHelper + "@getColumnByProperty(@java.lang.Class@forName(\"" + entityClassName + "\")," - + "@tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))} in" - + "\n" - + "#{obj}\n" - + "\n"; + + "@tk.mybatis.mapper.weekend.reflection.Reflections@fnToFieldName(fn))} in" + + "\n" + + "#{obj}\n" + + "\n"; sql.append(sqlSegment); // 逻辑删除的未删除查询条件 sql.append(SqlHelper.whereLogicDelete(entityClass, false)); @@ -225,8 +226,9 @@ public String selectCountByProperty(MappedStatement ms) { /** * 根据实体Class和属性名获取对应的表字段名 + * * @param entityClass 实体Class对象 - * @param property 属性名 + * @param property 属性名 * @return */ public static String getColumnByProperty(Class entityClass, String property) { @@ -237,6 +239,7 @@ public static String getColumnByProperty(Class entityClass, String property) /** * 判断是否需要拼接 where 条件 + * * @param value * @param notEmpty * @return diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java index 91bacdb13..d704aafda 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java @@ -132,9 +132,9 @@ public String updateSetColumnsByDiffer(Class entityClass) { String versionClass = version.nextVersion().getCanonicalName(); //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)} sql.append(column.getColumn()) - .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") - .append("@").append(versionClass).append("@class, ") - .append(column.getProperty()).append(")},"); + .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") + .append("@").append(versionClass).append("@class, ") + .append(column.getProperty()).append(")},"); } else { //if old.xx != newer.xx sql.append(getIfNotEqual(column, column.getColumnEqualsHolder(NEWER) + ",")); diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceMapper.java index b2e431ecd..c41b71fa2 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceMapper.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceMapper.java @@ -7,8 +7,8 @@ import java.util.List; /** - * @Description: 通用Mapper接口, 非空字段强制更新 * @author qrqhuangcy + * @Description: 通用Mapper接口, 非空字段强制更新 * @date 2018-06-26 */ @RegisterMapper @@ -16,6 +16,7 @@ public interface UpdateByPrimaryKeySelectiveForceMapper { /** * 根据主键更新属性不为null的值, 指定的属性(null值)会被强制更新 + * * @param record * @param forceUpdateProperties * @return diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java index 87d513dba..26532f884 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java @@ -37,8 +37,8 @@ import java.util.Set; /** - * @Description: 通用Mapper接口,更新,强制,实现 * @author qrqhuangcy + * @Description: 通用Mapper接口, 更新, 强制,实现 * @date 2018-06-26 */ public class UpdateByPrimaryKeySelectiveForceProvider extends MapperTemplate { @@ -90,9 +90,9 @@ public String updateSetColumnsForce(Class entityClass, String entityName, boo String versionClass = version.nextVersion().getCanonicalName(); //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)} sql.append(column.getColumn()) - .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") - .append("@").append(versionClass).append("@class, ") - .append(column.getProperty()).append(")},"); + .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") + .append("@").append(versionClass).append("@class, ") + .append(column.getProperty()).append(")},"); } else if (notNull) { sql.append(this.getIfNotNull(entityName, column, column.getColumnEqualsHolder(entityName) + ",", notEmpty)); } else { diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/BaseTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/BaseTest.java index 9719ee98e..773a0666f 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/BaseTest.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/BaseTest.java @@ -47,7 +47,7 @@ public abstract class BaseTest { private SqlSessionFactory sqlSessionFactory; @Before - public final void init(){ + public final void init() { try { Reader reader = getConfigFileAsReader(); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); @@ -64,7 +64,7 @@ public final void init(){ /** * 配置通用 Mapper */ - protected void configMapperHelper(){ + protected void configMapperHelper() { SqlSession session = getSqlSession(); try { //创建一个MapperHelper @@ -84,7 +84,7 @@ protected void configMapperHelper(){ * @param reader */ protected void runSql(Reader reader) { - if(reader == null){ + if (reader == null) { return; } SqlSession sqlSession = getSqlSession(); @@ -95,7 +95,8 @@ protected void runSql(Reader reader) { runner.runScript(reader); try { reader.close(); - } catch (IOException e) {} + } catch (IOException e) { + } } finally { sqlSession.close(); } @@ -106,7 +107,7 @@ protected void runSql(Reader reader) { * * @return */ - protected Config getConfig(){ + protected Config getConfig() { return new Config(); } @@ -118,7 +119,9 @@ protected Config getConfig(){ protected Reader getConfigFileAsReader() throws IOException { URL url = BaseTest.class.getResource("mybatis-config.xml"); return toReader(url); - }; + } + + ; /** * 获取初始化 sql @@ -128,7 +131,9 @@ protected Reader getConfigFileAsReader() throws IOException { protected Reader getSqlFileAsReader() throws IOException { URL url = BaseTest.class.getResource("CreateDB.sql"); return toReader(url); - }; + } + + ; /** * 转为 Reader diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/CreateDB.sql index 6d67470fd..069dc4e71 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/CreateDB.sql @@ -1,192 +1,376 @@ drop table country if exists; -create table country ( - id integer NOT NULL PRIMARY KEY, - countryname varchar(32), - countrycode VARCHAR(2) DEFAULT 'HH', - version INTEGER DEFAULT 1 NOT NULL +create table country +( + id integer NOT NULL PRIMARY KEY, + countryname varchar(32), + countrycode VARCHAR(2) DEFAULT 'HH', + version INTEGER DEFAULT 1 NOT NULL ); -INSERT INTO country (id, countryname, countrycode, version) VALUES (1, 'Angola', 'AO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (2, 'Afghanistan', 'AF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (3, 'Albania', 'AL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (4, 'Algeria', 'DZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (5, 'Andorra', 'AD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (6, 'Anguilla', 'AI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (7, 'Antigua and Barbuda', 'AG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (8, 'Argentina', 'AR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (9, 'Armenia', 'AM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (10, 'Australia', 'AU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (11, 'Austria', 'AT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (12, 'Azerbaijan', 'AZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (13, 'Bahamas', 'BS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (14, 'Bahrain', 'BH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (15, 'Bangladesh', 'BD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (16, 'Barbados', 'BB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (17, 'Belarus', 'BY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (18, 'Belgium', 'BE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (19, 'Belize', 'BZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (20, 'Benin', 'BJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (21, 'Bermuda Is.', 'BM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (22, 'Bolivia', 'BO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (23, 'Botswana', 'BW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (24, 'Brazil', 'BR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (25, 'Brunei', 'BN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (26, 'Bulgaria', 'BG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (27, 'Burkina-faso', 'BF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (28, 'Burma', 'MM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (29, 'Burundi', 'BI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (30, 'Cameroon', 'CM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (31, 'Canada', 'CA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (32, 'Central African Republic', 'CF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (33, 'Chad', 'TD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (34, 'Chile', 'CL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (35, 'China', 'CN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (36, 'Colombia', 'CO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (37, 'Congo', 'CG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (38, 'Cook Is.', 'CK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (39, 'Costa Rica', 'CR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (40, 'Cuba', 'CU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (41, 'Cyprus', 'CY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (42, 'Czech Republic', 'CZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (43, 'Denmark', 'DK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (44, 'Djibouti', 'DJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (45, 'Dominica Rep.', 'DO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (46, 'Ecuador', 'EC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (47, 'Egypt', 'EG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (48, 'EI Salvador', 'SV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (49, 'Estonia', 'EE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (50, 'Ethiopia', 'ET', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (51, 'Fiji', 'FJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (52, 'Finland', 'FI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (53, 'France', 'FR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (54, 'French Guiana', 'GF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (55, 'Gabon', 'GA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (56, 'Gambia', 'GM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (57, 'Georgia', 'GE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (58, 'Germany', 'DE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (59, 'Ghana', 'GH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (60, 'Gibraltar', 'GI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (61, 'Greece', 'GR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (62, 'Grenada', 'GD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (63, 'Guam', 'GU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (64, 'Guatemala', 'GT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (65, 'Guinea', 'GN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (66, 'Guyana', 'GY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (67, 'Haiti', 'HT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (68, 'Honduras', 'HN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (69, 'Hongkong', 'HK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (70, 'Hungary', 'HU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (71, 'Iceland', 'IS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (72, 'India', 'IN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (73, 'Indonesia', 'ID', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (74, 'Iran', 'IR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (75, 'Iraq', 'IQ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (76, 'Ireland', 'IE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (77, 'Israel', 'IL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (78, 'Italy', 'IT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (79, 'Jamaica', 'JM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (80, 'Japan', 'JP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (81, 'Jordan', 'JO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (83, 'Kazakstan', 'KZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (84, 'Kenya', 'KE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (85, 'Korea', 'KR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (86, 'Kuwait', 'KW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (87, 'Kyrgyzstan', 'KG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (88, 'Laos', 'LA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (89, 'Latvia', 'LV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (90, 'Lebanon', 'LB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (91, 'Lesotho', 'LS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (92, 'Liberia', 'LR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (93, 'Libya', 'LY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (94, 'Liechtenstein', 'LI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (95, 'Lithuania', 'LT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (96, 'Luxembourg', 'LU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (97, 'Macao', 'MO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (98, 'Madagascar', 'MG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (99, 'Malawi', 'MW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (100, 'Malaysia', 'MY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (101, 'Maldives', 'MV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (102, 'Mali', 'ML', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (103, 'Malta', 'MT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (104, 'Mauritius', 'MU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (105, 'Mexico', 'MX', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (106, 'Moldova, Republic of', 'MD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (107, 'Monaco', 'MC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (108, 'Mongolia', 'MN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (109, 'Montserrat Is', 'MS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (110, 'Morocco', 'MA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (111, 'Mozambique', 'MZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (112, 'Namibia', 'NA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (113, 'Nauru', 'NR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (114, 'Nepal', 'NP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (115, 'Netherlands', 'NL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (116, 'New Zealand', 'NZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (117, 'Nicaragua', 'NI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (118, 'Niger', 'NE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (119, 'Nigeria', 'NG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (120, 'North Korea', 'KP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (121, 'Norway', 'NO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (122, 'Oman', 'OM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (123, 'Pakistan', 'PK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (124, 'Panama', 'PA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (125, 'Papua New Cuinea', 'PG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (126, 'Paraguay', 'PY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (127, 'Peru', 'PE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (128, 'Philippines', 'PH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (129, 'Poland', 'PL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (130, 'French Polynesia', 'PF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (131, 'Portugal', 'PT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (132, 'Puerto Rico', 'PR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (133, 'Qatar', 'QA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (134, 'Romania', 'RO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (135, 'Russia', 'RU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (136, 'Saint Lueia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (137, 'Saint Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (138, 'San Marino', 'SM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (139, 'Sao Tome and Principe', 'ST', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (140, 'Saudi Arabia', 'SA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (141, 'Senegal', 'SN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (142, 'Seychelles', 'SC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (143, 'Sierra Leone', 'SL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (144, 'Singapore', 'SG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (145, 'Slovakia', 'SK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (146, 'Slovenia', 'SI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (147, 'Solomon Is', 'SB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (148, 'Somali', 'SO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (149, 'South Africa', 'ZA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (150, 'Spain', 'ES', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (151, 'Sri Lanka', 'LK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (152, 'St.Lucia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (153, 'St.Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (154, 'Sudan', 'SD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (155, 'Suriname', 'SR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (156, 'Swaziland', 'SZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (157, 'Sweden', 'SE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (158, 'Switzerland', 'CH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (159, 'Syria', 'SY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (160, 'Taiwan', 'TW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (161, 'Tajikstan', 'TJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (162, 'Tanzania', 'TZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (163, 'Thailand', 'TH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (164, 'Togo', 'TG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (165, 'Tonga', 'TO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (166, 'Trinidad and Tobago', 'TT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (167, 'Tunisia', 'TN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (168, 'Turkey', 'TR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (169, 'Turkmenistan', 'TM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (170, 'Uganda', 'UG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (171, 'Ukraine', 'UA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (172, 'United Arab Emirates', 'AE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (173, 'United Kiongdom', 'GB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (174, 'United States of America', 'US', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (175, 'Uruguay', 'UY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (176, 'Uzbekistan', 'UZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (177, 'Venezuela', 'VE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (178, 'Vietnam', 'VN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (179, 'Yemen', 'YE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (180, 'Yugoslavia', 'YU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (181, 'Zimbabwe', 'ZW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (182, 'Zaire', 'ZR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (183, 'Zambia', 'ZM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (1, 'Angola', 'AO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (2, 'Afghanistan', 'AF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (3, 'Albania', 'AL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (4, 'Algeria', 'DZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (5, 'Andorra', 'AD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (6, 'Anguilla', 'AI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (7, 'Antigua and Barbuda', 'AG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (8, 'Argentina', 'AR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (9, 'Armenia', 'AM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (10, 'Australia', 'AU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (11, 'Austria', 'AT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (12, 'Azerbaijan', 'AZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (13, 'Bahamas', 'BS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (14, 'Bahrain', 'BH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (15, 'Bangladesh', 'BD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (16, 'Barbados', 'BB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (17, 'Belarus', 'BY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (18, 'Belgium', 'BE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (19, 'Belize', 'BZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (20, 'Benin', 'BJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (21, 'Bermuda Is.', 'BM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (22, 'Bolivia', 'BO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (23, 'Botswana', 'BW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (24, 'Brazil', 'BR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (25, 'Brunei', 'BN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (26, 'Bulgaria', 'BG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (27, 'Burkina-faso', 'BF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (28, 'Burma', 'MM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (29, 'Burundi', 'BI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (30, 'Cameroon', 'CM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (31, 'Canada', 'CA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (32, 'Central African Republic', 'CF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (33, 'Chad', 'TD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (34, 'Chile', 'CL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (35, 'China', 'CN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (36, 'Colombia', 'CO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (37, 'Congo', 'CG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (38, 'Cook Is.', 'CK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (39, 'Costa Rica', 'CR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (40, 'Cuba', 'CU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (41, 'Cyprus', 'CY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (42, 'Czech Republic', 'CZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (43, 'Denmark', 'DK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (44, 'Djibouti', 'DJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (45, 'Dominica Rep.', 'DO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (46, 'Ecuador', 'EC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (47, 'Egypt', 'EG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (48, 'EI Salvador', 'SV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (49, 'Estonia', 'EE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (50, 'Ethiopia', 'ET', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (51, 'Fiji', 'FJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (52, 'Finland', 'FI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (53, 'France', 'FR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (54, 'French Guiana', 'GF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (55, 'Gabon', 'GA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (56, 'Gambia', 'GM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (57, 'Georgia', 'GE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (58, 'Germany', 'DE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (59, 'Ghana', 'GH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (60, 'Gibraltar', 'GI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (61, 'Greece', 'GR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (62, 'Grenada', 'GD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (63, 'Guam', 'GU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (64, 'Guatemala', 'GT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (65, 'Guinea', 'GN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (66, 'Guyana', 'GY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (67, 'Haiti', 'HT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (68, 'Honduras', 'HN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (69, 'Hongkong', 'HK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (70, 'Hungary', 'HU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (71, 'Iceland', 'IS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (72, 'India', 'IN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (73, 'Indonesia', 'ID', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (74, 'Iran', 'IR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (75, 'Iraq', 'IQ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (76, 'Ireland', 'IE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (77, 'Israel', 'IL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (78, 'Italy', 'IT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (79, 'Jamaica', 'JM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (80, 'Japan', 'JP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (81, 'Jordan', 'JO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (83, 'Kazakstan', 'KZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (84, 'Kenya', 'KE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (85, 'Korea', 'KR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (86, 'Kuwait', 'KW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (87, 'Kyrgyzstan', 'KG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (88, 'Laos', 'LA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (89, 'Latvia', 'LV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (90, 'Lebanon', 'LB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (91, 'Lesotho', 'LS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (92, 'Liberia', 'LR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (93, 'Libya', 'LY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (94, 'Liechtenstein', 'LI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (95, 'Lithuania', 'LT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (96, 'Luxembourg', 'LU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (97, 'Macao', 'MO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (98, 'Madagascar', 'MG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (99, 'Malawi', 'MW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (100, 'Malaysia', 'MY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (101, 'Maldives', 'MV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (102, 'Mali', 'ML', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (103, 'Malta', 'MT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (104, 'Mauritius', 'MU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (105, 'Mexico', 'MX', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (106, 'Moldova, Republic of', 'MD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (107, 'Monaco', 'MC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (108, 'Mongolia', 'MN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (109, 'Montserrat Is', 'MS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (110, 'Morocco', 'MA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (111, 'Mozambique', 'MZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (112, 'Namibia', 'NA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (113, 'Nauru', 'NR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (114, 'Nepal', 'NP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (115, 'Netherlands', 'NL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (116, 'New Zealand', 'NZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (117, 'Nicaragua', 'NI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (118, 'Niger', 'NE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (119, 'Nigeria', 'NG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (120, 'North Korea', 'KP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (121, 'Norway', 'NO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (122, 'Oman', 'OM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (123, 'Pakistan', 'PK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (124, 'Panama', 'PA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (125, 'Papua New Cuinea', 'PG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (126, 'Paraguay', 'PY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (127, 'Peru', 'PE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (128, 'Philippines', 'PH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (129, 'Poland', 'PL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (130, 'French Polynesia', 'PF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (131, 'Portugal', 'PT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (132, 'Puerto Rico', 'PR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (133, 'Qatar', 'QA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (134, 'Romania', 'RO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (135, 'Russia', 'RU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (136, 'Saint Lueia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (137, 'Saint Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (138, 'San Marino', 'SM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (139, 'Sao Tome and Principe', 'ST', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (140, 'Saudi Arabia', 'SA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (141, 'Senegal', 'SN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (142, 'Seychelles', 'SC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (143, 'Sierra Leone', 'SL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (144, 'Singapore', 'SG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (145, 'Slovakia', 'SK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (146, 'Slovenia', 'SI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (147, 'Solomon Is', 'SB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (148, 'Somali', 'SO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (149, 'South Africa', 'ZA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (150, 'Spain', 'ES', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (151, 'Sri Lanka', 'LK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (152, 'St.Lucia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (153, 'St.Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (154, 'Sudan', 'SD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (155, 'Suriname', 'SR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (156, 'Swaziland', 'SZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (157, 'Sweden', 'SE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (158, 'Switzerland', 'CH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (159, 'Syria', 'SY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (160, 'Taiwan', 'TW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (161, 'Tajikstan', 'TJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (162, 'Tanzania', 'TZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (163, 'Thailand', 'TH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (164, 'Togo', 'TG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (165, 'Tonga', 'TO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (166, 'Trinidad and Tobago', 'TT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (167, 'Tunisia', 'TN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (168, 'Turkey', 'TR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (169, 'Turkmenistan', 'TM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (170, 'Uganda', 'UG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (171, 'Ukraine', 'UA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (172, 'United Arab Emirates', 'AE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (173, 'United Kiongdom', 'GB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (174, 'United States of America', 'US', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (175, 'Uruguay', 'UY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (176, 'Uzbekistan', 'UZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (177, 'Venezuela', 'VE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (178, 'Vietnam', 'VN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (179, 'Yemen', 'YE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (180, 'Yugoslavia', 'YU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (181, 'Zimbabwe', 'ZW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (182, 'Zaire', 'ZR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (183, 'Zambia', 'ZM', 1); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/AggregationMapperTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/AggregationMapperTest.java index 5118a378a..ee99357b5 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/AggregationMapperTest.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/AggregationMapperTest.java @@ -21,7 +21,9 @@ public class AggregationMapperTest extends BaseTest { protected Reader getConfigFileAsReader() throws IOException { URL url = getClass().getResource("mybatis-config.xml"); return toReader(url); - }; + } + + ; /** * 获取初始化 sql @@ -31,7 +33,9 @@ protected Reader getConfigFileAsReader() throws IOException { protected Reader getSqlFileAsReader() throws IOException { URL url = getClass().getResource("CreateDB.sql"); return toReader(url); - }; + } + + ; @Test public void testCount() { diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/CreateDB.sql index 17683093f..9c8df0788 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/CreateDB.sql @@ -1,14 +1,21 @@ drop table user if exists; -create table user ( - id integer NOT NULL PRIMARY KEY, - name varchar(32), - role VARCHAR(32) +create table user +( + id integer NOT NULL PRIMARY KEY, + name varchar(32), + role VARCHAR(32) ); -INSERT INTO user (id, name, role) VALUES (1, 'Angola', 'Admin'); -INSERT INTO user (id, name, role) VALUES (2, 'Afghanistan', 'Admin'); -INSERT INTO user (id, name, role) VALUES (3, 'Albania', 'Admin'); -INSERT INTO user (id, name, role) VALUES (4, 'Algeria', 'USER'); -INSERT INTO user (id, name, role) VALUES (5, 'Andorra', 'USER'); -INSERT INTO user (id, name, role) VALUES (6, 'Anguilla', 'USER'); \ No newline at end of file +INSERT INTO user (id, name, role) +VALUES (1, 'Angola', 'Admin'); +INSERT INTO user (id, name, role) +VALUES (2, 'Afghanistan', 'Admin'); +INSERT INTO user (id, name, role) +VALUES (3, 'Albania', 'Admin'); +INSERT INTO user (id, name, role) +VALUES (4, 'Algeria', 'USER'); +INSERT INTO user (id, name, role) +VALUES (5, 'Andorra', 'USER'); +INSERT INTO user (id, name, role) +VALUES (6, 'Anguilla', 'USER'); \ No newline at end of file diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/User.java b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/User.java index 61f6b51ad..35f0c52ea 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/User.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/User.java @@ -34,9 +34,9 @@ public class User implements Serializable { private static final long serialVersionUID = 1L; @Id - private Long id; - private String name; - private String role; + private Long id; + private String name; + private String role; //存储聚合函数值 @Transient private Long aggregation; diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/mybatis-config.xml index ec78ae28c..0644ac38d 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java b/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java index ce37ce38f..57c3c237e 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java @@ -24,7 +24,7 @@ public class Course { @LogicDelete @Column(name = "is_deleted") private Boolean isDeleted; - + public Integer getId() { return id; } diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql index 54d5c95cb..8bfcc83ea 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql @@ -1,14 +1,19 @@ drop table course if exists; -create table course ( - id integer NOT NULL PRIMARY KEY, - name varchar(32), - price integer, - published date, - is_deleted integer +create table course +( + id integer NOT NULL PRIMARY KEY, + name varchar(32), + price integer, + published date, + is_deleted integer ); -INSERT INTO course VALUES (1, 'JavaStarter1', '50', '2015-11-11', '0'); -INSERT INTO course VALUES (2, 'JavaStarter2', '50', '2015-11-11', '0'); -INSERT INTO course VALUES (3, 'Java3', '80', '2017-11-11', '0'); -INSERT INTO course VALUES (4, 'Java4', '100', '2019-11-11', '0'); +INSERT INTO course +VALUES (1, 'JavaStarter1', '50', '2015-11-11', '0'); +INSERT INTO course +VALUES (2, 'JavaStarter2', '50', '2015-11-11', '0'); +INSERT INTO course +VALUES (3, 'Java3', '80', '2017-11-11', '0'); +INSERT INTO course +VALUES (4, 'Java4', '100', '2019-11-11', '0'); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml index e7f4502a1..4d4f1a7f9 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/CreateDB.sql index d9fb36f24..32b321abf 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/CreateDB.sql @@ -1,25 +1,40 @@ --该脚本需手动导入本地Oracle库 -create table demo_country ( - country_id varchar2(50) constraint pk_demo_country__id primary key, - country_name varchar(255) not null, - country_code varchar(255) not null +create table demo_country +( + country_id varchar2 (50) constraint pk_demo_country__id primary key, + country_name varchar(255) not null, + country_code varchar(255) not null ); -create sequence seq_demo_country +create +sequence seq_demo_country minvalue 1 maxvalue 9999999999 - start with 200 + start +with 200 increment by 1; -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (1,'Angola','AO'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (2,'Afghanistan','AF'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (3,'Albania','AL'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (4,'Algeria','DZ'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (5,'Andorra','AD'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (6,'Anguilla','AI'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (7,'Antigua and Barbuda','AG'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (8,'Argentina','AR'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (9,'Armenia','AM'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (10,'Australia','AU'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (11,'Austria','AT'); -INSERT INTO demo_country(country_id, country_name, country_code) VALUES (12,'Azerbaijan','AZ'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (1, 'Angola', 'AO'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (2, 'Afghanistan', 'AF'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (3, 'Albania', 'AL'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (4, 'Algeria', 'DZ'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (5, 'Andorra', 'AD'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (6, 'Anguilla', 'AI'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (7, 'Antigua and Barbuda', 'AG'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (8, 'Argentina', 'AR'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (9, 'Armenia', 'AM'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (10, 'Australia', 'AU'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (11, 'Austria', 'AT'); +INSERT INTO demo_country(country_id, country_name, country_code) +VALUES (12, 'Azerbaijan', 'AZ'); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/OracleTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/OracleTest.java index 4a7a970ac..56381cfd0 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/OracleTest.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/OracleTest.java @@ -50,7 +50,9 @@ public class OracleTest extends BaseTest { protected Reader getConfigFileAsReader() throws IOException { URL url = getClass().getResource("mybatis-config.xml"); return toReader(url); - }; + } + + ; @Override protected void runSql(Reader reader) { @@ -74,9 +76,9 @@ public void testInsertList() { try { DemoCountryMapper mapper = sqlSession.getMapper(DemoCountryMapper.class); List countryList = new ArrayList(); - countryList.add(new DemoCountry("20", "Zimbabwe","ZW")); - countryList.add(new DemoCountry("21", "Zaire","ZR")); - countryList.add(new DemoCountry("22", "Zambia","ZM")); + countryList.add(new DemoCountry("20", "Zimbabwe", "ZW")); + countryList.add(new DemoCountry("21", "Zaire", "ZR")); + countryList.add(new DemoCountry("22", "Zambia", "ZM")); int updates = mapper.insertList(countryList); Assert.assertEquals(3, updates); } finally { diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/mybatis-config.xml index af49d5157..6b96017cb 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/mybatis-config.xml @@ -29,8 +29,8 @@ - - + + @@ -38,10 +38,10 @@ - - - - + + + + diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/idlist/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/idlist/mybatis-config.xml index a8da04b6c..c4abfb1fe 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/idlist/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/idlist/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/CreateDB.sql index f98ce7a94..23039f4cf 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/CreateDB.sql @@ -1,7 +1,8 @@ drop table user if exists; -create table user ( - id varchar(64) NOT NULL PRIMARY KEY, - name varchar(32), - role VARCHAR(32) +create table user +( + id varchar(64) NOT NULL PRIMARY KEY, + name varchar(32), + role VARCHAR(32) ); \ No newline at end of file diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/User.java b/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/User.java index 3f8e476a2..3f04c739c 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/User.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/User.java @@ -36,9 +36,9 @@ public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @KeySql(genId = UUIdGenId.class) - private String id; - private String name; - private String role; + private String id; + private String name; + private String role; public User() { } diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/mybatis-config.xml index d59911b82..3a8d82bed 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/mybatis-config.xml index ec8eb7994..6a869546d 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql index b7a9fc366..4edd8de8d 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql @@ -1,13 +1,18 @@ drop table book if exists; -create table book ( - id integer NOT NULL PRIMARY KEY, - name varchar(32), - price integer, - published date +create table book +( + id integer NOT NULL PRIMARY KEY, + name varchar(32), + price integer, + published date ); -INSERT INTO book VALUES (1, 'JavaStarter1', '50', '2015-11-11'); -INSERT INTO book VALUES (2, 'JavaStarter2', '50', '2015-11-11'); -INSERT INTO book VALUES (3, 'Java3', '80', '2017-11-11'); -INSERT INTO book VALUES (4, 'Java4', '100', '2019-11-11'); +INSERT INTO book +VALUES (1, 'JavaStarter1', '50', '2015-11-11'); +INSERT INTO book +VALUES (2, 'JavaStarter2', '50', '2015-11-11'); +INSERT INTO book +VALUES (3, 'Java3', '80', '2017-11-11'); +INSERT INTO book +VALUES (4, 'Java4', '100', '2019-11-11'); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml index 099e6079d..8dc2a4791 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferMapperTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferMapperTest.java index c6c34c351..4ae990211 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferMapperTest.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferMapperTest.java @@ -20,7 +20,9 @@ public class UpdateByDifferMapperTest extends BaseTest { protected Reader getConfigFileAsReader() throws IOException { URL url = getClass().getResource("mybatis-config.xml"); return toReader(url); - }; + } + + ; @Test diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/update/differ/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/update/differ/mybatis-config.xml index aa01a1e29..5034b2ecf 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/update/differ/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/update/differ/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CountryIntMapper.java b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CountryIntMapper.java index 81c7fe71e..224a137b8 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CountryIntMapper.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CountryIntMapper.java @@ -27,8 +27,8 @@ import tk.mybatis.mapper.common.base.BaseSelectMapper; /** - * @Description: 验证数值空值强制更新 * @author qrqhuangcy + * @Description: 验证数值空值强制更新 * @date 2018-06-25 */ public interface CountryIntMapper extends BaseSelectMapper, UpdateByPrimaryKeySelectiveForceMapper { diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CreateDB.sql b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CreateDB.sql index cd497d7ab..87505da51 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CreateDB.sql +++ b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CreateDB.sql @@ -1,10 +1,12 @@ drop table country_int if exists; -create table country_int ( - id integer NOT NULL PRIMARY KEY, - countryname varchar(32), - countrycode integer +create table country_int +( + id integer NOT NULL PRIMARY KEY, + countryname varchar(32), + countrycode integer ); -INSERT INTO country_int (id, countryname, countrycode) VALUES (174, 'United States of America', 100); +INSERT INTO country_int (id, countryname, countrycode) +VALUES (174, 'United States of America', 100); diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceTest.java b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceTest.java index cb5fe40d6..348e5c3f9 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceTest.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceTest.java @@ -35,8 +35,8 @@ import java.util.Arrays; /** - * @Description: 验证数值空值强制更新 * @author qrqhuangcy + * @Description: 验证数值空值强制更新 * @date 2018-06-25 */ public class UpdateByPrimaryKeySelectiveForceTest extends BaseTest { @@ -49,7 +49,9 @@ public class UpdateByPrimaryKeySelectiveForceTest extends BaseTest { protected Reader getConfigFileAsReader() throws IOException { URL url = getClass().getResource("mybatis-config.xml"); return toReader(url); - }; + } + + ; /** * 获取初始化 sql @@ -94,4 +96,4 @@ public void testUpdateByPrimaryKeySelectiveForce() { sqlSession.close(); } } - } +} diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/mybatis-config.xml b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/mybatis-config.xml index b9fc6e820..a186e4a2a 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/mybatis-config.xml +++ b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/mybatis-config.xml @@ -29,7 +29,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/extra/src/test/resources/log4j.properties b/extra/src/test/resources/log4j.properties deleted file mode 100644 index b56b8a94e..000000000 --- a/extra/src/test/resources/log4j.properties +++ /dev/null @@ -1,35 +0,0 @@ -# -# The MIT License (MIT) -# -# Copyright (c) 2014-2017 abel533@gmail.com -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -log4j.rootLogger=INFO, stdout - -log4j.logger.tk.mybatis.mapper=DEBUG -log4j.logger.org.apache.ibatis=DEBUG - -log4j.logger.tk.mybatis.mapper.common = TRACE - -### Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n \ No newline at end of file diff --git a/extra/src/test/resources/logback.xml b/extra/src/test/resources/logback.xml new file mode 100644 index 000000000..3b71bf41f --- /dev/null +++ b/extra/src/test/resources/logback.xml @@ -0,0 +1,10 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + \ No newline at end of file diff --git a/generator/README.md b/generator/README.md index a2a73f519..3dd4657a1 100644 --- a/generator/README.md +++ b/generator/README.md @@ -16,7 +16,6 @@ 代码生成器的配置在 `generatorConfig.xml` 中。 - # 代码生成器文档 代码生成器是基于 MBG 插件的,所以需要配合 MBG 使用。 @@ -71,6 +70,7 @@ ``` + 在这个配置中,我们只关注 `tk.mybatis.mapper.generator.TemplateFilePlugin`。 ## 基于模板的插件 `TemplateFilePlugin` @@ -96,8 +96,7 @@ ### 1. `targetProject` -用于指定目标项目,一般是 `src/main/java` 或者 `src/main/resource` 这样的目录。 -还可以是 `src/test/java` 或者 `src/test/resource` 这样的目录。 +用于指定目标项目,一般是 `src/main/java` 或者 `src/main/resource` 这样的目录。 还可以是 `src/test/java` 或者 `src/test/resource` 这样的目录。 在多模块项目中,还能通过相对路径指定为其他的目录,例如: @@ -119,7 +118,7 @@ 这个属性还有一个特殊的地方,它还支持使用模板,就和下面的 `fileName` 一样,举个简单的使用场景。 ->你可能在生成前端代码的时候,希望将表对应的 JSP 生成在自己的一个目录中,此时可以配置为: +> 你可能在生成前端代码的时候,希望将表对应的 JSP 生成在自己的一个目录中,此时可以配置为: > >`` > @@ -185,7 +184,7 @@ 因为一个模板只能生成一类的文件,所以如果要生成多个不同的文件,就需要配置多个插件。 ->这种设计很灵活,因为自由度很高,所以代价就是配置的多。 +> 这种设计很灵活,因为自由度很高,所以代价就是配置的多。 > >但是正常情况下,根据业务设计的一套模板基本是固定的,不会有太多变化,所以用起来并不麻烦。 @@ -230,8 +229,8 @@ ``` -前两个会生成 Dao 后缀的 Mapper 接口和 XML,其中有个针对性的参数 `mapperSuffix` 用于配置后缀, -还有个 `mapperPackage` 在生成 XML 时获取接口的包名(因为和这里的 `targetPackage` 可以不同)。 +前两个会生成 Dao 后缀的 Mapper 接口和 XML,其中有个针对性的参数 `mapperSuffix` 用于配置后缀, 还有个 `mapperPackage` 在生成 XML +时获取接口的包名(因为和这里的 `targetPackage` 可以不同)。 后两个插件用于演示所有可用的属性,而且是两种不同的模式。 @@ -354,6 +353,7 @@ Blob列: 测试生成的**部分**结果如下。 实体: + ```java @Table(name = "`user_info`") public class UserInfo { @@ -364,6 +364,7 @@ public class UserInfo { ``` Dao: + ```java package test.mapper; @@ -380,6 +381,7 @@ public interface UserInfoDao extends tk.mybatis.mapper.common.Mapper { ``` XML: + ```xml 项目的发展离不开你的支持,请作者喝杯咖啡吧! +> 项目的发展离不开你的支持,请作者喝杯咖啡吧! > >支付宝 > diff --git a/generator/pom.xml b/generator/pom.xml index 3febfa83a..906a28216 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.1 + 4.2.2-SNAPSHOT mapper-generator jar @@ -37,7 +37,7 @@ Mybatis 通用 Mapper 代码生成器 - 4.2.1 + 4.2.2-SNAPSHOT 2.3.28 1.3.7 @@ -75,7 +75,7 @@ javax.persistence - persistence-api + javax.persistence-api test diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java index 3d9156a50..a690e1f79 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java @@ -71,34 +71,34 @@ public class TemplateFilePlugin extends PluginAdapter { /** * 单个文件模式 */ - private String singleMode; + private String singleMode; /** * 项目路径(目录需要已经存在) */ - private String targetProject; + private String targetProject; /** * 生成的包(路径不存在则创建) */ - private String targetPackage; + private String targetPackage; /** * 模板路径 */ - private String templatePath; + private String templatePath; /** * 模板内容 */ - private String templateContent; + private String templateContent; /** * 文件名模板,通过模板方式生成文件名,包含后缀 */ - private String fileName; + private String fileName; /** * 模板生成器 */ - private Object templateFormatter; - private String templateFormatterClass; + private Object templateFormatter; + private String templateFormatterClass; private Set cacheTables; - + /** * 编码 */ diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/formatter/FreemarkerTemplateFormatter.java b/generator/src/main/java/tk/mybatis/mapper/generator/formatter/FreemarkerTemplateFormatter.java index cf96809d6..70bebde48 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/formatter/FreemarkerTemplateFormatter.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/formatter/FreemarkerTemplateFormatter.java @@ -42,7 +42,7 @@ * @since 3.4.5 */ public class FreemarkerTemplateFormatter implements TemplateFormatter, ListTemplateFormatter { - private final Configuration configuration = new Configuration(Configuration.VERSION_2_3_23); + private final Configuration configuration = new Configuration(Configuration.VERSION_2_3_23); private final StringTemplateLoader templateLoader = new StringTemplateLoader(); public FreemarkerTemplateFormatter() { diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/model/ColumnField.java b/generator/src/main/java/tk/mybatis/mapper/generator/model/ColumnField.java index bda744062..95097c186 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/model/ColumnField.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/model/ColumnField.java @@ -35,25 +35,25 @@ public class ColumnField implements Serializable { private static final long serialVersionUID = -435113788623615260L; - private TableClass tableClass; - private String columnName; - private String jdbcType; - private String fieldName; - private String remarks; + private TableClass tableClass; + private String columnName; + private String jdbcType; + private String fieldName; + private String remarks; private FullyQualifiedJavaType type; - private String typePackage; - private String shortTypeName; - private String fullTypeName; - private boolean identity; - private boolean nullable; - private boolean blobColumn; - private boolean stringColumn; - private boolean jdbcCharacterColumn; - private boolean jdbcDateColumn; - private boolean jdbcTimeColumn; - private boolean sequenceColumn; - private int length; - private int scale; + private String typePackage; + private String shortTypeName; + private String fullTypeName; + private boolean identity; + private boolean nullable; + private boolean blobColumn; + private boolean stringColumn; + private boolean jdbcCharacterColumn; + private boolean jdbcDateColumn; + private boolean jdbcTimeColumn; + private boolean sequenceColumn; + private int length; + private int scale; public String getColumnName() { return columnName; diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/model/TableClass.java b/generator/src/main/java/tk/mybatis/mapper/generator/model/TableClass.java index 2668bc5d1..a51f74106 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/model/TableClass.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/model/TableClass.java @@ -39,12 +39,12 @@ public class TableClass implements Serializable { private IntrospectedTable introspectedTable; - private String tableName; - private String variableName; - private String lowerCaseName; - private String shortClassName; - private String fullClassName; - private String packageName; + private String tableName; + private String variableName; + private String lowerCaseName; + private String shortClassName; + private String fullClassName; + private String packageName; private FullyQualifiedJavaType type; private List pkFields; diff --git a/generator/src/main/resources/generator/test-all.ftl b/generator/src/main/resources/generator/test-all.ftl index 921153865..8fbafe9c8 100644 --- a/generator/src/main/resources/generator/test-all.ftl +++ b/generator/src/main/resources/generator/test-all.ftl @@ -9,104 +9,104 @@ ${dateTime?string["yyyy-MM-dd HH:mm:ss"]} 所有配置的属性信息: <#list props?keys as key> -${key} - ${props[key]} + ${key} - ${props[key]} <#list tableClassSet as tableClass> -**************************************************************************************** -实体和表的信息: -表名:${tableClass.tableName} -变量名:${tableClass.variableName} -小写名:${tableClass.lowerCaseName} -类名:${tableClass.shortClassName} -全名:${tableClass.fullClassName} -包名:${tableClass.packageName} + **************************************************************************************** + 实体和表的信息: + 表名:${tableClass.tableName} + 变量名:${tableClass.variableName} + 小写名:${tableClass.lowerCaseName} + 类名:${tableClass.shortClassName} + 全名:${tableClass.fullClassName} + 包名:${tableClass.packageName} -列的信息: -===================================== + 列的信息: + ===================================== <#if tableClass.pkFields??> - 主键: + 主键: <#list tableClass.pkFields as field> - ------------------------------------- - 列名:${field.columnName} - 列类型:${field.jdbcType} - 字段名:${field.fieldName} - <#if field.remarks??> - 注释:${field.remarks} - - 类型包名:${field.typePackage} - 类型短名:${field.shortTypeName} - 类型全名:${field.fullTypeName} - 是否主键:${field.identity?c} - 是否可空:${field.nullable?c} - 是否为BLOB列:${field.blobColumn?c} - 是否为String列:${field.stringColumn?c} - 是否为字符串列:${field.jdbcCharacterColumn?c} - 是否为日期列:${field.jdbcDateColumn?c} - 是否为时间列:${field.jdbcTimeColumn?c} - 是否为序列列:${field.sequenceColumn?c} - 列长度:${field.length?c} - 列精度:${field.scale} + ------------------------------------- + 列名:${field.columnName} + 列类型:${field.jdbcType} + 字段名:${field.fieldName} + <#if field.remarks??> + 注释:${field.remarks} + + 类型包名:${field.typePackage} + 类型短名:${field.shortTypeName} + 类型全名:${field.fullTypeName} + 是否主键:${field.identity?c} + 是否可空:${field.nullable?c} + 是否为BLOB列:${field.blobColumn?c} + 是否为String列:${field.stringColumn?c} + 是否为字符串列:${field.jdbcCharacterColumn?c} + 是否为日期列:${field.jdbcDateColumn?c} + 是否为时间列:${field.jdbcTimeColumn?c} + 是否为序列列:${field.sequenceColumn?c} + 列长度:${field.length?c} + 列精度:${field.scale} <#if tableClass.baseFields??> - 基础列: + 基础列: <#list tableClass.baseFields as field> - ------------------------------------- - 列名:${field.columnName} - 列类型:${field.jdbcType} - 字段名:${field.fieldName} - <#if field.remarks??> - 注释:${field.remarks} - - 类型包名:${field.typePackage} - 类型短名:${field.shortTypeName} - 类型全名:${field.fullTypeName} - 是否主键:${field.identity?c} - 是否可空:${field.nullable?c} - 是否为BLOB列:${field.blobColumn?c} - 是否为String列:${field.stringColumn?c} - 是否为字符串列:${field.jdbcCharacterColumn?c} - 是否为日期列:${field.jdbcDateColumn?c} - 是否为时间列:${field.jdbcTimeColumn?c} - 是否为序列列:${field.sequenceColumn?c} - 列长度:${field.length?c} - 列精度:${field.scale} + ------------------------------------- + 列名:${field.columnName} + 列类型:${field.jdbcType} + 字段名:${field.fieldName} + <#if field.remarks??> + 注释:${field.remarks} + + 类型包名:${field.typePackage} + 类型短名:${field.shortTypeName} + 类型全名:${field.fullTypeName} + 是否主键:${field.identity?c} + 是否可空:${field.nullable?c} + 是否为BLOB列:${field.blobColumn?c} + 是否为String列:${field.stringColumn?c} + 是否为字符串列:${field.jdbcCharacterColumn?c} + 是否为日期列:${field.jdbcDateColumn?c} + 是否为时间列:${field.jdbcTimeColumn?c} + 是否为序列列:${field.sequenceColumn?c} + 列长度:${field.length?c} + 列精度:${field.scale} <#if tableClass.blobFields??> - Blob列: + Blob列: <#list tableClass.blobFields as field> - ------------------------------------- - 列名:${field.columnName} - 列类型:${field.jdbcType} - 字段名:${field.fieldName} - <#if field.remarks??> - 注释:${field.remarks} - - 类型包名:${field.typePackage} - 类型短名:${field.shortTypeName} - 类型全名:${field.fullTypeName} - 是否主键:${field.identity?c} - 是否可空:${field.nullable?c} - 是否为BLOB列:${field.blobColumn?c} - 是否为String列:${field.stringColumn?c} - 是否为字符串列:${field.jdbcCharacterColumn?c} - 是否为日期列:${field.jdbcDateColumn?c} - 是否为时间列:${field.jdbcTimeColumn?c} - 是否为序列列:${field.sequenceColumn?c} - 列长度:${field.length?c} - 列精度:${field.scale} + ------------------------------------- + 列名:${field.columnName} + 列类型:${field.jdbcType} + 字段名:${field.fieldName} + <#if field.remarks??> + 注释:${field.remarks} + + 类型包名:${field.typePackage} + 类型短名:${field.shortTypeName} + 类型全名:${field.fullTypeName} + 是否主键:${field.identity?c} + 是否可空:${field.nullable?c} + 是否为BLOB列:${field.blobColumn?c} + 是否为String列:${field.stringColumn?c} + 是否为字符串列:${field.jdbcCharacterColumn?c} + 是否为日期列:${field.jdbcDateColumn?c} + 是否为时间列:${field.jdbcTimeColumn?c} + 是否为序列列:${field.sequenceColumn?c} + 列长度:${field.length?c} + 列精度:${field.scale} -===================================== -全部列: + ===================================== + 全部列: <#if tableClass.allFields??> - 列名 - 字段名 + 列名 - 字段名 <#list tableClass.allFields as field> - ${field.columnName} - ${field.fieldName} + ${field.columnName} - ${field.fieldName} \ No newline at end of file diff --git a/generator/src/main/resources/generator/test-one.ftl b/generator/src/main/resources/generator/test-one.ftl index b8cbb4a24..a26505448 100644 --- a/generator/src/main/resources/generator/test-one.ftl +++ b/generator/src/main/resources/generator/test-one.ftl @@ -8,7 +8,7 @@ ${dateTime?string["yyyy-MM-dd HH:mm:ss"]} 所有配置的属性信息: <#list props?keys as key> -${key} - ${props[key]} + ${key} - ${props[key]} 实体和表的信息: @@ -22,88 +22,88 @@ ${key} - ${props[key]} 列的信息: ===================================== <#if tableClass.pkFields??> -主键: + 主键: <#list tableClass.pkFields as field> - ------------------------------------- - 列名:${field.columnName} - 列类型:${field.jdbcType} - 字段名:${field.fieldName} - <#if field.remarks??> - 注释:${field.remarks} - - 类型包名:${field.typePackage} - 类型短名:${field.shortTypeName} - 类型全名:${field.fullTypeName} - 是否主键:${field.identity?c} - 是否可空:${field.nullable?c} - 是否为BLOB列:${field.blobColumn?c} - 是否为String列:${field.stringColumn?c} - 是否为字符串列:${field.jdbcCharacterColumn?c} - 是否为日期列:${field.jdbcDateColumn?c} - 是否为时间列:${field.jdbcTimeColumn?c} - 是否为序列列:${field.sequenceColumn?c} - 列长度:${field.length?c} - 列精度:${field.scale} + ------------------------------------- + 列名:${field.columnName} + 列类型:${field.jdbcType} + 字段名:${field.fieldName} + <#if field.remarks??> + 注释:${field.remarks} + + 类型包名:${field.typePackage} + 类型短名:${field.shortTypeName} + 类型全名:${field.fullTypeName} + 是否主键:${field.identity?c} + 是否可空:${field.nullable?c} + 是否为BLOB列:${field.blobColumn?c} + 是否为String列:${field.stringColumn?c} + 是否为字符串列:${field.jdbcCharacterColumn?c} + 是否为日期列:${field.jdbcDateColumn?c} + 是否为时间列:${field.jdbcTimeColumn?c} + 是否为序列列:${field.sequenceColumn?c} + 列长度:${field.length?c} + 列精度:${field.scale} <#if tableClass.baseFields??> -基础列: + 基础列: <#list tableClass.baseFields as field> - ------------------------------------- - 列名:${field.columnName} - 列类型:${field.jdbcType} - 字段名:${field.fieldName} - <#if field.remarks??> - 注释:${field.remarks} - - 类型包名:${field.typePackage} - 类型短名:${field.shortTypeName} - 类型全名:${field.fullTypeName} - 是否主键:${field.identity?c} - 是否可空:${field.nullable?c} - 是否为BLOB列:${field.blobColumn?c} - 是否为String列:${field.stringColumn?c} - 是否为字符串列:${field.jdbcCharacterColumn?c} - 是否为日期列:${field.jdbcDateColumn?c} - 是否为时间列:${field.jdbcTimeColumn?c} - 是否为序列列:${field.sequenceColumn?c} - 列长度:${field.length?c} - 列精度:${field.scale} + ------------------------------------- + 列名:${field.columnName} + 列类型:${field.jdbcType} + 字段名:${field.fieldName} + <#if field.remarks??> + 注释:${field.remarks} + + 类型包名:${field.typePackage} + 类型短名:${field.shortTypeName} + 类型全名:${field.fullTypeName} + 是否主键:${field.identity?c} + 是否可空:${field.nullable?c} + 是否为BLOB列:${field.blobColumn?c} + 是否为String列:${field.stringColumn?c} + 是否为字符串列:${field.jdbcCharacterColumn?c} + 是否为日期列:${field.jdbcDateColumn?c} + 是否为时间列:${field.jdbcTimeColumn?c} + 是否为序列列:${field.sequenceColumn?c} + 列长度:${field.length?c} + 列精度:${field.scale} <#if tableClass.blobFields??> -Blob列: + Blob列: <#list tableClass.blobFields as field> - ------------------------------------- - 列名:${field.columnName} - 列类型:${field.jdbcType} - 字段名:${field.fieldName} - <#if field.remarks??> - 注释:${field.remarks} - - 类型包名:${field.typePackage} - 类型短名:${field.shortTypeName} - 类型全名:${field.fullTypeName} - 是否主键:${field.identity?c} - 是否可空:${field.nullable?c} - 是否为BLOB列:${field.blobColumn?c} - 是否为String列:${field.stringColumn?c} - 是否为字符串列:${field.jdbcCharacterColumn?c} - 是否为日期列:${field.jdbcDateColumn?c} - 是否为时间列:${field.jdbcTimeColumn?c} - 是否为序列列:${field.sequenceColumn?c} - 列长度:${field.length?c} - 列精度:${field.scale} + ------------------------------------- + 列名:${field.columnName} + 列类型:${field.jdbcType} + 字段名:${field.fieldName} + <#if field.remarks??> + 注释:${field.remarks} + + 类型包名:${field.typePackage} + 类型短名:${field.shortTypeName} + 类型全名:${field.fullTypeName} + 是否主键:${field.identity?c} + 是否可空:${field.nullable?c} + 是否为BLOB列:${field.blobColumn?c} + 是否为String列:${field.stringColumn?c} + 是否为字符串列:${field.jdbcCharacterColumn?c} + 是否为日期列:${field.jdbcDateColumn?c} + 是否为时间列:${field.jdbcTimeColumn?c} + 是否为序列列:${field.sequenceColumn?c} + 列长度:${field.length?c} + 列精度:${field.scale} ===================================== 全部列: <#if tableClass.allFields??> -列名 - 字段名 + 列名 - 字段名 <#list tableClass.allFields as field> - ${field.columnName} - ${field.fieldName} + ${field.columnName} - ${field.fieldName} \ No newline at end of file diff --git a/generator/src/test/java/tk/mybatis/mapper/generator/Generator.java b/generator/src/test/java/tk/mybatis/mapper/generator/Generator.java index 8ec0e22f4..8fdbfa863 100644 --- a/generator/src/test/java/tk/mybatis/mapper/generator/Generator.java +++ b/generator/src/test/java/tk/mybatis/mapper/generator/Generator.java @@ -33,7 +33,8 @@ import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; import java.util.ArrayList; import java.util.List; @@ -42,7 +43,7 @@ */ public class Generator { - public static void startDB(){ + public static void startDB() { try { Class.forName("org.hsqldb.jdbcDriver"); } catch (ClassNotFoundException e) { @@ -65,7 +66,7 @@ public static void startDB(){ } } - public static InputStream getResourceAsStream(String path){ + public static InputStream getResourceAsStream(String path) { return Thread.currentThread().getContextClassLoader().getResourceAsStream(path); } diff --git a/generator/src/test/resources/CreateDB.sql b/generator/src/test/resources/CreateDB.sql index 66958a2f6..f2133419a 100644 --- a/generator/src/test/resources/CreateDB.sql +++ b/generator/src/test/resources/CreateDB.sql @@ -1,44 +1,63 @@ drop table country if exists; -create table country ( - id integer NOT NULL PRIMARY KEY, - countryname varchar(32), - countrycode VARCHAR(2) DEFAULT 'HH', - decimal_num decimal (10,5) DEFAULT 0.1, - version INTEGER DEFAULT 1 NOT NULL +create table country +( + id integer NOT NULL PRIMARY KEY, + countryname varchar(32), + countrycode VARCHAR(2) DEFAULT 'HH', + decimal_num decimal(10, 5) DEFAULT 0.1, + version INTEGER DEFAULT 1 NOT NULL ); drop table user_info if exists; --用户信息表 -create table user_info ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, - username varchar(32) NOT NULL, - password varchar(32) DEFAULT '12345678', - usertype varchar(2), - enabled integer, - realname varchar(50), - qq varchar(12), - email varchar(100), - address varchar(200), - tel varchar(30) +create table user_info +( + id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, + username varchar(32) NOT NULL, + password varchar(32) DEFAULT '12345678', + usertype varchar(2), + enabled integer, + realname varchar(50), + qq varchar(12), + email varchar(100), + address varchar(200), + tel varchar(30) ); -insert into user_info (id,username,password,usertype) values (1,'test1','12345678','1'); -insert into user_info (id,username,password,usertype) values (2,'test2','aaaa','2'); -insert into user_info (id,username,password,usertype) values (3,'test3','bbbb','1'); -insert into user_info (id,username,password,usertype) values (4,'test4','cccc','2'); -insert into user_info (id,username,password,usertype) values (5,'test5','dddd','1'); +insert into user_info (id, username, password, usertype) +values (1, 'test1', '12345678', '1'); +insert into user_info (id, username, password, usertype) +values (2, 'test2', 'aaaa', '2'); +insert into user_info (id, username, password, usertype) +values (3, 'test3', 'bbbb', '1'); +insert into user_info (id, username, password, usertype) +values (4, 'test4', 'cccc', '2'); +insert into user_info (id, username, password, usertype) +values (5, 'test5', 'dddd', '1'); -INSERT INTO country (id, countryname, countrycode, version) VALUES (1, 'Angola', 'AO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (2, 'Afghanistan', 'AF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (3, 'Albania', 'AL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (4, 'Algeria', 'DZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (5, 'Andorra', 'AD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (6, 'Anguilla', 'AI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (7, 'Antigua and Barbuda', 'AG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (8, 'Argentina', 'AR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (9, 'Armenia', 'AM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (10, 'Australia', 'AU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (11, 'Austria', 'AT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (12, 'Azerbaijan', 'AZ', 1); \ No newline at end of file +INSERT INTO country (id, countryname, countrycode, version) +VALUES (1, 'Angola', 'AO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (2, 'Afghanistan', 'AF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (3, 'Albania', 'AL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (4, 'Algeria', 'DZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (5, 'Andorra', 'AD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (6, 'Anguilla', 'AI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (7, 'Antigua and Barbuda', 'AG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (8, 'Argentina', 'AR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (9, 'Armenia', 'AM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (10, 'Australia', 'AU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (11, 'Austria', 'AT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (12, 'Azerbaijan', 'AZ', 1); \ No newline at end of file diff --git a/generator/src/test/resources/generatorConfig.xml b/generator/src/test/resources/generatorConfig.xml index d913aea66..f5988c5aa 100644 --- a/generator/src/test/resources/generatorConfig.xml +++ b/generator/src/test/resources/generatorConfig.xml @@ -41,10 +41,10 @@ - - - - + + + + diff --git a/pom.xml b/pom.xml index 27a03a2c9..d84254b36 100644 --- a/pom.xml +++ b/pom.xml @@ -28,10 +28,11 @@ tk.mybatis mapper-parent - 3 + 8 + mapper-modules - 4.2.1 + 4.2.2-SNAPSHOT pom mapper-parent @@ -57,8 +58,8 @@ scm:git@github.com:abel533/mapper.git git@github.com:abel533/mapper.git - - + + all base core diff --git a/spring-boot-starter/README.md b/spring-boot-starter/README.md index 307bd7acb..678f43ac6 100644 --- a/spring-boot-starter/README.md +++ b/spring-boot-starter/README.md @@ -7,9 +7,11 @@ Mapper-Spring-Boot-Starter 帮助你集成通用 Mapper 到 Spring Boot。 Mapper-Spring-Boot-Starter will help you use Mapper with Spring Boot. ## How to use + 在 pom.xml 中添加如下依赖: -Add the following dependency to your pom.xml: +Add the following dependency to your pom.xml: + ```xml tk.mybatis @@ -30,17 +32,18 @@ Add the following dependency to your pom.xml: ## 1.2.1 - 2018-01-10 -- 为了增强兼容性,`MapperAutoConfiguration` 增加 `@AutoConfigureBefore(name = "org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration")` -即使依赖中存在 MyBatis 的 starter,Mapper 也可以优先使用自动配置,MyBatis后续就不会触发生成 `@Bean` +- 为了增强兼容性,`MapperAutoConfiguration` + 增加 `@AutoConfigureBefore(name = "org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration")` + 即使依赖中存在 MyBatis 的 starter,Mapper 也可以优先使用自动配置,MyBatis后续就不会触发生成 `@Bean` - 支持简单的 relax 绑定,例如 not-empty 会转换为 notEmpty 使用,兼容 spring boot 配置方式 - ## 1.2.0 - 2018-01-08 - 通用 Mapper 3.5.0 - 去掉 mybatis-spring-boot-starter 依赖,不在使用 mybatis 官方 starter,使用通用 Mapper 时不要再引入官方 starter -- 参考 mybatis 官方 starter 重新实现,解决 mapper 初始化可能存在的问题 [pr#5 by fengcbo](https://github.com/abel533/mapper-boot-starter/pull/5) +- 参考 mybatis 官方 starter 重新实现,解决 mapper + 初始化可能存在的问题 [pr#5 by fengcbo](https://github.com/abel533/mapper-boot-starter/pull/5) - 如果需要使用 `@MapperScan` 请选择 tk 开头的 `tk.mybatis.spring.annotation.MapperScan` ## 1.1.7 - 2017-12-17 @@ -87,9 +90,11 @@ Add the following dependency to your pom.xml: - spring-boot 升级到 1.4.4.RELEASE ## Example ->https://github.com/abel533/MyBatis-Spring-Boot + +> https://github.com/abel533/MyBatis-Spring-Boot ## Special Configurations + 一般情况下,你不需要做任何配置。 Normally, you don't need to do any configuration. @@ -99,22 +104,27 @@ Normally, you don't need to do any configuration. You can config PageHelper as the following: application.properties: + ```properties mapper.propertyName=propertyValue ``` 示例: + ```properties mapper.mappers[0]=tk.mybatis.sample.mapper.BaseMapper mapper.mappers[1]=tk.mybatis.mapper.common.Mapper ``` + 默认情况下,没有 mappers 配置时,会自动注册 `tk.mybatis.mapper.common.Mapper` -因为通用 Mapper 是固定的属性,所以接收参数使用的对象,按照 Spring Boot 配置规则,大写字母都变了带横线的小写字母。针对如 IDENTITY(对应i-d-e-n-t-i-t-y)提供了全小写的 identity 配置,如果 IDE 能自动提示,看自动提示即可。 +因为通用 Mapper 是固定的属性,所以接收参数使用的对象,按照 Spring Boot 配置规则,大写字母都变了带横线的小写字母。针对如 IDENTITY(对应i-d-e-n-t-i-t-y)提供了全小写的 identity 配置,如果 +IDE 能自动提示,看自动提示即可。 -IDE 应该可以自动提示: +IDE 应该可以自动提示: ![自动提示属性](properties.png) ## MyBatis Mapper ->https://github.com/abel533/Mapper + +> https://github.com/abel533/Mapper diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml index ce16e92d6..75e36e1e4 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.1 + 4.2.2-SNAPSHOT mapper-spring-boot-autoconfigure mapper-spring-boot-autoconfigure diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/ConfigurationCustomizer.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/ConfigurationCustomizer.java index 80c40ef67..9e46157b9 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/ConfigurationCustomizer.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/ConfigurationCustomizer.java @@ -1,17 +1,17 @@ /** - * Copyright 2015-2017 the original author or authors. - * - * 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. + * Copyright 2015-2017 the original author or authors. + *

+ * 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 tk.mybatis.mapper.autoconfigure; @@ -25,10 +25,11 @@ */ public interface ConfigurationCustomizer { - /** - * Customize the given a {@link Configuration} object. - * @param configuration the configuration object to customize - */ - void customize(Configuration configuration); + /** + * Customize the given a {@link Configuration} object. + * + * @param configuration the configuration object to customize + */ + void customize(Configuration configuration); } diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java index ae8c2e7ea..2f4631c4c 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java @@ -1,17 +1,17 @@ /** - * Copyright 2015-2018 the original author or authors. - * - * 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. + * Copyright 2015-2018 the original author or authors. + *

+ * 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 tk.mybatis.mapper.autoconfigure; @@ -78,7 +78,7 @@ * @author Eduardo Macarrón */ @org.springframework.context.annotation.Configuration -@ConditionalOnClass({ SqlSessionFactory.class, SqlSessionFactoryBean.class }) +@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class}) @ConditionalOnSingleCandidate(DataSource.class) @EnableConfigurationProperties(MybatisProperties.class) @AutoConfigureAfter(DataSourceAutoConfiguration.class) @@ -98,10 +98,10 @@ public class MapperAutoConfiguration implements InitializingBean { private final List configurationCustomizers; public MapperAutoConfiguration(MybatisProperties properties, - ObjectProvider interceptorsProvider, - ResourceLoader resourceLoader, - ObjectProvider databaseIdProvider, - ObjectProvider> configurationCustomizersProvider) { + ObjectProvider interceptorsProvider, + ResourceLoader resourceLoader, + ObjectProvider databaseIdProvider, + ObjectProvider> configurationCustomizersProvider) { this.properties = properties; this.interceptors = interceptorsProvider.getIfAvailable(); this.resourceLoader = resourceLoader; @@ -215,7 +215,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B } } BaseProperties properties = SpringBootBindUtil.bind(environment, BaseProperties.class, BaseProperties.MYBATIS_PREFIX); - if(properties != null && properties.getBasePackages() != null && properties.getBasePackages().length > 0){ + if (properties != null && properties.getBasePackages() != null && properties.getBasePackages().length > 0) { packages.addAll(Arrays.asList(properties.getBasePackages())); } else { //设置了包名的情况下,不需要指定该注解 @@ -253,7 +253,7 @@ public void setResourceLoader(ResourceLoader resourceLoader) { * on the same component-scanning path as Spring Boot itself. */ @org.springframework.context.annotation.Configuration - @Import({ AutoConfiguredMapperScannerRegistrar.class }) + @Import({AutoConfiguredMapperScannerRegistrar.class}) @ConditionalOnMissingBean(MapperFactoryBean.class) public static class MapperScannerRegistrarNotFoundConfiguration implements InitializingBean { diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisProperties.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisProperties.java index 9fcfe087b..33130ffa6 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisProperties.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisProperties.java @@ -1,17 +1,17 @@ /** - * Copyright 2015-2017 the original author or authors. - * - * 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. + * Copyright 2015-2017 the original author or authors. + *

+ * 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 tk.mybatis.mapper.autoconfigure; @@ -39,172 +39,172 @@ @ConfigurationProperties(prefix = BaseProperties.MYBATIS_PREFIX) public class MybatisProperties extends BaseProperties { - private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); - - /** - * Location of MyBatis xml config file. - */ - private String configLocation; - - /** - * Locations of MyBatis mapper files. - */ - private String[] mapperLocations; - - /** - * Packages to search type aliases. (Package delimiters are ",; \t\n") - */ - private String typeAliasesPackage; - - /** - * The super class for filtering type alias. - * If this not specifies, the MyBatis deal as type alias all classes that searched from typeAliasesPackage. - */ - private Class typeAliasesSuperType; - - /** - * Packages to search for type handlers. (Package delimiters are ",; \t\n") - */ - private String typeHandlersPackage; - - /** - * Indicates whether perform presence check of the MyBatis xml config file. - */ - private boolean checkConfigLocation = false; - - /** - * Execution mode for {@link org.mybatis.spring.SqlSessionTemplate}. - */ - private ExecutorType executorType; - - /** - * Externalized properties for MyBatis configuration. - */ - private Properties configurationProperties; - - /** - * A Configuration object for customize default settings. If {@link #configLocation} - * is specified, this property is not used. - */ - @NestedConfigurationProperty - private Configuration configuration; - - /** - * @since 1.1.0 - */ - public String getConfigLocation() { - return this.configLocation; - } - - /** - * @since 1.1.0 - */ - public void setConfigLocation(String configLocation) { - this.configLocation = configLocation; - } - - @Deprecated - public String getConfig() { - return this.configLocation; - } - - @Deprecated - public void setConfig(String config) { - this.configLocation = config; - } - - public String[] getMapperLocations() { - return this.mapperLocations; - } - - public void setMapperLocations(String[] mapperLocations) { - this.mapperLocations = mapperLocations; - } - - public String getTypeHandlersPackage() { - return this.typeHandlersPackage; - } - - public void setTypeHandlersPackage(String typeHandlersPackage) { - this.typeHandlersPackage = typeHandlersPackage; - } - - public String getTypeAliasesPackage() { - return this.typeAliasesPackage; - } - - public void setTypeAliasesPackage(String typeAliasesPackage) { - this.typeAliasesPackage = typeAliasesPackage; - } - - /** - * @since 1.3.3 - */ - public Class getTypeAliasesSuperType() { - return typeAliasesSuperType; - } - - /** - * @since 1.3.3 - */ - public void setTypeAliasesSuperType(Class typeAliasesSuperType) { - this.typeAliasesSuperType = typeAliasesSuperType; - } - - public boolean isCheckConfigLocation() { - return this.checkConfigLocation; - } - - public void setCheckConfigLocation(boolean checkConfigLocation) { - this.checkConfigLocation = checkConfigLocation; - } - - public ExecutorType getExecutorType() { - return this.executorType; - } - - public void setExecutorType(ExecutorType executorType) { - this.executorType = executorType; - } - - /** - * @since 1.2.0 - */ - public Properties getConfigurationProperties() { - return configurationProperties; - } - - /** - * @since 1.2.0 - */ - public void setConfigurationProperties(Properties configurationProperties) { - this.configurationProperties = configurationProperties; - } - - public Configuration getConfiguration() { - return configuration; - } - - public void setConfiguration(Configuration configuration) { - this.configuration = configuration; - } - - public Resource[] resolveMapperLocations() { - List resources = new ArrayList(); - if (this.mapperLocations != null) { - for (String mapperLocation : this.mapperLocations) { - resources.addAll(Arrays.asList(getResources(mapperLocation))); - } - } - return resources.toArray(new Resource[resources.size()]); - } - - private Resource[] getResources(String location) { - try { - return resourceResolver.getResources(location); - } catch (IOException e) { - return new Resource[0]; - } - } + private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); + + /** + * Location of MyBatis xml config file. + */ + private String configLocation; + + /** + * Locations of MyBatis mapper files. + */ + private String[] mapperLocations; + + /** + * Packages to search type aliases. (Package delimiters are ",; \t\n") + */ + private String typeAliasesPackage; + + /** + * The super class for filtering type alias. + * If this not specifies, the MyBatis deal as type alias all classes that searched from typeAliasesPackage. + */ + private Class typeAliasesSuperType; + + /** + * Packages to search for type handlers. (Package delimiters are ",; \t\n") + */ + private String typeHandlersPackage; + + /** + * Indicates whether perform presence check of the MyBatis xml config file. + */ + private boolean checkConfigLocation = false; + + /** + * Execution mode for {@link org.mybatis.spring.SqlSessionTemplate}. + */ + private ExecutorType executorType; + + /** + * Externalized properties for MyBatis configuration. + */ + private Properties configurationProperties; + + /** + * A Configuration object for customize default settings. If {@link #configLocation} + * is specified, this property is not used. + */ + @NestedConfigurationProperty + private Configuration configuration; + + /** + * @since 1.1.0 + */ + public String getConfigLocation() { + return this.configLocation; + } + + /** + * @since 1.1.0 + */ + public void setConfigLocation(String configLocation) { + this.configLocation = configLocation; + } + + @Deprecated + public String getConfig() { + return this.configLocation; + } + + @Deprecated + public void setConfig(String config) { + this.configLocation = config; + } + + public String[] getMapperLocations() { + return this.mapperLocations; + } + + public void setMapperLocations(String[] mapperLocations) { + this.mapperLocations = mapperLocations; + } + + public String getTypeHandlersPackage() { + return this.typeHandlersPackage; + } + + public void setTypeHandlersPackage(String typeHandlersPackage) { + this.typeHandlersPackage = typeHandlersPackage; + } + + public String getTypeAliasesPackage() { + return this.typeAliasesPackage; + } + + public void setTypeAliasesPackage(String typeAliasesPackage) { + this.typeAliasesPackage = typeAliasesPackage; + } + + /** + * @since 1.3.3 + */ + public Class getTypeAliasesSuperType() { + return typeAliasesSuperType; + } + + /** + * @since 1.3.3 + */ + public void setTypeAliasesSuperType(Class typeAliasesSuperType) { + this.typeAliasesSuperType = typeAliasesSuperType; + } + + public boolean isCheckConfigLocation() { + return this.checkConfigLocation; + } + + public void setCheckConfigLocation(boolean checkConfigLocation) { + this.checkConfigLocation = checkConfigLocation; + } + + public ExecutorType getExecutorType() { + return this.executorType; + } + + public void setExecutorType(ExecutorType executorType) { + this.executorType = executorType; + } + + /** + * @since 1.2.0 + */ + public Properties getConfigurationProperties() { + return configurationProperties; + } + + /** + * @since 1.2.0 + */ + public void setConfigurationProperties(Properties configurationProperties) { + this.configurationProperties = configurationProperties; + } + + public Configuration getConfiguration() { + return configuration; + } + + public void setConfiguration(Configuration configuration) { + this.configuration = configuration; + } + + public Resource[] resolveMapperLocations() { + List resources = new ArrayList(); + if (this.mapperLocations != null) { + for (String mapperLocation : this.mapperLocations) { + resources.addAll(Arrays.asList(getResources(mapperLocation))); + } + } + return resources.toArray(new Resource[resources.size()]); + } + + private Resource[] getResources(String location) { + try { + return resourceResolver.getResources(location); + } catch (IOException e) { + return new Resource[0]; + } + } } diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SpringBootVFS.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SpringBootVFS.java index 79d023a64..66d0b77b0 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SpringBootVFS.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SpringBootVFS.java @@ -1,17 +1,17 @@ /** - * Copyright 2015-2017 the original author or authors. - * - * 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. + * Copyright 2015-2017 the original author or authors. + *

+ * 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 tk.mybatis.mapper.autoconfigure; @@ -33,31 +33,31 @@ */ public class SpringBootVFS extends VFS { - private final ResourcePatternResolver resourceResolver; + private final ResourcePatternResolver resourceResolver; - public SpringBootVFS() { - this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader()); - } + public SpringBootVFS() { + this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader()); + } + + @Override + public boolean isValid() { + return true; + } - @Override - public boolean isValid() { - return true; - } + @Override + protected List list(URL url, String path) throws IOException { + Resource[] resources = resourceResolver.getResources("classpath*:" + path + "/**/*.class"); + List resourcePaths = new ArrayList(); + for (Resource resource : resources) { + resourcePaths.add(preserveSubpackageName(resource.getURI(), path)); + } + return resourcePaths; + } - @Override - protected List list(URL url, String path) throws IOException { - Resource[] resources = resourceResolver.getResources("classpath*:" + path + "/**/*.class"); - List resourcePaths = new ArrayList(); - for (Resource resource : resources) { - resourcePaths.add(preserveSubpackageName(resource.getURI(), path)); + private static String preserveSubpackageName(final URI uri, final String rootPath) { + final String uriStr = uri.toString(); + final int start = uriStr.indexOf(rootPath); + return uriStr.substring(start); } - return resourcePaths; - } - - private static String preserveSubpackageName(final URI uri, final String rootPath) { - final String uriStr = uri.toString(); - final int start = uriStr.indexOf(rootPath); - return uriStr.substring(start); - } } diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml index ce03e290a..006382390 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot-samples - 4.2.1 + 4.2.2-SNAPSHOT mapper-spring-boot-sample-annotation jar diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/java/tk/mybatis/sample/domain/Country.java b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/java/tk/mybatis/sample/domain/Country.java index d555fc7c0..3e7e12bf9 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/java/tk/mybatis/sample/domain/Country.java +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/java/tk/mybatis/sample/domain/Country.java @@ -39,7 +39,7 @@ public class Country implements Serializable { private static final long serialVersionUID = 6569081236403751407L; @Id @ColumnType(jdbcType = JdbcType.BIGINT) - private Long id; + private Long id; private String countryname; private String countrycode; diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/import.sql b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/import.sql index 2e7e7c544..fa52b2e92 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/import.sql +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/import.sql @@ -1,191 +1,375 @@ drop table country if exists; -create table country ( - id int primary key auto_increment, - countryname varchar(32), - countrycode varchar(2) +create table country +( + id int primary key auto_increment, + countryname varchar(32), + countrycode varchar(2) ); -insert into country (id, countryname, countrycode) values(1,'Angola','AO'); -insert into country (id, countryname, countrycode) values(2,'Afghanistan','AF'); -insert into country (id, countryname, countrycode) values(3,'Albania','AL'); -insert into country (id, countryname, countrycode) values(4,'Algeria','DZ'); -insert into country (id, countryname, countrycode) values(5,'Andorra','AD'); -insert into country (id, countryname, countrycode) values(6,'Anguilla','AI'); -insert into country (id, countryname, countrycode) values(7,'Antigua and Barbuda','AG'); -insert into country (id, countryname, countrycode) values(8,'Argentina','AR'); -insert into country (id, countryname, countrycode) values(9,'Armenia','AM'); -insert into country (id, countryname, countrycode) values(10,'Australia','AU'); -insert into country (id, countryname, countrycode) values(11,'Austria','AT'); -insert into country (id, countryname, countrycode) values(12,'Azerbaijan','AZ'); -insert into country (id, countryname, countrycode) values(13,'Bahamas','BS'); -insert into country (id, countryname, countrycode) values(14,'Bahrain','BH'); -insert into country (id, countryname, countrycode) values(15,'Bangladesh','BD'); -insert into country (id, countryname, countrycode) values(16,'Barbados','BB'); -insert into country (id, countryname, countrycode) values(17,'Belarus','BY'); -insert into country (id, countryname, countrycode) values(18,'Belgium','BE'); -insert into country (id, countryname, countrycode) values(19,'Belize','BZ'); -insert into country (id, countryname, countrycode) values(20,'Benin','BJ'); -insert into country (id, countryname, countrycode) values(21,'Bermuda Is.','BM'); -insert into country (id, countryname, countrycode) values(22,'Bolivia','BO'); -insert into country (id, countryname, countrycode) values(23,'Botswana','BW'); -insert into country (id, countryname, countrycode) values(24,'Brazil','BR'); -insert into country (id, countryname, countrycode) values(25,'Brunei','BN'); -insert into country (id, countryname, countrycode) values(26,'Bulgaria','BG'); -insert into country (id, countryname, countrycode) values(27,'Burkina-faso','BF'); -insert into country (id, countryname, countrycode) values(28,'Burma','MM'); -insert into country (id, countryname, countrycode) values(29,'Burundi','BI'); -insert into country (id, countryname, countrycode) values(30,'Cameroon','CM'); -insert into country (id, countryname, countrycode) values(31,'Canada','CA'); -insert into country (id, countryname, countrycode) values(32,'Central African Republic','CF'); -insert into country (id, countryname, countrycode) values(33,'Chad','TD'); -insert into country (id, countryname, countrycode) values(34,'Chile','CL'); -insert into country (id, countryname, countrycode) values(35,'China','CN'); -insert into country (id, countryname, countrycode) values(36,'Colombia','CO'); -insert into country (id, countryname, countrycode) values(37,'Congo','CG'); -insert into country (id, countryname, countrycode) values(38,'Cook Is.','CK'); -insert into country (id, countryname, countrycode) values(39,'Costa Rica','CR'); -insert into country (id, countryname, countrycode) values(40,'Cuba','CU'); -insert into country (id, countryname, countrycode) values(41,'Cyprus','CY'); -insert into country (id, countryname, countrycode) values(42,'Czech Republic','CZ'); -insert into country (id, countryname, countrycode) values(43,'Denmark','DK'); -insert into country (id, countryname, countrycode) values(44,'Djibouti','DJ'); -insert into country (id, countryname, countrycode) values(45,'Dominica Rep.','DO'); -insert into country (id, countryname, countrycode) values(46,'Ecuador','EC'); -insert into country (id, countryname, countrycode) values(47,'Egypt','EG'); -insert into country (id, countryname, countrycode) values(48,'EI Salvador','SV'); -insert into country (id, countryname, countrycode) values(49,'Estonia','EE'); -insert into country (id, countryname, countrycode) values(50,'Ethiopia','ET'); -insert into country (id, countryname, countrycode) values(51,'Fiji','FJ'); -insert into country (id, countryname, countrycode) values(52,'Finland','FI'); -insert into country (id, countryname, countrycode) values(53,'France','FR'); -insert into country (id, countryname, countrycode) values(54,'French Guiana','GF'); -insert into country (id, countryname, countrycode) values(55,'Gabon','GA'); -insert into country (id, countryname, countrycode) values(56,'Gambia','GM'); -insert into country (id, countryname, countrycode) values(57,'Georgia','GE'); -insert into country (id, countryname, countrycode) values(58,'Germany','DE'); -insert into country (id, countryname, countrycode) values(59,'Ghana','GH'); -insert into country (id, countryname, countrycode) values(60,'Gibraltar','GI'); -insert into country (id, countryname, countrycode) values(61,'Greece','GR'); -insert into country (id, countryname, countrycode) values(62,'Grenada','GD'); -insert into country (id, countryname, countrycode) values(63,'Guam','GU'); -insert into country (id, countryname, countrycode) values(64,'Guatemala','GT'); -insert into country (id, countryname, countrycode) values(65,'Guinea','GN'); -insert into country (id, countryname, countrycode) values(66,'Guyana','GY'); -insert into country (id, countryname, countrycode) values(67,'Haiti','HT'); -insert into country (id, countryname, countrycode) values(68,'Honduras','HN'); -insert into country (id, countryname, countrycode) values(69,'Hongkong','HK'); -insert into country (id, countryname, countrycode) values(70,'Hungary','HU'); -insert into country (id, countryname, countrycode) values(71,'Iceland','IS'); -insert into country (id, countryname, countrycode) values(72,'India','IN'); -insert into country (id, countryname, countrycode) values(73,'Indonesia','ID'); -insert into country (id, countryname, countrycode) values(74,'Iran','IR'); -insert into country (id, countryname, countrycode) values(75,'Iraq','IQ'); -insert into country (id, countryname, countrycode) values(76,'Ireland','IE'); -insert into country (id, countryname, countrycode) values(77,'Israel','IL'); -insert into country (id, countryname, countrycode) values(78,'Italy','IT'); -insert into country (id, countryname, countrycode) values(79,'Jamaica','JM'); -insert into country (id, countryname, countrycode) values(80,'Japan','JP'); -insert into country (id, countryname, countrycode) values(81,'Jordan','JO'); -insert into country (id, countryname, countrycode) values(82,'Kampuchea (Cambodia )','KH'); -insert into country (id, countryname, countrycode) values(83,'Kazakstan','KZ'); -insert into country (id, countryname, countrycode) values(84,'Kenya','KE'); -insert into country (id, countryname, countrycode) values(85,'Korea','KR'); -insert into country (id, countryname, countrycode) values(86,'Kuwait','KW'); -insert into country (id, countryname, countrycode) values(87,'Kyrgyzstan','KG'); -insert into country (id, countryname, countrycode) values(88,'Laos','LA'); -insert into country (id, countryname, countrycode) values(89,'Latvia','LV'); -insert into country (id, countryname, countrycode) values(90,'Lebanon','LB'); -insert into country (id, countryname, countrycode) values(91,'Lesotho','LS'); -insert into country (id, countryname, countrycode) values(92,'Liberia','LR'); -insert into country (id, countryname, countrycode) values(93,'Libya','LY'); -insert into country (id, countryname, countrycode) values(94,'Liechtenstein','LI'); -insert into country (id, countryname, countrycode) values(95,'Lithuania','LT'); -insert into country (id, countryname, countrycode) values(96,'Luxembourg','LU'); -insert into country (id, countryname, countrycode) values(97,'Macao','MO'); -insert into country (id, countryname, countrycode) values(98,'Madagascar','MG'); -insert into country (id, countryname, countrycode) values(99,'Malawi','MW'); -insert into country (id, countryname, countrycode) values(100,'Malaysia','MY'); -insert into country (id, countryname, countrycode) values(101,'Maldives','MV'); -insert into country (id, countryname, countrycode) values(102,'Mali','ML'); -insert into country (id, countryname, countrycode) values(103,'Malta','MT'); -insert into country (id, countryname, countrycode) values(104,'Mauritius','MU'); -insert into country (id, countryname, countrycode) values(105,'Mexico','MX'); -insert into country (id, countryname, countrycode) values(106,'Moldova, Republic of','MD'); -insert into country (id, countryname, countrycode) values(107,'Monaco','MC'); -insert into country (id, countryname, countrycode) values(108,'Mongolia','MN'); -insert into country (id, countryname, countrycode) values(109,'Montserrat Is','MS'); -insert into country (id, countryname, countrycode) values(110,'Morocco','MA'); -insert into country (id, countryname, countrycode) values(111,'Mozambique','MZ'); -insert into country (id, countryname, countrycode) values(112,'Namibia','NA'); -insert into country (id, countryname, countrycode) values(113,'Nauru','NR'); -insert into country (id, countryname, countrycode) values(114,'Nepal','NP'); -insert into country (id, countryname, countrycode) values(115,'Netherlands','NL'); -insert into country (id, countryname, countrycode) values(116,'New Zealand','NZ'); -insert into country (id, countryname, countrycode) values(117,'Nicaragua','NI'); -insert into country (id, countryname, countrycode) values(118,'Niger','NE'); -insert into country (id, countryname, countrycode) values(119,'Nigeria','NG'); -insert into country (id, countryname, countrycode) values(120,'North Korea','KP'); -insert into country (id, countryname, countrycode) values(121,'Norway','NO'); -insert into country (id, countryname, countrycode) values(122,'Oman','OM'); -insert into country (id, countryname, countrycode) values(123,'Pakistan','PK'); -insert into country (id, countryname, countrycode) values(124,'Panama','PA'); -insert into country (id, countryname, countrycode) values(125,'Papua New Cuinea','PG'); -insert into country (id, countryname, countrycode) values(126,'Paraguay','PY'); -insert into country (id, countryname, countrycode) values(127,'Peru','PE'); -insert into country (id, countryname, countrycode) values(128,'Philippines','PH'); -insert into country (id, countryname, countrycode) values(129,'Poland','PL'); -insert into country (id, countryname, countrycode) values(130,'French Polynesia','PF'); -insert into country (id, countryname, countrycode) values(131,'Portugal','PT'); -insert into country (id, countryname, countrycode) values(132,'Puerto Rico','PR'); -insert into country (id, countryname, countrycode) values(133,'Qatar','QA'); -insert into country (id, countryname, countrycode) values(134,'Romania','RO'); -insert into country (id, countryname, countrycode) values(135,'Russia','RU'); -insert into country (id, countryname, countrycode) values(136,'Saint Lueia','LC'); -insert into country (id, countryname, countrycode) values(137,'Saint Vincent','VC'); -insert into country (id, countryname, countrycode) values(138,'San Marino','SM'); -insert into country (id, countryname, countrycode) values(139,'Sao Tome and Principe','ST'); -insert into country (id, countryname, countrycode) values(140,'Saudi Arabia','SA'); -insert into country (id, countryname, countrycode) values(141,'Senegal','SN'); -insert into country (id, countryname, countrycode) values(142,'Seychelles','SC'); -insert into country (id, countryname, countrycode) values(143,'Sierra Leone','SL'); -insert into country (id, countryname, countrycode) values(144,'Singapore','SG'); -insert into country (id, countryname, countrycode) values(145,'Slovakia','SK'); -insert into country (id, countryname, countrycode) values(146,'Slovenia','SI'); -insert into country (id, countryname, countrycode) values(147,'Solomon Is','SB'); -insert into country (id, countryname, countrycode) values(148,'Somali','SO'); -insert into country (id, countryname, countrycode) values(149,'South Africa','ZA'); -insert into country (id, countryname, countrycode) values(150,'Spain','ES'); -insert into country (id, countryname, countrycode) values(151,'Sri Lanka','LK'); -insert into country (id, countryname, countrycode) values(152,'St.Lucia','LC'); -insert into country (id, countryname, countrycode) values(153,'St.Vincent','VC'); -insert into country (id, countryname, countrycode) values(154,'Sudan','SD'); -insert into country (id, countryname, countrycode) values(155,'Suriname','SR'); -insert into country (id, countryname, countrycode) values(156,'Swaziland','SZ'); -insert into country (id, countryname, countrycode) values(157,'Sweden','SE'); -insert into country (id, countryname, countrycode) values(158,'Switzerland','CH'); -insert into country (id, countryname, countrycode) values(159,'Syria','SY'); -insert into country (id, countryname, countrycode) values(160,'Taiwan','TW'); -insert into country (id, countryname, countrycode) values(161,'Tajikstan','TJ'); -insert into country (id, countryname, countrycode) values(162,'Tanzania','TZ'); -insert into country (id, countryname, countrycode) values(163,'Thailand','TH'); -insert into country (id, countryname, countrycode) values(164,'Togo','TG'); -insert into country (id, countryname, countrycode) values(165,'Tonga','TO'); -insert into country (id, countryname, countrycode) values(166,'Trinidad and Tobago','TT'); -insert into country (id, countryname, countrycode) values(167,'Tunisia','TN'); -insert into country (id, countryname, countrycode) values(168,'Turkey','TR'); -insert into country (id, countryname, countrycode) values(169,'Turkmenistan','TM'); -insert into country (id, countryname, countrycode) values(170,'Uganda','UG'); -insert into country (id, countryname, countrycode) values(171,'Ukraine','UA'); -insert into country (id, countryname, countrycode) values(172,'United Arab Emirates','AE'); -insert into country (id, countryname, countrycode) values(173,'United Kiongdom','GB'); -insert into country (id, countryname, countrycode) values(174,'United States of America','US'); -insert into country (id, countryname, countrycode) values(175,'Uruguay','UY'); -insert into country (id, countryname, countrycode) values(176,'Uzbekistan','UZ'); -insert into country (id, countryname, countrycode) values(177,'Venezuela','VE'); -insert into country (id, countryname, countrycode) values(178,'Vietnam','VN'); -insert into country (id, countryname, countrycode) values(179,'Yemen','YE'); -insert into country (id, countryname, countrycode) values(180,'Yugoslavia','YU'); -insert into country (id, countryname, countrycode) values(181,'Zimbabwe','ZW'); -insert into country (id, countryname, countrycode) values(182,'Zaire','ZR'); -insert into country (id, countryname, countrycode) values(183,'Zambia','ZM'); \ No newline at end of file +insert into country (id, countryname, countrycode) +values (1, 'Angola', 'AO'); +insert into country (id, countryname, countrycode) +values (2, 'Afghanistan', 'AF'); +insert into country (id, countryname, countrycode) +values (3, 'Albania', 'AL'); +insert into country (id, countryname, countrycode) +values (4, 'Algeria', 'DZ'); +insert into country (id, countryname, countrycode) +values (5, 'Andorra', 'AD'); +insert into country (id, countryname, countrycode) +values (6, 'Anguilla', 'AI'); +insert into country (id, countryname, countrycode) +values (7, 'Antigua and Barbuda', 'AG'); +insert into country (id, countryname, countrycode) +values (8, 'Argentina', 'AR'); +insert into country (id, countryname, countrycode) +values (9, 'Armenia', 'AM'); +insert into country (id, countryname, countrycode) +values (10, 'Australia', 'AU'); +insert into country (id, countryname, countrycode) +values (11, 'Austria', 'AT'); +insert into country (id, countryname, countrycode) +values (12, 'Azerbaijan', 'AZ'); +insert into country (id, countryname, countrycode) +values (13, 'Bahamas', 'BS'); +insert into country (id, countryname, countrycode) +values (14, 'Bahrain', 'BH'); +insert into country (id, countryname, countrycode) +values (15, 'Bangladesh', 'BD'); +insert into country (id, countryname, countrycode) +values (16, 'Barbados', 'BB'); +insert into country (id, countryname, countrycode) +values (17, 'Belarus', 'BY'); +insert into country (id, countryname, countrycode) +values (18, 'Belgium', 'BE'); +insert into country (id, countryname, countrycode) +values (19, 'Belize', 'BZ'); +insert into country (id, countryname, countrycode) +values (20, 'Benin', 'BJ'); +insert into country (id, countryname, countrycode) +values (21, 'Bermuda Is.', 'BM'); +insert into country (id, countryname, countrycode) +values (22, 'Bolivia', 'BO'); +insert into country (id, countryname, countrycode) +values (23, 'Botswana', 'BW'); +insert into country (id, countryname, countrycode) +values (24, 'Brazil', 'BR'); +insert into country (id, countryname, countrycode) +values (25, 'Brunei', 'BN'); +insert into country (id, countryname, countrycode) +values (26, 'Bulgaria', 'BG'); +insert into country (id, countryname, countrycode) +values (27, 'Burkina-faso', 'BF'); +insert into country (id, countryname, countrycode) +values (28, 'Burma', 'MM'); +insert into country (id, countryname, countrycode) +values (29, 'Burundi', 'BI'); +insert into country (id, countryname, countrycode) +values (30, 'Cameroon', 'CM'); +insert into country (id, countryname, countrycode) +values (31, 'Canada', 'CA'); +insert into country (id, countryname, countrycode) +values (32, 'Central African Republic', 'CF'); +insert into country (id, countryname, countrycode) +values (33, 'Chad', 'TD'); +insert into country (id, countryname, countrycode) +values (34, 'Chile', 'CL'); +insert into country (id, countryname, countrycode) +values (35, 'China', 'CN'); +insert into country (id, countryname, countrycode) +values (36, 'Colombia', 'CO'); +insert into country (id, countryname, countrycode) +values (37, 'Congo', 'CG'); +insert into country (id, countryname, countrycode) +values (38, 'Cook Is.', 'CK'); +insert into country (id, countryname, countrycode) +values (39, 'Costa Rica', 'CR'); +insert into country (id, countryname, countrycode) +values (40, 'Cuba', 'CU'); +insert into country (id, countryname, countrycode) +values (41, 'Cyprus', 'CY'); +insert into country (id, countryname, countrycode) +values (42, 'Czech Republic', 'CZ'); +insert into country (id, countryname, countrycode) +values (43, 'Denmark', 'DK'); +insert into country (id, countryname, countrycode) +values (44, 'Djibouti', 'DJ'); +insert into country (id, countryname, countrycode) +values (45, 'Dominica Rep.', 'DO'); +insert into country (id, countryname, countrycode) +values (46, 'Ecuador', 'EC'); +insert into country (id, countryname, countrycode) +values (47, 'Egypt', 'EG'); +insert into country (id, countryname, countrycode) +values (48, 'EI Salvador', 'SV'); +insert into country (id, countryname, countrycode) +values (49, 'Estonia', 'EE'); +insert into country (id, countryname, countrycode) +values (50, 'Ethiopia', 'ET'); +insert into country (id, countryname, countrycode) +values (51, 'Fiji', 'FJ'); +insert into country (id, countryname, countrycode) +values (52, 'Finland', 'FI'); +insert into country (id, countryname, countrycode) +values (53, 'France', 'FR'); +insert into country (id, countryname, countrycode) +values (54, 'French Guiana', 'GF'); +insert into country (id, countryname, countrycode) +values (55, 'Gabon', 'GA'); +insert into country (id, countryname, countrycode) +values (56, 'Gambia', 'GM'); +insert into country (id, countryname, countrycode) +values (57, 'Georgia', 'GE'); +insert into country (id, countryname, countrycode) +values (58, 'Germany', 'DE'); +insert into country (id, countryname, countrycode) +values (59, 'Ghana', 'GH'); +insert into country (id, countryname, countrycode) +values (60, 'Gibraltar', 'GI'); +insert into country (id, countryname, countrycode) +values (61, 'Greece', 'GR'); +insert into country (id, countryname, countrycode) +values (62, 'Grenada', 'GD'); +insert into country (id, countryname, countrycode) +values (63, 'Guam', 'GU'); +insert into country (id, countryname, countrycode) +values (64, 'Guatemala', 'GT'); +insert into country (id, countryname, countrycode) +values (65, 'Guinea', 'GN'); +insert into country (id, countryname, countrycode) +values (66, 'Guyana', 'GY'); +insert into country (id, countryname, countrycode) +values (67, 'Haiti', 'HT'); +insert into country (id, countryname, countrycode) +values (68, 'Honduras', 'HN'); +insert into country (id, countryname, countrycode) +values (69, 'Hongkong', 'HK'); +insert into country (id, countryname, countrycode) +values (70, 'Hungary', 'HU'); +insert into country (id, countryname, countrycode) +values (71, 'Iceland', 'IS'); +insert into country (id, countryname, countrycode) +values (72, 'India', 'IN'); +insert into country (id, countryname, countrycode) +values (73, 'Indonesia', 'ID'); +insert into country (id, countryname, countrycode) +values (74, 'Iran', 'IR'); +insert into country (id, countryname, countrycode) +values (75, 'Iraq', 'IQ'); +insert into country (id, countryname, countrycode) +values (76, 'Ireland', 'IE'); +insert into country (id, countryname, countrycode) +values (77, 'Israel', 'IL'); +insert into country (id, countryname, countrycode) +values (78, 'Italy', 'IT'); +insert into country (id, countryname, countrycode) +values (79, 'Jamaica', 'JM'); +insert into country (id, countryname, countrycode) +values (80, 'Japan', 'JP'); +insert into country (id, countryname, countrycode) +values (81, 'Jordan', 'JO'); +insert into country (id, countryname, countrycode) +values (82, 'Kampuchea (Cambodia )', 'KH'); +insert into country (id, countryname, countrycode) +values (83, 'Kazakstan', 'KZ'); +insert into country (id, countryname, countrycode) +values (84, 'Kenya', 'KE'); +insert into country (id, countryname, countrycode) +values (85, 'Korea', 'KR'); +insert into country (id, countryname, countrycode) +values (86, 'Kuwait', 'KW'); +insert into country (id, countryname, countrycode) +values (87, 'Kyrgyzstan', 'KG'); +insert into country (id, countryname, countrycode) +values (88, 'Laos', 'LA'); +insert into country (id, countryname, countrycode) +values (89, 'Latvia', 'LV'); +insert into country (id, countryname, countrycode) +values (90, 'Lebanon', 'LB'); +insert into country (id, countryname, countrycode) +values (91, 'Lesotho', 'LS'); +insert into country (id, countryname, countrycode) +values (92, 'Liberia', 'LR'); +insert into country (id, countryname, countrycode) +values (93, 'Libya', 'LY'); +insert into country (id, countryname, countrycode) +values (94, 'Liechtenstein', 'LI'); +insert into country (id, countryname, countrycode) +values (95, 'Lithuania', 'LT'); +insert into country (id, countryname, countrycode) +values (96, 'Luxembourg', 'LU'); +insert into country (id, countryname, countrycode) +values (97, 'Macao', 'MO'); +insert into country (id, countryname, countrycode) +values (98, 'Madagascar', 'MG'); +insert into country (id, countryname, countrycode) +values (99, 'Malawi', 'MW'); +insert into country (id, countryname, countrycode) +values (100, 'Malaysia', 'MY'); +insert into country (id, countryname, countrycode) +values (101, 'Maldives', 'MV'); +insert into country (id, countryname, countrycode) +values (102, 'Mali', 'ML'); +insert into country (id, countryname, countrycode) +values (103, 'Malta', 'MT'); +insert into country (id, countryname, countrycode) +values (104, 'Mauritius', 'MU'); +insert into country (id, countryname, countrycode) +values (105, 'Mexico', 'MX'); +insert into country (id, countryname, countrycode) +values (106, 'Moldova, Republic of', 'MD'); +insert into country (id, countryname, countrycode) +values (107, 'Monaco', 'MC'); +insert into country (id, countryname, countrycode) +values (108, 'Mongolia', 'MN'); +insert into country (id, countryname, countrycode) +values (109, 'Montserrat Is', 'MS'); +insert into country (id, countryname, countrycode) +values (110, 'Morocco', 'MA'); +insert into country (id, countryname, countrycode) +values (111, 'Mozambique', 'MZ'); +insert into country (id, countryname, countrycode) +values (112, 'Namibia', 'NA'); +insert into country (id, countryname, countrycode) +values (113, 'Nauru', 'NR'); +insert into country (id, countryname, countrycode) +values (114, 'Nepal', 'NP'); +insert into country (id, countryname, countrycode) +values (115, 'Netherlands', 'NL'); +insert into country (id, countryname, countrycode) +values (116, 'New Zealand', 'NZ'); +insert into country (id, countryname, countrycode) +values (117, 'Nicaragua', 'NI'); +insert into country (id, countryname, countrycode) +values (118, 'Niger', 'NE'); +insert into country (id, countryname, countrycode) +values (119, 'Nigeria', 'NG'); +insert into country (id, countryname, countrycode) +values (120, 'North Korea', 'KP'); +insert into country (id, countryname, countrycode) +values (121, 'Norway', 'NO'); +insert into country (id, countryname, countrycode) +values (122, 'Oman', 'OM'); +insert into country (id, countryname, countrycode) +values (123, 'Pakistan', 'PK'); +insert into country (id, countryname, countrycode) +values (124, 'Panama', 'PA'); +insert into country (id, countryname, countrycode) +values (125, 'Papua New Cuinea', 'PG'); +insert into country (id, countryname, countrycode) +values (126, 'Paraguay', 'PY'); +insert into country (id, countryname, countrycode) +values (127, 'Peru', 'PE'); +insert into country (id, countryname, countrycode) +values (128, 'Philippines', 'PH'); +insert into country (id, countryname, countrycode) +values (129, 'Poland', 'PL'); +insert into country (id, countryname, countrycode) +values (130, 'French Polynesia', 'PF'); +insert into country (id, countryname, countrycode) +values (131, 'Portugal', 'PT'); +insert into country (id, countryname, countrycode) +values (132, 'Puerto Rico', 'PR'); +insert into country (id, countryname, countrycode) +values (133, 'Qatar', 'QA'); +insert into country (id, countryname, countrycode) +values (134, 'Romania', 'RO'); +insert into country (id, countryname, countrycode) +values (135, 'Russia', 'RU'); +insert into country (id, countryname, countrycode) +values (136, 'Saint Lueia', 'LC'); +insert into country (id, countryname, countrycode) +values (137, 'Saint Vincent', 'VC'); +insert into country (id, countryname, countrycode) +values (138, 'San Marino', 'SM'); +insert into country (id, countryname, countrycode) +values (139, 'Sao Tome and Principe', 'ST'); +insert into country (id, countryname, countrycode) +values (140, 'Saudi Arabia', 'SA'); +insert into country (id, countryname, countrycode) +values (141, 'Senegal', 'SN'); +insert into country (id, countryname, countrycode) +values (142, 'Seychelles', 'SC'); +insert into country (id, countryname, countrycode) +values (143, 'Sierra Leone', 'SL'); +insert into country (id, countryname, countrycode) +values (144, 'Singapore', 'SG'); +insert into country (id, countryname, countrycode) +values (145, 'Slovakia', 'SK'); +insert into country (id, countryname, countrycode) +values (146, 'Slovenia', 'SI'); +insert into country (id, countryname, countrycode) +values (147, 'Solomon Is', 'SB'); +insert into country (id, countryname, countrycode) +values (148, 'Somali', 'SO'); +insert into country (id, countryname, countrycode) +values (149, 'South Africa', 'ZA'); +insert into country (id, countryname, countrycode) +values (150, 'Spain', 'ES'); +insert into country (id, countryname, countrycode) +values (151, 'Sri Lanka', 'LK'); +insert into country (id, countryname, countrycode) +values (152, 'St.Lucia', 'LC'); +insert into country (id, countryname, countrycode) +values (153, 'St.Vincent', 'VC'); +insert into country (id, countryname, countrycode) +values (154, 'Sudan', 'SD'); +insert into country (id, countryname, countrycode) +values (155, 'Suriname', 'SR'); +insert into country (id, countryname, countrycode) +values (156, 'Swaziland', 'SZ'); +insert into country (id, countryname, countrycode) +values (157, 'Sweden', 'SE'); +insert into country (id, countryname, countrycode) +values (158, 'Switzerland', 'CH'); +insert into country (id, countryname, countrycode) +values (159, 'Syria', 'SY'); +insert into country (id, countryname, countrycode) +values (160, 'Taiwan', 'TW'); +insert into country (id, countryname, countrycode) +values (161, 'Tajikstan', 'TJ'); +insert into country (id, countryname, countrycode) +values (162, 'Tanzania', 'TZ'); +insert into country (id, countryname, countrycode) +values (163, 'Thailand', 'TH'); +insert into country (id, countryname, countrycode) +values (164, 'Togo', 'TG'); +insert into country (id, countryname, countrycode) +values (165, 'Tonga', 'TO'); +insert into country (id, countryname, countrycode) +values (166, 'Trinidad and Tobago', 'TT'); +insert into country (id, countryname, countrycode) +values (167, 'Tunisia', 'TN'); +insert into country (id, countryname, countrycode) +values (168, 'Turkey', 'TR'); +insert into country (id, countryname, countrycode) +values (169, 'Turkmenistan', 'TM'); +insert into country (id, countryname, countrycode) +values (170, 'Uganda', 'UG'); +insert into country (id, countryname, countrycode) +values (171, 'Ukraine', 'UA'); +insert into country (id, countryname, countrycode) +values (172, 'United Arab Emirates', 'AE'); +insert into country (id, countryname, countrycode) +values (173, 'United Kiongdom', 'GB'); +insert into country (id, countryname, countrycode) +values (174, 'United States of America', 'US'); +insert into country (id, countryname, countrycode) +values (175, 'Uruguay', 'UY'); +insert into country (id, countryname, countrycode) +values (176, 'Uzbekistan', 'UZ'); +insert into country (id, countryname, countrycode) +values (177, 'Venezuela', 'VE'); +insert into country (id, countryname, countrycode) +values (178, 'Vietnam', 'VN'); +insert into country (id, countryname, countrycode) +values (179, 'Yemen', 'YE'); +insert into country (id, countryname, countrycode) +values (180, 'Yugoslavia', 'YU'); +insert into country (id, countryname, countrycode) +values (181, 'Zimbabwe', 'ZW'); +insert into country (id, countryname, countrycode) +values (182, 'Zaire', 'ZR'); +insert into country (id, countryname, countrycode) +values (183, 'Zambia', 'ZM'); \ No newline at end of file diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml index bb54e9a35..656602bd8 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot-samples - 4.2.1 + 4.2.2-SNAPSHOT mapper-spring-boot-sample-xml jar diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/domain/Country.java b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/domain/Country.java index d555fc7c0..3e7e12bf9 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/domain/Country.java +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/domain/Country.java @@ -39,7 +39,7 @@ public class Country implements Serializable { private static final long serialVersionUID = 6569081236403751407L; @Id @ColumnType(jdbcType = JdbcType.BIGINT) - private Long id; + private Long id; private String countryname; private String countrycode; diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/import.sql b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/import.sql index 2e7e7c544..fa52b2e92 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/import.sql +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/import.sql @@ -1,191 +1,375 @@ drop table country if exists; -create table country ( - id int primary key auto_increment, - countryname varchar(32), - countrycode varchar(2) +create table country +( + id int primary key auto_increment, + countryname varchar(32), + countrycode varchar(2) ); -insert into country (id, countryname, countrycode) values(1,'Angola','AO'); -insert into country (id, countryname, countrycode) values(2,'Afghanistan','AF'); -insert into country (id, countryname, countrycode) values(3,'Albania','AL'); -insert into country (id, countryname, countrycode) values(4,'Algeria','DZ'); -insert into country (id, countryname, countrycode) values(5,'Andorra','AD'); -insert into country (id, countryname, countrycode) values(6,'Anguilla','AI'); -insert into country (id, countryname, countrycode) values(7,'Antigua and Barbuda','AG'); -insert into country (id, countryname, countrycode) values(8,'Argentina','AR'); -insert into country (id, countryname, countrycode) values(9,'Armenia','AM'); -insert into country (id, countryname, countrycode) values(10,'Australia','AU'); -insert into country (id, countryname, countrycode) values(11,'Austria','AT'); -insert into country (id, countryname, countrycode) values(12,'Azerbaijan','AZ'); -insert into country (id, countryname, countrycode) values(13,'Bahamas','BS'); -insert into country (id, countryname, countrycode) values(14,'Bahrain','BH'); -insert into country (id, countryname, countrycode) values(15,'Bangladesh','BD'); -insert into country (id, countryname, countrycode) values(16,'Barbados','BB'); -insert into country (id, countryname, countrycode) values(17,'Belarus','BY'); -insert into country (id, countryname, countrycode) values(18,'Belgium','BE'); -insert into country (id, countryname, countrycode) values(19,'Belize','BZ'); -insert into country (id, countryname, countrycode) values(20,'Benin','BJ'); -insert into country (id, countryname, countrycode) values(21,'Bermuda Is.','BM'); -insert into country (id, countryname, countrycode) values(22,'Bolivia','BO'); -insert into country (id, countryname, countrycode) values(23,'Botswana','BW'); -insert into country (id, countryname, countrycode) values(24,'Brazil','BR'); -insert into country (id, countryname, countrycode) values(25,'Brunei','BN'); -insert into country (id, countryname, countrycode) values(26,'Bulgaria','BG'); -insert into country (id, countryname, countrycode) values(27,'Burkina-faso','BF'); -insert into country (id, countryname, countrycode) values(28,'Burma','MM'); -insert into country (id, countryname, countrycode) values(29,'Burundi','BI'); -insert into country (id, countryname, countrycode) values(30,'Cameroon','CM'); -insert into country (id, countryname, countrycode) values(31,'Canada','CA'); -insert into country (id, countryname, countrycode) values(32,'Central African Republic','CF'); -insert into country (id, countryname, countrycode) values(33,'Chad','TD'); -insert into country (id, countryname, countrycode) values(34,'Chile','CL'); -insert into country (id, countryname, countrycode) values(35,'China','CN'); -insert into country (id, countryname, countrycode) values(36,'Colombia','CO'); -insert into country (id, countryname, countrycode) values(37,'Congo','CG'); -insert into country (id, countryname, countrycode) values(38,'Cook Is.','CK'); -insert into country (id, countryname, countrycode) values(39,'Costa Rica','CR'); -insert into country (id, countryname, countrycode) values(40,'Cuba','CU'); -insert into country (id, countryname, countrycode) values(41,'Cyprus','CY'); -insert into country (id, countryname, countrycode) values(42,'Czech Republic','CZ'); -insert into country (id, countryname, countrycode) values(43,'Denmark','DK'); -insert into country (id, countryname, countrycode) values(44,'Djibouti','DJ'); -insert into country (id, countryname, countrycode) values(45,'Dominica Rep.','DO'); -insert into country (id, countryname, countrycode) values(46,'Ecuador','EC'); -insert into country (id, countryname, countrycode) values(47,'Egypt','EG'); -insert into country (id, countryname, countrycode) values(48,'EI Salvador','SV'); -insert into country (id, countryname, countrycode) values(49,'Estonia','EE'); -insert into country (id, countryname, countrycode) values(50,'Ethiopia','ET'); -insert into country (id, countryname, countrycode) values(51,'Fiji','FJ'); -insert into country (id, countryname, countrycode) values(52,'Finland','FI'); -insert into country (id, countryname, countrycode) values(53,'France','FR'); -insert into country (id, countryname, countrycode) values(54,'French Guiana','GF'); -insert into country (id, countryname, countrycode) values(55,'Gabon','GA'); -insert into country (id, countryname, countrycode) values(56,'Gambia','GM'); -insert into country (id, countryname, countrycode) values(57,'Georgia','GE'); -insert into country (id, countryname, countrycode) values(58,'Germany','DE'); -insert into country (id, countryname, countrycode) values(59,'Ghana','GH'); -insert into country (id, countryname, countrycode) values(60,'Gibraltar','GI'); -insert into country (id, countryname, countrycode) values(61,'Greece','GR'); -insert into country (id, countryname, countrycode) values(62,'Grenada','GD'); -insert into country (id, countryname, countrycode) values(63,'Guam','GU'); -insert into country (id, countryname, countrycode) values(64,'Guatemala','GT'); -insert into country (id, countryname, countrycode) values(65,'Guinea','GN'); -insert into country (id, countryname, countrycode) values(66,'Guyana','GY'); -insert into country (id, countryname, countrycode) values(67,'Haiti','HT'); -insert into country (id, countryname, countrycode) values(68,'Honduras','HN'); -insert into country (id, countryname, countrycode) values(69,'Hongkong','HK'); -insert into country (id, countryname, countrycode) values(70,'Hungary','HU'); -insert into country (id, countryname, countrycode) values(71,'Iceland','IS'); -insert into country (id, countryname, countrycode) values(72,'India','IN'); -insert into country (id, countryname, countrycode) values(73,'Indonesia','ID'); -insert into country (id, countryname, countrycode) values(74,'Iran','IR'); -insert into country (id, countryname, countrycode) values(75,'Iraq','IQ'); -insert into country (id, countryname, countrycode) values(76,'Ireland','IE'); -insert into country (id, countryname, countrycode) values(77,'Israel','IL'); -insert into country (id, countryname, countrycode) values(78,'Italy','IT'); -insert into country (id, countryname, countrycode) values(79,'Jamaica','JM'); -insert into country (id, countryname, countrycode) values(80,'Japan','JP'); -insert into country (id, countryname, countrycode) values(81,'Jordan','JO'); -insert into country (id, countryname, countrycode) values(82,'Kampuchea (Cambodia )','KH'); -insert into country (id, countryname, countrycode) values(83,'Kazakstan','KZ'); -insert into country (id, countryname, countrycode) values(84,'Kenya','KE'); -insert into country (id, countryname, countrycode) values(85,'Korea','KR'); -insert into country (id, countryname, countrycode) values(86,'Kuwait','KW'); -insert into country (id, countryname, countrycode) values(87,'Kyrgyzstan','KG'); -insert into country (id, countryname, countrycode) values(88,'Laos','LA'); -insert into country (id, countryname, countrycode) values(89,'Latvia','LV'); -insert into country (id, countryname, countrycode) values(90,'Lebanon','LB'); -insert into country (id, countryname, countrycode) values(91,'Lesotho','LS'); -insert into country (id, countryname, countrycode) values(92,'Liberia','LR'); -insert into country (id, countryname, countrycode) values(93,'Libya','LY'); -insert into country (id, countryname, countrycode) values(94,'Liechtenstein','LI'); -insert into country (id, countryname, countrycode) values(95,'Lithuania','LT'); -insert into country (id, countryname, countrycode) values(96,'Luxembourg','LU'); -insert into country (id, countryname, countrycode) values(97,'Macao','MO'); -insert into country (id, countryname, countrycode) values(98,'Madagascar','MG'); -insert into country (id, countryname, countrycode) values(99,'Malawi','MW'); -insert into country (id, countryname, countrycode) values(100,'Malaysia','MY'); -insert into country (id, countryname, countrycode) values(101,'Maldives','MV'); -insert into country (id, countryname, countrycode) values(102,'Mali','ML'); -insert into country (id, countryname, countrycode) values(103,'Malta','MT'); -insert into country (id, countryname, countrycode) values(104,'Mauritius','MU'); -insert into country (id, countryname, countrycode) values(105,'Mexico','MX'); -insert into country (id, countryname, countrycode) values(106,'Moldova, Republic of','MD'); -insert into country (id, countryname, countrycode) values(107,'Monaco','MC'); -insert into country (id, countryname, countrycode) values(108,'Mongolia','MN'); -insert into country (id, countryname, countrycode) values(109,'Montserrat Is','MS'); -insert into country (id, countryname, countrycode) values(110,'Morocco','MA'); -insert into country (id, countryname, countrycode) values(111,'Mozambique','MZ'); -insert into country (id, countryname, countrycode) values(112,'Namibia','NA'); -insert into country (id, countryname, countrycode) values(113,'Nauru','NR'); -insert into country (id, countryname, countrycode) values(114,'Nepal','NP'); -insert into country (id, countryname, countrycode) values(115,'Netherlands','NL'); -insert into country (id, countryname, countrycode) values(116,'New Zealand','NZ'); -insert into country (id, countryname, countrycode) values(117,'Nicaragua','NI'); -insert into country (id, countryname, countrycode) values(118,'Niger','NE'); -insert into country (id, countryname, countrycode) values(119,'Nigeria','NG'); -insert into country (id, countryname, countrycode) values(120,'North Korea','KP'); -insert into country (id, countryname, countrycode) values(121,'Norway','NO'); -insert into country (id, countryname, countrycode) values(122,'Oman','OM'); -insert into country (id, countryname, countrycode) values(123,'Pakistan','PK'); -insert into country (id, countryname, countrycode) values(124,'Panama','PA'); -insert into country (id, countryname, countrycode) values(125,'Papua New Cuinea','PG'); -insert into country (id, countryname, countrycode) values(126,'Paraguay','PY'); -insert into country (id, countryname, countrycode) values(127,'Peru','PE'); -insert into country (id, countryname, countrycode) values(128,'Philippines','PH'); -insert into country (id, countryname, countrycode) values(129,'Poland','PL'); -insert into country (id, countryname, countrycode) values(130,'French Polynesia','PF'); -insert into country (id, countryname, countrycode) values(131,'Portugal','PT'); -insert into country (id, countryname, countrycode) values(132,'Puerto Rico','PR'); -insert into country (id, countryname, countrycode) values(133,'Qatar','QA'); -insert into country (id, countryname, countrycode) values(134,'Romania','RO'); -insert into country (id, countryname, countrycode) values(135,'Russia','RU'); -insert into country (id, countryname, countrycode) values(136,'Saint Lueia','LC'); -insert into country (id, countryname, countrycode) values(137,'Saint Vincent','VC'); -insert into country (id, countryname, countrycode) values(138,'San Marino','SM'); -insert into country (id, countryname, countrycode) values(139,'Sao Tome and Principe','ST'); -insert into country (id, countryname, countrycode) values(140,'Saudi Arabia','SA'); -insert into country (id, countryname, countrycode) values(141,'Senegal','SN'); -insert into country (id, countryname, countrycode) values(142,'Seychelles','SC'); -insert into country (id, countryname, countrycode) values(143,'Sierra Leone','SL'); -insert into country (id, countryname, countrycode) values(144,'Singapore','SG'); -insert into country (id, countryname, countrycode) values(145,'Slovakia','SK'); -insert into country (id, countryname, countrycode) values(146,'Slovenia','SI'); -insert into country (id, countryname, countrycode) values(147,'Solomon Is','SB'); -insert into country (id, countryname, countrycode) values(148,'Somali','SO'); -insert into country (id, countryname, countrycode) values(149,'South Africa','ZA'); -insert into country (id, countryname, countrycode) values(150,'Spain','ES'); -insert into country (id, countryname, countrycode) values(151,'Sri Lanka','LK'); -insert into country (id, countryname, countrycode) values(152,'St.Lucia','LC'); -insert into country (id, countryname, countrycode) values(153,'St.Vincent','VC'); -insert into country (id, countryname, countrycode) values(154,'Sudan','SD'); -insert into country (id, countryname, countrycode) values(155,'Suriname','SR'); -insert into country (id, countryname, countrycode) values(156,'Swaziland','SZ'); -insert into country (id, countryname, countrycode) values(157,'Sweden','SE'); -insert into country (id, countryname, countrycode) values(158,'Switzerland','CH'); -insert into country (id, countryname, countrycode) values(159,'Syria','SY'); -insert into country (id, countryname, countrycode) values(160,'Taiwan','TW'); -insert into country (id, countryname, countrycode) values(161,'Tajikstan','TJ'); -insert into country (id, countryname, countrycode) values(162,'Tanzania','TZ'); -insert into country (id, countryname, countrycode) values(163,'Thailand','TH'); -insert into country (id, countryname, countrycode) values(164,'Togo','TG'); -insert into country (id, countryname, countrycode) values(165,'Tonga','TO'); -insert into country (id, countryname, countrycode) values(166,'Trinidad and Tobago','TT'); -insert into country (id, countryname, countrycode) values(167,'Tunisia','TN'); -insert into country (id, countryname, countrycode) values(168,'Turkey','TR'); -insert into country (id, countryname, countrycode) values(169,'Turkmenistan','TM'); -insert into country (id, countryname, countrycode) values(170,'Uganda','UG'); -insert into country (id, countryname, countrycode) values(171,'Ukraine','UA'); -insert into country (id, countryname, countrycode) values(172,'United Arab Emirates','AE'); -insert into country (id, countryname, countrycode) values(173,'United Kiongdom','GB'); -insert into country (id, countryname, countrycode) values(174,'United States of America','US'); -insert into country (id, countryname, countrycode) values(175,'Uruguay','UY'); -insert into country (id, countryname, countrycode) values(176,'Uzbekistan','UZ'); -insert into country (id, countryname, countrycode) values(177,'Venezuela','VE'); -insert into country (id, countryname, countrycode) values(178,'Vietnam','VN'); -insert into country (id, countryname, countrycode) values(179,'Yemen','YE'); -insert into country (id, countryname, countrycode) values(180,'Yugoslavia','YU'); -insert into country (id, countryname, countrycode) values(181,'Zimbabwe','ZW'); -insert into country (id, countryname, countrycode) values(182,'Zaire','ZR'); -insert into country (id, countryname, countrycode) values(183,'Zambia','ZM'); \ No newline at end of file +insert into country (id, countryname, countrycode) +values (1, 'Angola', 'AO'); +insert into country (id, countryname, countrycode) +values (2, 'Afghanistan', 'AF'); +insert into country (id, countryname, countrycode) +values (3, 'Albania', 'AL'); +insert into country (id, countryname, countrycode) +values (4, 'Algeria', 'DZ'); +insert into country (id, countryname, countrycode) +values (5, 'Andorra', 'AD'); +insert into country (id, countryname, countrycode) +values (6, 'Anguilla', 'AI'); +insert into country (id, countryname, countrycode) +values (7, 'Antigua and Barbuda', 'AG'); +insert into country (id, countryname, countrycode) +values (8, 'Argentina', 'AR'); +insert into country (id, countryname, countrycode) +values (9, 'Armenia', 'AM'); +insert into country (id, countryname, countrycode) +values (10, 'Australia', 'AU'); +insert into country (id, countryname, countrycode) +values (11, 'Austria', 'AT'); +insert into country (id, countryname, countrycode) +values (12, 'Azerbaijan', 'AZ'); +insert into country (id, countryname, countrycode) +values (13, 'Bahamas', 'BS'); +insert into country (id, countryname, countrycode) +values (14, 'Bahrain', 'BH'); +insert into country (id, countryname, countrycode) +values (15, 'Bangladesh', 'BD'); +insert into country (id, countryname, countrycode) +values (16, 'Barbados', 'BB'); +insert into country (id, countryname, countrycode) +values (17, 'Belarus', 'BY'); +insert into country (id, countryname, countrycode) +values (18, 'Belgium', 'BE'); +insert into country (id, countryname, countrycode) +values (19, 'Belize', 'BZ'); +insert into country (id, countryname, countrycode) +values (20, 'Benin', 'BJ'); +insert into country (id, countryname, countrycode) +values (21, 'Bermuda Is.', 'BM'); +insert into country (id, countryname, countrycode) +values (22, 'Bolivia', 'BO'); +insert into country (id, countryname, countrycode) +values (23, 'Botswana', 'BW'); +insert into country (id, countryname, countrycode) +values (24, 'Brazil', 'BR'); +insert into country (id, countryname, countrycode) +values (25, 'Brunei', 'BN'); +insert into country (id, countryname, countrycode) +values (26, 'Bulgaria', 'BG'); +insert into country (id, countryname, countrycode) +values (27, 'Burkina-faso', 'BF'); +insert into country (id, countryname, countrycode) +values (28, 'Burma', 'MM'); +insert into country (id, countryname, countrycode) +values (29, 'Burundi', 'BI'); +insert into country (id, countryname, countrycode) +values (30, 'Cameroon', 'CM'); +insert into country (id, countryname, countrycode) +values (31, 'Canada', 'CA'); +insert into country (id, countryname, countrycode) +values (32, 'Central African Republic', 'CF'); +insert into country (id, countryname, countrycode) +values (33, 'Chad', 'TD'); +insert into country (id, countryname, countrycode) +values (34, 'Chile', 'CL'); +insert into country (id, countryname, countrycode) +values (35, 'China', 'CN'); +insert into country (id, countryname, countrycode) +values (36, 'Colombia', 'CO'); +insert into country (id, countryname, countrycode) +values (37, 'Congo', 'CG'); +insert into country (id, countryname, countrycode) +values (38, 'Cook Is.', 'CK'); +insert into country (id, countryname, countrycode) +values (39, 'Costa Rica', 'CR'); +insert into country (id, countryname, countrycode) +values (40, 'Cuba', 'CU'); +insert into country (id, countryname, countrycode) +values (41, 'Cyprus', 'CY'); +insert into country (id, countryname, countrycode) +values (42, 'Czech Republic', 'CZ'); +insert into country (id, countryname, countrycode) +values (43, 'Denmark', 'DK'); +insert into country (id, countryname, countrycode) +values (44, 'Djibouti', 'DJ'); +insert into country (id, countryname, countrycode) +values (45, 'Dominica Rep.', 'DO'); +insert into country (id, countryname, countrycode) +values (46, 'Ecuador', 'EC'); +insert into country (id, countryname, countrycode) +values (47, 'Egypt', 'EG'); +insert into country (id, countryname, countrycode) +values (48, 'EI Salvador', 'SV'); +insert into country (id, countryname, countrycode) +values (49, 'Estonia', 'EE'); +insert into country (id, countryname, countrycode) +values (50, 'Ethiopia', 'ET'); +insert into country (id, countryname, countrycode) +values (51, 'Fiji', 'FJ'); +insert into country (id, countryname, countrycode) +values (52, 'Finland', 'FI'); +insert into country (id, countryname, countrycode) +values (53, 'France', 'FR'); +insert into country (id, countryname, countrycode) +values (54, 'French Guiana', 'GF'); +insert into country (id, countryname, countrycode) +values (55, 'Gabon', 'GA'); +insert into country (id, countryname, countrycode) +values (56, 'Gambia', 'GM'); +insert into country (id, countryname, countrycode) +values (57, 'Georgia', 'GE'); +insert into country (id, countryname, countrycode) +values (58, 'Germany', 'DE'); +insert into country (id, countryname, countrycode) +values (59, 'Ghana', 'GH'); +insert into country (id, countryname, countrycode) +values (60, 'Gibraltar', 'GI'); +insert into country (id, countryname, countrycode) +values (61, 'Greece', 'GR'); +insert into country (id, countryname, countrycode) +values (62, 'Grenada', 'GD'); +insert into country (id, countryname, countrycode) +values (63, 'Guam', 'GU'); +insert into country (id, countryname, countrycode) +values (64, 'Guatemala', 'GT'); +insert into country (id, countryname, countrycode) +values (65, 'Guinea', 'GN'); +insert into country (id, countryname, countrycode) +values (66, 'Guyana', 'GY'); +insert into country (id, countryname, countrycode) +values (67, 'Haiti', 'HT'); +insert into country (id, countryname, countrycode) +values (68, 'Honduras', 'HN'); +insert into country (id, countryname, countrycode) +values (69, 'Hongkong', 'HK'); +insert into country (id, countryname, countrycode) +values (70, 'Hungary', 'HU'); +insert into country (id, countryname, countrycode) +values (71, 'Iceland', 'IS'); +insert into country (id, countryname, countrycode) +values (72, 'India', 'IN'); +insert into country (id, countryname, countrycode) +values (73, 'Indonesia', 'ID'); +insert into country (id, countryname, countrycode) +values (74, 'Iran', 'IR'); +insert into country (id, countryname, countrycode) +values (75, 'Iraq', 'IQ'); +insert into country (id, countryname, countrycode) +values (76, 'Ireland', 'IE'); +insert into country (id, countryname, countrycode) +values (77, 'Israel', 'IL'); +insert into country (id, countryname, countrycode) +values (78, 'Italy', 'IT'); +insert into country (id, countryname, countrycode) +values (79, 'Jamaica', 'JM'); +insert into country (id, countryname, countrycode) +values (80, 'Japan', 'JP'); +insert into country (id, countryname, countrycode) +values (81, 'Jordan', 'JO'); +insert into country (id, countryname, countrycode) +values (82, 'Kampuchea (Cambodia )', 'KH'); +insert into country (id, countryname, countrycode) +values (83, 'Kazakstan', 'KZ'); +insert into country (id, countryname, countrycode) +values (84, 'Kenya', 'KE'); +insert into country (id, countryname, countrycode) +values (85, 'Korea', 'KR'); +insert into country (id, countryname, countrycode) +values (86, 'Kuwait', 'KW'); +insert into country (id, countryname, countrycode) +values (87, 'Kyrgyzstan', 'KG'); +insert into country (id, countryname, countrycode) +values (88, 'Laos', 'LA'); +insert into country (id, countryname, countrycode) +values (89, 'Latvia', 'LV'); +insert into country (id, countryname, countrycode) +values (90, 'Lebanon', 'LB'); +insert into country (id, countryname, countrycode) +values (91, 'Lesotho', 'LS'); +insert into country (id, countryname, countrycode) +values (92, 'Liberia', 'LR'); +insert into country (id, countryname, countrycode) +values (93, 'Libya', 'LY'); +insert into country (id, countryname, countrycode) +values (94, 'Liechtenstein', 'LI'); +insert into country (id, countryname, countrycode) +values (95, 'Lithuania', 'LT'); +insert into country (id, countryname, countrycode) +values (96, 'Luxembourg', 'LU'); +insert into country (id, countryname, countrycode) +values (97, 'Macao', 'MO'); +insert into country (id, countryname, countrycode) +values (98, 'Madagascar', 'MG'); +insert into country (id, countryname, countrycode) +values (99, 'Malawi', 'MW'); +insert into country (id, countryname, countrycode) +values (100, 'Malaysia', 'MY'); +insert into country (id, countryname, countrycode) +values (101, 'Maldives', 'MV'); +insert into country (id, countryname, countrycode) +values (102, 'Mali', 'ML'); +insert into country (id, countryname, countrycode) +values (103, 'Malta', 'MT'); +insert into country (id, countryname, countrycode) +values (104, 'Mauritius', 'MU'); +insert into country (id, countryname, countrycode) +values (105, 'Mexico', 'MX'); +insert into country (id, countryname, countrycode) +values (106, 'Moldova, Republic of', 'MD'); +insert into country (id, countryname, countrycode) +values (107, 'Monaco', 'MC'); +insert into country (id, countryname, countrycode) +values (108, 'Mongolia', 'MN'); +insert into country (id, countryname, countrycode) +values (109, 'Montserrat Is', 'MS'); +insert into country (id, countryname, countrycode) +values (110, 'Morocco', 'MA'); +insert into country (id, countryname, countrycode) +values (111, 'Mozambique', 'MZ'); +insert into country (id, countryname, countrycode) +values (112, 'Namibia', 'NA'); +insert into country (id, countryname, countrycode) +values (113, 'Nauru', 'NR'); +insert into country (id, countryname, countrycode) +values (114, 'Nepal', 'NP'); +insert into country (id, countryname, countrycode) +values (115, 'Netherlands', 'NL'); +insert into country (id, countryname, countrycode) +values (116, 'New Zealand', 'NZ'); +insert into country (id, countryname, countrycode) +values (117, 'Nicaragua', 'NI'); +insert into country (id, countryname, countrycode) +values (118, 'Niger', 'NE'); +insert into country (id, countryname, countrycode) +values (119, 'Nigeria', 'NG'); +insert into country (id, countryname, countrycode) +values (120, 'North Korea', 'KP'); +insert into country (id, countryname, countrycode) +values (121, 'Norway', 'NO'); +insert into country (id, countryname, countrycode) +values (122, 'Oman', 'OM'); +insert into country (id, countryname, countrycode) +values (123, 'Pakistan', 'PK'); +insert into country (id, countryname, countrycode) +values (124, 'Panama', 'PA'); +insert into country (id, countryname, countrycode) +values (125, 'Papua New Cuinea', 'PG'); +insert into country (id, countryname, countrycode) +values (126, 'Paraguay', 'PY'); +insert into country (id, countryname, countrycode) +values (127, 'Peru', 'PE'); +insert into country (id, countryname, countrycode) +values (128, 'Philippines', 'PH'); +insert into country (id, countryname, countrycode) +values (129, 'Poland', 'PL'); +insert into country (id, countryname, countrycode) +values (130, 'French Polynesia', 'PF'); +insert into country (id, countryname, countrycode) +values (131, 'Portugal', 'PT'); +insert into country (id, countryname, countrycode) +values (132, 'Puerto Rico', 'PR'); +insert into country (id, countryname, countrycode) +values (133, 'Qatar', 'QA'); +insert into country (id, countryname, countrycode) +values (134, 'Romania', 'RO'); +insert into country (id, countryname, countrycode) +values (135, 'Russia', 'RU'); +insert into country (id, countryname, countrycode) +values (136, 'Saint Lueia', 'LC'); +insert into country (id, countryname, countrycode) +values (137, 'Saint Vincent', 'VC'); +insert into country (id, countryname, countrycode) +values (138, 'San Marino', 'SM'); +insert into country (id, countryname, countrycode) +values (139, 'Sao Tome and Principe', 'ST'); +insert into country (id, countryname, countrycode) +values (140, 'Saudi Arabia', 'SA'); +insert into country (id, countryname, countrycode) +values (141, 'Senegal', 'SN'); +insert into country (id, countryname, countrycode) +values (142, 'Seychelles', 'SC'); +insert into country (id, countryname, countrycode) +values (143, 'Sierra Leone', 'SL'); +insert into country (id, countryname, countrycode) +values (144, 'Singapore', 'SG'); +insert into country (id, countryname, countrycode) +values (145, 'Slovakia', 'SK'); +insert into country (id, countryname, countrycode) +values (146, 'Slovenia', 'SI'); +insert into country (id, countryname, countrycode) +values (147, 'Solomon Is', 'SB'); +insert into country (id, countryname, countrycode) +values (148, 'Somali', 'SO'); +insert into country (id, countryname, countrycode) +values (149, 'South Africa', 'ZA'); +insert into country (id, countryname, countrycode) +values (150, 'Spain', 'ES'); +insert into country (id, countryname, countrycode) +values (151, 'Sri Lanka', 'LK'); +insert into country (id, countryname, countrycode) +values (152, 'St.Lucia', 'LC'); +insert into country (id, countryname, countrycode) +values (153, 'St.Vincent', 'VC'); +insert into country (id, countryname, countrycode) +values (154, 'Sudan', 'SD'); +insert into country (id, countryname, countrycode) +values (155, 'Suriname', 'SR'); +insert into country (id, countryname, countrycode) +values (156, 'Swaziland', 'SZ'); +insert into country (id, countryname, countrycode) +values (157, 'Sweden', 'SE'); +insert into country (id, countryname, countrycode) +values (158, 'Switzerland', 'CH'); +insert into country (id, countryname, countrycode) +values (159, 'Syria', 'SY'); +insert into country (id, countryname, countrycode) +values (160, 'Taiwan', 'TW'); +insert into country (id, countryname, countrycode) +values (161, 'Tajikstan', 'TJ'); +insert into country (id, countryname, countrycode) +values (162, 'Tanzania', 'TZ'); +insert into country (id, countryname, countrycode) +values (163, 'Thailand', 'TH'); +insert into country (id, countryname, countrycode) +values (164, 'Togo', 'TG'); +insert into country (id, countryname, countrycode) +values (165, 'Tonga', 'TO'); +insert into country (id, countryname, countrycode) +values (166, 'Trinidad and Tobago', 'TT'); +insert into country (id, countryname, countrycode) +values (167, 'Tunisia', 'TN'); +insert into country (id, countryname, countrycode) +values (168, 'Turkey', 'TR'); +insert into country (id, countryname, countrycode) +values (169, 'Turkmenistan', 'TM'); +insert into country (id, countryname, countrycode) +values (170, 'Uganda', 'UG'); +insert into country (id, countryname, countrycode) +values (171, 'Ukraine', 'UA'); +insert into country (id, countryname, countrycode) +values (172, 'United Arab Emirates', 'AE'); +insert into country (id, countryname, countrycode) +values (173, 'United Kiongdom', 'GB'); +insert into country (id, countryname, countrycode) +values (174, 'United States of America', 'US'); +insert into country (id, countryname, countrycode) +values (175, 'Uruguay', 'UY'); +insert into country (id, countryname, countrycode) +values (176, 'Uzbekistan', 'UZ'); +insert into country (id, countryname, countrycode) +values (177, 'Venezuela', 'VE'); +insert into country (id, countryname, countrycode) +values (178, 'Vietnam', 'VN'); +insert into country (id, countryname, countrycode) +values (179, 'Yemen', 'YE'); +insert into country (id, countryname, countrycode) +values (180, 'Yugoslavia', 'YU'); +insert into country (id, countryname, countrycode) +values (181, 'Zimbabwe', 'ZW'); +insert into country (id, countryname, countrycode) +values (182, 'Zaire', 'ZR'); +insert into country (id, countryname, countrycode) +values (183, 'Zambia', 'ZM'); \ No newline at end of file diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/tk/mybatis/sample/mapper/CountryMapper.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/tk/mybatis/sample/mapper/CountryMapper.xml index 96059b0d9..aa5fba297 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/tk/mybatis/sample/mapper/CountryMapper.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/tk/mybatis/sample/mapper/CountryMapper.xml @@ -28,6 +28,7 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> diff --git a/spring-boot-starter/mapper-spring-boot-samples/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/pom.xml index d0262fe9a..fad3c0241 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.1 + 4.2.2-SNAPSHOT mapper-spring-boot-samples pom diff --git a/spring-boot-starter/mapper-spring-boot-starter/pom.xml b/spring-boot-starter/mapper-spring-boot-starter/pom.xml index 46e1886b8..0c975e2ba 100644 --- a/spring-boot-starter/mapper-spring-boot-starter/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-starter/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.1 + 4.2.2-SNAPSHOT mapper-spring-boot-starter mapper-spring-boot-starter diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml index 6349aa18b..35712a128 100644 --- a/spring-boot-starter/pom.xml +++ b/spring-boot-starter/pom.xml @@ -29,10 +29,11 @@ tk.mybatis mapper-parent - 3 + 8 + mapper-spring-boot - 4.2.1 + 4.2.2-SNAPSHOT pom mapper-spring-boot @@ -45,13 +46,13 @@ mapper-spring-boot-samples - - 4.2.1 - 4.2.1 - 3.5.9 - 2.0.7 - 2.6.4 - + + 4.2.2-SNAPSHOT + 4.2.2-SNAPSHOT + 3.5.9 + 2.0.7 + 2.6.4 + diff --git a/spring/README.md b/spring/README.md index e5987e6b7..6e21e4807 100644 --- a/spring/README.md +++ b/spring/README.md @@ -86,10 +86,11 @@ ``` + 注意两点: - 1. 这里使用的 `tk.mybatis.spring.mapper.MapperScannerConfigurer`,不是官方的 `org.xxx` - 2. 所有对通用 Mapper 的配置,参考上面的 mappers=xxx,一行写一个配置即可 +1. 这里使用的 `tk.mybatis.spring.mapper.MapperScannerConfigurer`,不是官方的 `org.xxx` +2. 所有对通用 Mapper 的配置,参考上面的 mappers=xxx,一行写一个配置即可 ### 二、`@MapperScan` 注解 @@ -136,9 +137,10 @@ public static class MyBatisConfigRef { } ``` -在这个例子中 `@MapperScan` 唯一特殊的地方在于 `mapperHelperRef` 属性,这个属性用于指定 MapperHelper bean 的 `name`,这里的名字和代码中配置的 `mapperHelper()` 的方法名一致。 +在这个例子中 `@MapperScan` 唯一特殊的地方在于 `mapperHelperRef` 属性,这个属性用于指定 MapperHelper bean 的 `name`,这里的名字和代码中配置的 `mapperHelper()` +的方法名一致。 ->Spring 中默认的 name 就是方法名,还可以通过 `@Bean` 注解指定 `name`。 +> Spring 中默认的 name 就是方法名,还可以通过 `@Bean` 注解指定 `name`。 在这种配置方式中,你可以很方便的控制 `MapperHelper` 中的各项配置。 @@ -173,15 +175,17 @@ public static class MyBatisConfigProperties { } } ``` + 如上面代码中所示,这种配置方式和 xml bean 的方式比较接近,就是通过一行一行的 `xx=xxx` 对通用 Mapper 进行配置,配置时参考这里的示例配置即可。 #### 3. Spring Boot 环境中使用 `application.[yml|properties]` 配置文件 在 Spring Boot 中使用 Mapper 时,如果选择使用注解方式(可以不引入 mapper-starter 依赖),就可以选择这第 3 种方式。 ->特别提醒:Spring Boot 中常见的是配置文件方式,使用环境变量或者运行时的参数都可以配置,这些配置都可以对通用 Mapper 生效。 +> 特别提醒:Spring Boot 中常见的是配置文件方式,使用环境变量或者运行时的参数都可以配置,这些配置都可以对通用 Mapper 生效。 例如在 yml 格式中配置: + ```yml mapper: mappers: @@ -191,12 +195,13 @@ mapper: ``` 在 propertie 配置中: + ```properties mapper.mappers=tk.mybatis.mapper.common.Mapper,tk.mybatis.mapper.common.Mapper2 mapper.not-empty=true ``` ->特别提醒:Spring Boot 中支持 relax 方式的参数配置,但是前面两种方式都不支持,前两种配置参数的时候需要保证大小写一致! +> 特别提醒:Spring Boot 中支持 relax 方式的参数配置,但是前面两种方式都不支持,前两种配置参数的时候需要保证大小写一致! ### 三、`tk.mybatis.mapper.session.Configuration` 配置 @@ -222,6 +227,7 @@ public void addMappedStatement(MappedStatement ms) { ``` `tk.mybatis.mapper.session.Configuration` 提供了 3 种配置通用 Mapper 的方式,如下所示: + ```java /** * 直接注入 mapperHelper @@ -285,7 +291,7 @@ public void setConfig(Config config) { ``` ->特别注意:这种情况下的 MapperScannerConfigurer 是官方 mybatis-spring 中提供的类,不是 tk 开头的! +> 特别注意:这种情况下的 MapperScannerConfigurer 是官方 mybatis-spring 中提供的类,不是 tk 开头的! 参考这里的配置即可,注意和其他方式的区别。 diff --git a/spring/pom.xml b/spring/pom.xml index 8da4d0c60..0f09f4245 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.1 + 4.2.2-SNAPSHOT mapper-spring jar diff --git a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java index 677d2729e..12522df89 100644 --- a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java +++ b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java @@ -1,17 +1,17 @@ /** - * Copyright 2010-2016 the original author or authors. - * - * 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. + * Copyright 2010-2016 the original author or authors. + *

+ * 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 tk.mybatis.spring.annotation; diff --git a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java index 4872df054..953ff4728 100644 --- a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java +++ b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java @@ -103,8 +103,8 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B scanner.setMapperProperties(this.environment); } catch (Exception e) { LOGGER.warn("只有 Spring Boot 环境中可以通过 Environment(配置文件,环境变量,运行参数等方式) 配置通用 Mapper," + - "其他环境请通过 @MapperScan 注解中的 mapperHelperRef 或 properties 参数进行配置!" + - "如果你使用 tk.mybatis.mapper.session.Configuration 配置的通用 Mapper,你可以忽略该错误!", e); + "其他环境请通过 @MapperScan 注解中的 mapperHelperRef 或 properties 参数进行配置!" + + "如果你使用 tk.mybatis.mapper.session.Configuration 配置的通用 Mapper,你可以忽略该错误!", e); } } scanner.registerFilters(); diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java b/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java index bdd6e53e7..0fb49279f 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java @@ -124,11 +124,11 @@ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metada @Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { String className = metadataReader.getClassMetadata().getClassName(); - if(className.endsWith("package-info")){ + if (className.endsWith("package-info")) { return true; } return metadataReader.getAnnotationMetadata() - .hasAnnotation("tk.mybatis.mapper.annotation.RegisterMapper"); + .hasAnnotation("tk.mybatis.mapper.annotation.RegisterMapper"); } }); } @@ -166,11 +166,11 @@ private void processBeanDefinitions(Set beanDefinitions) { definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName()); // issue #59 definition.setBeanClass(this.mapperFactoryBean.getClass()); //设置通用 Mapper - if(StringUtils.hasText(this.mapperHelperBeanName)){ + if (StringUtils.hasText(this.mapperHelperBeanName)) { definition.getPropertyValues().add("mapperHelper", new RuntimeBeanReference(this.mapperHelperBeanName)); } else { //不做任何配置的时候使用默认方式 - if(this.mapperHelper == null){ + if (this.mapperHelper == null) { this.mapperHelper = new MapperHelper(); } definition.getPropertyValues().add("mapperHelper", this.mapperHelper); @@ -279,7 +279,7 @@ public void setMapperProperties(Environment environment) { if (mapperHelper == null) { mapperHelper = new MapperHelper(); } - if(config != null){ + if (config != null) { mapperHelper.setConfig(config); } } @@ -297,7 +297,7 @@ public void setMapperProperties(String[] properties) { for (String property : properties) { property = property.trim(); int index = property.indexOf("="); - if(index < 0){ + if (index < 0) { throw new MapperException("通过 @MapperScan 注解的 properties 参数配置出错:" + property + " !\n" + "请保证配置项按 properties 文件格式要求进行配置,例如:\n" + "properties = {\n" diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/MapperFactoryBean.java b/spring/src/main/java/tk/mybatis/spring/mapper/MapperFactoryBean.java index d97297684..032473d44 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/MapperFactoryBean.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/MapperFactoryBean.java @@ -1,17 +1,17 @@ /** - * Copyright 2010-2016 the original author or authors. - * - * 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. + * Copyright 2010-2016 the original author or authors. + *

+ * 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 tk.mybatis.spring.mapper; @@ -163,6 +163,7 @@ public void setAddToConfig(boolean addToConfig) { public void setMapperHelper(MapperHelper mapperHelper) { this.mapperHelper = mapperHelper; } + /** * {@inheritDoc} */ diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java b/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java index 39c85f683..1a3fda4ab 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java @@ -1,17 +1,17 @@ /** - * Copyright 2010-2016 the original author or authors. - * - * 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. + * Copyright 2010-2016 the original author or authors. + *

+ * 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 tk.mybatis.spring.mapper; diff --git a/spring/src/test/java/tk/mybatis/mapper/annotation/Country.java b/spring/src/test/java/tk/mybatis/mapper/annotation/Country.java index d2d333b0b..069b254d0 100644 --- a/spring/src/test/java/tk/mybatis/mapper/annotation/Country.java +++ b/spring/src/test/java/tk/mybatis/mapper/annotation/Country.java @@ -31,8 +31,8 @@ public class Country implements Serializable { private static final long serialVersionUID = 1L; @Id private Integer id; - private String countryname; - private String countrycode; + private String countryname; + private String countrycode; public String getCountrycode() { return countrycode; diff --git a/spring/src/test/java/tk/mybatis/mapper/annotation/SpringAnnotationTest.java b/spring/src/test/java/tk/mybatis/mapper/annotation/SpringAnnotationTest.java index 0c8d9cf99..fe273f3e0 100644 --- a/spring/src/test/java/tk/mybatis/mapper/annotation/SpringAnnotationTest.java +++ b/spring/src/test/java/tk/mybatis/mapper/annotation/SpringAnnotationTest.java @@ -117,10 +117,10 @@ public MapperHelper mapperHelper() { @Configuration @MapperScan(value = "tk.mybatis.mapper.annotation", - properties = { - "mappers=tk.mybatis.mapper.common.Mapper", - "notEmpty=true" - } + properties = { + "mappers=tk.mybatis.mapper.common.Mapper", + "notEmpty=true" + } ) public static class MyBatisConfigProperties { @Bean @@ -145,11 +145,11 @@ public SqlSessionFactory sqlSessionFactory() throws Exception { @Configuration @MapperScan(value = "tk.mybatis.mapper.annotation", - properties = { - //参数配置错误 - "mapperstk.mybatis.mapper.common.Mapper", - "notEmpty=true" - } + properties = { + //参数配置错误 + "mapperstk.mybatis.mapper.common.Mapper", + "notEmpty=true" + } ) public static class MyBatisConfigPropertiesError { @Bean diff --git a/spring/src/test/java/tk/mybatis/mapper/configuration/Country.java b/spring/src/test/java/tk/mybatis/mapper/configuration/Country.java index 86324a689..28f2e1221 100644 --- a/spring/src/test/java/tk/mybatis/mapper/configuration/Country.java +++ b/spring/src/test/java/tk/mybatis/mapper/configuration/Country.java @@ -31,8 +31,8 @@ public class Country implements Serializable { private static final long serialVersionUID = 1L; @Id private Integer id; - private String countryname; - private String countrycode; + private String countryname; + private String countrycode; public String getCountrycode() { return countrycode; diff --git a/spring/src/test/java/tk/mybatis/mapper/configuration/CreateDB.sql b/spring/src/test/java/tk/mybatis/mapper/configuration/CreateDB.sql index dec01e398..f4f2795f4 100644 --- a/spring/src/test/java/tk/mybatis/mapper/configuration/CreateDB.sql +++ b/spring/src/test/java/tk/mybatis/mapper/configuration/CreateDB.sql @@ -1,193 +1,377 @@ drop table country if exists; -create table country ( - id integer NOT NULL PRIMARY KEY, - countryname varchar(32), - countrycode VARCHAR(2) DEFAULT 'HH', - version INTEGER DEFAULT 1 NOT NULL +create table country +( + id integer NOT NULL PRIMARY KEY, + countryname varchar(32), + countrycode VARCHAR(2) DEFAULT 'HH', + version INTEGER DEFAULT 1 NOT NULL ); -INSERT INTO country (id, countryname, countrycode, version) VALUES (1, 'Angola', 'AO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (2, 'Afghanistan', 'AF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (3, 'Albania', 'AL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (4, 'Algeria', 'DZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (5, 'Andorra', 'AD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (6, 'Anguilla', 'AI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (7, 'Antigua and Barbuda', 'AG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (8, 'Argentina', 'AR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (9, 'Armenia', 'AM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (10, 'Australia', 'AU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (11, 'Austria', 'AT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (12, 'Azerbaijan', 'AZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (13, 'Bahamas', 'BS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (14, 'Bahrain', 'BH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (15, 'Bangladesh', 'BD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (16, 'Barbados', 'BB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (17, 'Belarus', 'BY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (18, 'Belgium', 'BE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (19, 'Belize', 'BZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (20, 'Benin', 'BJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (21, 'Bermuda Is.', 'BM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (22, 'Bolivia', 'BO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (23, 'Botswana', 'BW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (24, 'Brazil', 'BR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (25, 'Brunei', 'BN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (26, 'Bulgaria', 'BG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (27, 'Burkina-faso', 'BF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (28, 'Burma', 'MM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (29, 'Burundi', 'BI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (30, 'Cameroon', 'CM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (31, 'Canada', 'CA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (32, 'Central African Republic', 'CF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (33, 'Chad', 'TD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (34, 'Chile', 'CL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (35, 'China', 'CN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (36, 'Colombia', 'CO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (37, 'Congo', 'CG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (38, 'Cook Is.', 'CK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (39, 'Costa Rica', 'CR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (40, 'Cuba', 'CU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (41, 'Cyprus', 'CY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (42, 'Czech Republic', 'CZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (43, 'Denmark', 'DK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (44, 'Djibouti', 'DJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (45, 'Dominica Rep.', 'DO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (46, 'Ecuador', 'EC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (47, 'Egypt', 'EG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (48, 'EI Salvador', 'SV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (49, 'Estonia', 'EE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (50, 'Ethiopia', 'ET', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (51, 'Fiji', 'FJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (52, 'Finland', 'FI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (53, 'France', 'FR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (54, 'French Guiana', 'GF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (55, 'Gabon', 'GA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (56, 'Gambia', 'GM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (57, 'Georgia', 'GE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (58, 'Germany', 'DE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (59, 'Ghana', 'GH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (60, 'Gibraltar', 'GI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (61, 'Greece', 'GR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (62, 'Grenada', 'GD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (63, 'Guam', 'GU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (64, 'Guatemala', 'GT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (65, 'Guinea', 'GN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (66, 'Guyana', 'GY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (67, 'Haiti', 'HT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (68, 'Honduras', 'HN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (69, 'Hongkong', 'HK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (70, 'Hungary', 'HU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (71, 'Iceland', 'IS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (72, 'India', 'IN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (73, 'Indonesia', 'ID', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (74, 'Iran', 'IR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (75, 'Iraq', 'IQ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (76, 'Ireland', 'IE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (77, 'Israel', 'IL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (78, 'Italy', 'IT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (79, 'Jamaica', 'JM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (80, 'Japan', 'JP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (81, 'Jordan', 'JO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (83, 'Kazakstan', 'KZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (84, 'Kenya', 'KE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (85, 'Korea', 'KR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (86, 'Kuwait', 'KW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (87, 'Kyrgyzstan', 'KG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (88, 'Laos', 'LA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (89, 'Latvia', 'LV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (90, 'Lebanon', 'LB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (91, 'Lesotho', 'LS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (92, 'Liberia', 'LR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (93, 'Libya', 'LY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (94, 'Liechtenstein', 'LI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (95, 'Lithuania', 'LT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (96, 'Luxembourg', 'LU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (97, 'Macao', 'MO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (98, 'Madagascar', 'MG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (99, 'Malawi', 'MW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (100, 'Malaysia', 'MY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (101, 'Maldives', 'MV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (102, 'Mali', 'ML', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (103, 'Malta', 'MT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (104, 'Mauritius', 'MU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (105, 'Mexico', 'MX', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (106, 'Moldova, Republic of', 'MD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (107, 'Monaco', 'MC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (108, 'Mongolia', 'MN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (109, 'Montserrat Is', 'MS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (110, 'Morocco', 'MA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (111, 'Mozambique', 'MZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (112, 'Namibia', 'NA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (113, 'Nauru', 'NR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (114, 'Nepal', 'NP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (115, 'Netherlands', 'NL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (116, 'New Zealand', 'NZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (117, 'Nicaragua', 'NI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (118, 'Niger', 'NE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (119, 'Nigeria', 'NG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (120, 'North Korea', 'KP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (121, 'Norway', 'NO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (122, 'Oman', 'OM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (123, 'Pakistan', 'PK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (124, 'Panama', 'PA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (125, 'Papua New Cuinea', 'PG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (126, 'Paraguay', 'PY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (127, 'Peru', 'PE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (128, 'Philippines', 'PH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (129, 'Poland', 'PL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (130, 'French Polynesia', 'PF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (131, 'Portugal', 'PT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (132, 'Puerto Rico', 'PR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (133, 'Qatar', 'QA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (134, 'Romania', 'RO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (135, 'Russia', 'RU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (136, 'Saint Lueia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (137, 'Saint Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (138, 'San Marino', 'SM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (139, 'Sao Tome and Principe', 'ST', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (140, 'Saudi Arabia', 'SA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (141, 'Senegal', 'SN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (142, 'Seychelles', 'SC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (143, 'Sierra Leone', 'SL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (144, 'Singapore', 'SG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (145, 'Slovakia', 'SK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (146, 'Slovenia', 'SI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (147, 'Solomon Is', 'SB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (148, 'Somali', 'SO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (149, 'South Africa', 'ZA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (150, 'Spain', 'ES', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (151, 'Sri Lanka', 'LK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (152, 'St.Lucia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (153, 'St.Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (154, 'Sudan', 'SD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (155, 'Suriname', 'SR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (156, 'Swaziland', 'SZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (157, 'Sweden', 'SE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (158, 'Switzerland', 'CH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (159, 'Syria', 'SY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (160, 'Taiwan', 'TW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (161, 'Tajikstan', 'TJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (162, 'Tanzania', 'TZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (163, 'Thailand', 'TH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (164, 'Togo', 'TG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (165, 'Tonga', 'TO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (166, 'Trinidad and Tobago', 'TT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (167, 'Tunisia', 'TN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (168, 'Turkey', 'TR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (169, 'Turkmenistan', 'TM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (170, 'Uganda', 'UG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (171, 'Ukraine', 'UA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (172, 'United Arab Emirates', 'AE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (173, 'United Kiongdom', 'GB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (174, 'United States of America', 'US', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (175, 'Uruguay', 'UY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (176, 'Uzbekistan', 'UZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (177, 'Venezuela', 'VE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (178, 'Vietnam', 'VN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (179, 'Yemen', 'YE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (180, 'Yugoslavia', 'YU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (181, 'Zimbabwe', 'ZW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (182, 'Zaire', 'ZR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (183, 'Zambia', 'ZM', 1); \ No newline at end of file +INSERT INTO country (id, countryname, countrycode, version) +VALUES (1, 'Angola', 'AO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (2, 'Afghanistan', 'AF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (3, 'Albania', 'AL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (4, 'Algeria', 'DZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (5, 'Andorra', 'AD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (6, 'Anguilla', 'AI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (7, 'Antigua and Barbuda', 'AG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (8, 'Argentina', 'AR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (9, 'Armenia', 'AM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (10, 'Australia', 'AU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (11, 'Austria', 'AT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (12, 'Azerbaijan', 'AZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (13, 'Bahamas', 'BS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (14, 'Bahrain', 'BH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (15, 'Bangladesh', 'BD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (16, 'Barbados', 'BB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (17, 'Belarus', 'BY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (18, 'Belgium', 'BE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (19, 'Belize', 'BZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (20, 'Benin', 'BJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (21, 'Bermuda Is.', 'BM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (22, 'Bolivia', 'BO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (23, 'Botswana', 'BW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (24, 'Brazil', 'BR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (25, 'Brunei', 'BN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (26, 'Bulgaria', 'BG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (27, 'Burkina-faso', 'BF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (28, 'Burma', 'MM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (29, 'Burundi', 'BI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (30, 'Cameroon', 'CM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (31, 'Canada', 'CA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (32, 'Central African Republic', 'CF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (33, 'Chad', 'TD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (34, 'Chile', 'CL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (35, 'China', 'CN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (36, 'Colombia', 'CO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (37, 'Congo', 'CG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (38, 'Cook Is.', 'CK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (39, 'Costa Rica', 'CR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (40, 'Cuba', 'CU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (41, 'Cyprus', 'CY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (42, 'Czech Republic', 'CZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (43, 'Denmark', 'DK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (44, 'Djibouti', 'DJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (45, 'Dominica Rep.', 'DO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (46, 'Ecuador', 'EC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (47, 'Egypt', 'EG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (48, 'EI Salvador', 'SV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (49, 'Estonia', 'EE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (50, 'Ethiopia', 'ET', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (51, 'Fiji', 'FJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (52, 'Finland', 'FI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (53, 'France', 'FR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (54, 'French Guiana', 'GF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (55, 'Gabon', 'GA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (56, 'Gambia', 'GM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (57, 'Georgia', 'GE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (58, 'Germany', 'DE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (59, 'Ghana', 'GH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (60, 'Gibraltar', 'GI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (61, 'Greece', 'GR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (62, 'Grenada', 'GD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (63, 'Guam', 'GU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (64, 'Guatemala', 'GT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (65, 'Guinea', 'GN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (66, 'Guyana', 'GY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (67, 'Haiti', 'HT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (68, 'Honduras', 'HN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (69, 'Hongkong', 'HK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (70, 'Hungary', 'HU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (71, 'Iceland', 'IS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (72, 'India', 'IN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (73, 'Indonesia', 'ID', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (74, 'Iran', 'IR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (75, 'Iraq', 'IQ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (76, 'Ireland', 'IE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (77, 'Israel', 'IL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (78, 'Italy', 'IT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (79, 'Jamaica', 'JM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (80, 'Japan', 'JP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (81, 'Jordan', 'JO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (83, 'Kazakstan', 'KZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (84, 'Kenya', 'KE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (85, 'Korea', 'KR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (86, 'Kuwait', 'KW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (87, 'Kyrgyzstan', 'KG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (88, 'Laos', 'LA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (89, 'Latvia', 'LV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (90, 'Lebanon', 'LB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (91, 'Lesotho', 'LS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (92, 'Liberia', 'LR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (93, 'Libya', 'LY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (94, 'Liechtenstein', 'LI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (95, 'Lithuania', 'LT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (96, 'Luxembourg', 'LU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (97, 'Macao', 'MO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (98, 'Madagascar', 'MG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (99, 'Malawi', 'MW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (100, 'Malaysia', 'MY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (101, 'Maldives', 'MV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (102, 'Mali', 'ML', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (103, 'Malta', 'MT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (104, 'Mauritius', 'MU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (105, 'Mexico', 'MX', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (106, 'Moldova, Republic of', 'MD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (107, 'Monaco', 'MC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (108, 'Mongolia', 'MN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (109, 'Montserrat Is', 'MS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (110, 'Morocco', 'MA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (111, 'Mozambique', 'MZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (112, 'Namibia', 'NA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (113, 'Nauru', 'NR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (114, 'Nepal', 'NP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (115, 'Netherlands', 'NL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (116, 'New Zealand', 'NZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (117, 'Nicaragua', 'NI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (118, 'Niger', 'NE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (119, 'Nigeria', 'NG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (120, 'North Korea', 'KP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (121, 'Norway', 'NO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (122, 'Oman', 'OM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (123, 'Pakistan', 'PK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (124, 'Panama', 'PA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (125, 'Papua New Cuinea', 'PG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (126, 'Paraguay', 'PY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (127, 'Peru', 'PE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (128, 'Philippines', 'PH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (129, 'Poland', 'PL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (130, 'French Polynesia', 'PF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (131, 'Portugal', 'PT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (132, 'Puerto Rico', 'PR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (133, 'Qatar', 'QA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (134, 'Romania', 'RO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (135, 'Russia', 'RU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (136, 'Saint Lueia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (137, 'Saint Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (138, 'San Marino', 'SM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (139, 'Sao Tome and Principe', 'ST', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (140, 'Saudi Arabia', 'SA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (141, 'Senegal', 'SN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (142, 'Seychelles', 'SC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (143, 'Sierra Leone', 'SL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (144, 'Singapore', 'SG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (145, 'Slovakia', 'SK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (146, 'Slovenia', 'SI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (147, 'Solomon Is', 'SB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (148, 'Somali', 'SO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (149, 'South Africa', 'ZA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (150, 'Spain', 'ES', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (151, 'Sri Lanka', 'LK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (152, 'St.Lucia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (153, 'St.Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (154, 'Sudan', 'SD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (155, 'Suriname', 'SR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (156, 'Swaziland', 'SZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (157, 'Sweden', 'SE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (158, 'Switzerland', 'CH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (159, 'Syria', 'SY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (160, 'Taiwan', 'TW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (161, 'Tajikstan', 'TJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (162, 'Tanzania', 'TZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (163, 'Thailand', 'TH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (164, 'Togo', 'TG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (165, 'Tonga', 'TO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (166, 'Trinidad and Tobago', 'TT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (167, 'Tunisia', 'TN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (168, 'Turkey', 'TR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (169, 'Turkmenistan', 'TM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (170, 'Uganda', 'UG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (171, 'Ukraine', 'UA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (172, 'United Arab Emirates', 'AE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (173, 'United Kiongdom', 'GB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (174, 'United States of America', 'US', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (175, 'Uruguay', 'UY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (176, 'Uzbekistan', 'UZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (177, 'Venezuela', 'VE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (178, 'Vietnam', 'VN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (179, 'Yemen', 'YE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (180, 'Yugoslavia', 'YU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (181, 'Zimbabwe', 'ZW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (182, 'Zaire', 'ZR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (183, 'Zambia', 'ZM', 1); \ No newline at end of file diff --git a/spring/src/test/java/tk/mybatis/mapper/configuration/SpringConfigTest.java b/spring/src/test/java/tk/mybatis/mapper/configuration/SpringConfigTest.java index fd731094f..afa8a378e 100644 --- a/spring/src/test/java/tk/mybatis/mapper/configuration/SpringConfigTest.java +++ b/spring/src/test/java/tk/mybatis/mapper/configuration/SpringConfigTest.java @@ -3,6 +3,7 @@ import org.junit.Assert; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; + import java.util.List; /** diff --git a/spring/src/test/java/tk/mybatis/mapper/xml/Country.java b/spring/src/test/java/tk/mybatis/mapper/xml/Country.java index 87dbbd4dc..0baa38233 100644 --- a/spring/src/test/java/tk/mybatis/mapper/xml/Country.java +++ b/spring/src/test/java/tk/mybatis/mapper/xml/Country.java @@ -31,8 +31,8 @@ public class Country implements Serializable { private static final long serialVersionUID = 1L; @Id private Integer id; - private String countryname; - private String countrycode; + private String countryname; + private String countrycode; public String getCountrycode() { return countrycode; diff --git a/spring/src/test/java/tk/mybatis/mapper/xml/CreateDB.sql b/spring/src/test/java/tk/mybatis/mapper/xml/CreateDB.sql index dec01e398..f4f2795f4 100644 --- a/spring/src/test/java/tk/mybatis/mapper/xml/CreateDB.sql +++ b/spring/src/test/java/tk/mybatis/mapper/xml/CreateDB.sql @@ -1,193 +1,377 @@ drop table country if exists; -create table country ( - id integer NOT NULL PRIMARY KEY, - countryname varchar(32), - countrycode VARCHAR(2) DEFAULT 'HH', - version INTEGER DEFAULT 1 NOT NULL +create table country +( + id integer NOT NULL PRIMARY KEY, + countryname varchar(32), + countrycode VARCHAR(2) DEFAULT 'HH', + version INTEGER DEFAULT 1 NOT NULL ); -INSERT INTO country (id, countryname, countrycode, version) VALUES (1, 'Angola', 'AO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (2, 'Afghanistan', 'AF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (3, 'Albania', 'AL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (4, 'Algeria', 'DZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (5, 'Andorra', 'AD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (6, 'Anguilla', 'AI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (7, 'Antigua and Barbuda', 'AG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (8, 'Argentina', 'AR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (9, 'Armenia', 'AM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (10, 'Australia', 'AU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (11, 'Austria', 'AT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (12, 'Azerbaijan', 'AZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (13, 'Bahamas', 'BS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (14, 'Bahrain', 'BH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (15, 'Bangladesh', 'BD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (16, 'Barbados', 'BB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (17, 'Belarus', 'BY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (18, 'Belgium', 'BE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (19, 'Belize', 'BZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (20, 'Benin', 'BJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (21, 'Bermuda Is.', 'BM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (22, 'Bolivia', 'BO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (23, 'Botswana', 'BW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (24, 'Brazil', 'BR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (25, 'Brunei', 'BN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (26, 'Bulgaria', 'BG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (27, 'Burkina-faso', 'BF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (28, 'Burma', 'MM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (29, 'Burundi', 'BI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (30, 'Cameroon', 'CM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (31, 'Canada', 'CA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (32, 'Central African Republic', 'CF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (33, 'Chad', 'TD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (34, 'Chile', 'CL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (35, 'China', 'CN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (36, 'Colombia', 'CO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (37, 'Congo', 'CG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (38, 'Cook Is.', 'CK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (39, 'Costa Rica', 'CR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (40, 'Cuba', 'CU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (41, 'Cyprus', 'CY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (42, 'Czech Republic', 'CZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (43, 'Denmark', 'DK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (44, 'Djibouti', 'DJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (45, 'Dominica Rep.', 'DO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (46, 'Ecuador', 'EC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (47, 'Egypt', 'EG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (48, 'EI Salvador', 'SV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (49, 'Estonia', 'EE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (50, 'Ethiopia', 'ET', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (51, 'Fiji', 'FJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (52, 'Finland', 'FI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (53, 'France', 'FR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (54, 'French Guiana', 'GF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (55, 'Gabon', 'GA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (56, 'Gambia', 'GM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (57, 'Georgia', 'GE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (58, 'Germany', 'DE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (59, 'Ghana', 'GH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (60, 'Gibraltar', 'GI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (61, 'Greece', 'GR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (62, 'Grenada', 'GD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (63, 'Guam', 'GU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (64, 'Guatemala', 'GT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (65, 'Guinea', 'GN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (66, 'Guyana', 'GY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (67, 'Haiti', 'HT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (68, 'Honduras', 'HN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (69, 'Hongkong', 'HK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (70, 'Hungary', 'HU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (71, 'Iceland', 'IS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (72, 'India', 'IN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (73, 'Indonesia', 'ID', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (74, 'Iran', 'IR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (75, 'Iraq', 'IQ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (76, 'Ireland', 'IE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (77, 'Israel', 'IL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (78, 'Italy', 'IT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (79, 'Jamaica', 'JM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (80, 'Japan', 'JP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (81, 'Jordan', 'JO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (83, 'Kazakstan', 'KZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (84, 'Kenya', 'KE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (85, 'Korea', 'KR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (86, 'Kuwait', 'KW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (87, 'Kyrgyzstan', 'KG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (88, 'Laos', 'LA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (89, 'Latvia', 'LV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (90, 'Lebanon', 'LB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (91, 'Lesotho', 'LS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (92, 'Liberia', 'LR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (93, 'Libya', 'LY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (94, 'Liechtenstein', 'LI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (95, 'Lithuania', 'LT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (96, 'Luxembourg', 'LU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (97, 'Macao', 'MO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (98, 'Madagascar', 'MG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (99, 'Malawi', 'MW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (100, 'Malaysia', 'MY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (101, 'Maldives', 'MV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (102, 'Mali', 'ML', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (103, 'Malta', 'MT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (104, 'Mauritius', 'MU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (105, 'Mexico', 'MX', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (106, 'Moldova, Republic of', 'MD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (107, 'Monaco', 'MC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (108, 'Mongolia', 'MN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (109, 'Montserrat Is', 'MS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (110, 'Morocco', 'MA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (111, 'Mozambique', 'MZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (112, 'Namibia', 'NA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (113, 'Nauru', 'NR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (114, 'Nepal', 'NP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (115, 'Netherlands', 'NL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (116, 'New Zealand', 'NZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (117, 'Nicaragua', 'NI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (118, 'Niger', 'NE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (119, 'Nigeria', 'NG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (120, 'North Korea', 'KP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (121, 'Norway', 'NO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (122, 'Oman', 'OM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (123, 'Pakistan', 'PK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (124, 'Panama', 'PA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (125, 'Papua New Cuinea', 'PG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (126, 'Paraguay', 'PY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (127, 'Peru', 'PE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (128, 'Philippines', 'PH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (129, 'Poland', 'PL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (130, 'French Polynesia', 'PF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (131, 'Portugal', 'PT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (132, 'Puerto Rico', 'PR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (133, 'Qatar', 'QA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (134, 'Romania', 'RO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (135, 'Russia', 'RU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (136, 'Saint Lueia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (137, 'Saint Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (138, 'San Marino', 'SM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (139, 'Sao Tome and Principe', 'ST', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (140, 'Saudi Arabia', 'SA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (141, 'Senegal', 'SN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (142, 'Seychelles', 'SC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (143, 'Sierra Leone', 'SL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (144, 'Singapore', 'SG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (145, 'Slovakia', 'SK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (146, 'Slovenia', 'SI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (147, 'Solomon Is', 'SB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (148, 'Somali', 'SO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (149, 'South Africa', 'ZA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (150, 'Spain', 'ES', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (151, 'Sri Lanka', 'LK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (152, 'St.Lucia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (153, 'St.Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (154, 'Sudan', 'SD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (155, 'Suriname', 'SR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (156, 'Swaziland', 'SZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (157, 'Sweden', 'SE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (158, 'Switzerland', 'CH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (159, 'Syria', 'SY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (160, 'Taiwan', 'TW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (161, 'Tajikstan', 'TJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (162, 'Tanzania', 'TZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (163, 'Thailand', 'TH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (164, 'Togo', 'TG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (165, 'Tonga', 'TO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (166, 'Trinidad and Tobago', 'TT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (167, 'Tunisia', 'TN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (168, 'Turkey', 'TR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (169, 'Turkmenistan', 'TM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (170, 'Uganda', 'UG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (171, 'Ukraine', 'UA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (172, 'United Arab Emirates', 'AE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (173, 'United Kiongdom', 'GB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (174, 'United States of America', 'US', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (175, 'Uruguay', 'UY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (176, 'Uzbekistan', 'UZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (177, 'Venezuela', 'VE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (178, 'Vietnam', 'VN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (179, 'Yemen', 'YE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (180, 'Yugoslavia', 'YU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (181, 'Zimbabwe', 'ZW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (182, 'Zaire', 'ZR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (183, 'Zambia', 'ZM', 1); \ No newline at end of file +INSERT INTO country (id, countryname, countrycode, version) +VALUES (1, 'Angola', 'AO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (2, 'Afghanistan', 'AF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (3, 'Albania', 'AL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (4, 'Algeria', 'DZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (5, 'Andorra', 'AD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (6, 'Anguilla', 'AI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (7, 'Antigua and Barbuda', 'AG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (8, 'Argentina', 'AR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (9, 'Armenia', 'AM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (10, 'Australia', 'AU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (11, 'Austria', 'AT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (12, 'Azerbaijan', 'AZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (13, 'Bahamas', 'BS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (14, 'Bahrain', 'BH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (15, 'Bangladesh', 'BD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (16, 'Barbados', 'BB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (17, 'Belarus', 'BY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (18, 'Belgium', 'BE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (19, 'Belize', 'BZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (20, 'Benin', 'BJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (21, 'Bermuda Is.', 'BM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (22, 'Bolivia', 'BO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (23, 'Botswana', 'BW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (24, 'Brazil', 'BR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (25, 'Brunei', 'BN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (26, 'Bulgaria', 'BG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (27, 'Burkina-faso', 'BF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (28, 'Burma', 'MM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (29, 'Burundi', 'BI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (30, 'Cameroon', 'CM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (31, 'Canada', 'CA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (32, 'Central African Republic', 'CF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (33, 'Chad', 'TD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (34, 'Chile', 'CL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (35, 'China', 'CN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (36, 'Colombia', 'CO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (37, 'Congo', 'CG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (38, 'Cook Is.', 'CK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (39, 'Costa Rica', 'CR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (40, 'Cuba', 'CU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (41, 'Cyprus', 'CY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (42, 'Czech Republic', 'CZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (43, 'Denmark', 'DK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (44, 'Djibouti', 'DJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (45, 'Dominica Rep.', 'DO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (46, 'Ecuador', 'EC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (47, 'Egypt', 'EG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (48, 'EI Salvador', 'SV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (49, 'Estonia', 'EE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (50, 'Ethiopia', 'ET', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (51, 'Fiji', 'FJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (52, 'Finland', 'FI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (53, 'France', 'FR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (54, 'French Guiana', 'GF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (55, 'Gabon', 'GA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (56, 'Gambia', 'GM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (57, 'Georgia', 'GE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (58, 'Germany', 'DE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (59, 'Ghana', 'GH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (60, 'Gibraltar', 'GI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (61, 'Greece', 'GR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (62, 'Grenada', 'GD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (63, 'Guam', 'GU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (64, 'Guatemala', 'GT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (65, 'Guinea', 'GN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (66, 'Guyana', 'GY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (67, 'Haiti', 'HT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (68, 'Honduras', 'HN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (69, 'Hongkong', 'HK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (70, 'Hungary', 'HU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (71, 'Iceland', 'IS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (72, 'India', 'IN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (73, 'Indonesia', 'ID', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (74, 'Iran', 'IR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (75, 'Iraq', 'IQ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (76, 'Ireland', 'IE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (77, 'Israel', 'IL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (78, 'Italy', 'IT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (79, 'Jamaica', 'JM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (80, 'Japan', 'JP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (81, 'Jordan', 'JO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (83, 'Kazakstan', 'KZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (84, 'Kenya', 'KE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (85, 'Korea', 'KR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (86, 'Kuwait', 'KW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (87, 'Kyrgyzstan', 'KG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (88, 'Laos', 'LA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (89, 'Latvia', 'LV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (90, 'Lebanon', 'LB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (91, 'Lesotho', 'LS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (92, 'Liberia', 'LR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (93, 'Libya', 'LY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (94, 'Liechtenstein', 'LI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (95, 'Lithuania', 'LT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (96, 'Luxembourg', 'LU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (97, 'Macao', 'MO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (98, 'Madagascar', 'MG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (99, 'Malawi', 'MW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (100, 'Malaysia', 'MY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (101, 'Maldives', 'MV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (102, 'Mali', 'ML', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (103, 'Malta', 'MT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (104, 'Mauritius', 'MU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (105, 'Mexico', 'MX', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (106, 'Moldova, Republic of', 'MD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (107, 'Monaco', 'MC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (108, 'Mongolia', 'MN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (109, 'Montserrat Is', 'MS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (110, 'Morocco', 'MA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (111, 'Mozambique', 'MZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (112, 'Namibia', 'NA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (113, 'Nauru', 'NR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (114, 'Nepal', 'NP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (115, 'Netherlands', 'NL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (116, 'New Zealand', 'NZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (117, 'Nicaragua', 'NI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (118, 'Niger', 'NE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (119, 'Nigeria', 'NG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (120, 'North Korea', 'KP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (121, 'Norway', 'NO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (122, 'Oman', 'OM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (123, 'Pakistan', 'PK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (124, 'Panama', 'PA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (125, 'Papua New Cuinea', 'PG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (126, 'Paraguay', 'PY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (127, 'Peru', 'PE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (128, 'Philippines', 'PH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (129, 'Poland', 'PL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (130, 'French Polynesia', 'PF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (131, 'Portugal', 'PT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (132, 'Puerto Rico', 'PR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (133, 'Qatar', 'QA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (134, 'Romania', 'RO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (135, 'Russia', 'RU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (136, 'Saint Lueia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (137, 'Saint Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (138, 'San Marino', 'SM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (139, 'Sao Tome and Principe', 'ST', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (140, 'Saudi Arabia', 'SA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (141, 'Senegal', 'SN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (142, 'Seychelles', 'SC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (143, 'Sierra Leone', 'SL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (144, 'Singapore', 'SG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (145, 'Slovakia', 'SK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (146, 'Slovenia', 'SI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (147, 'Solomon Is', 'SB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (148, 'Somali', 'SO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (149, 'South Africa', 'ZA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (150, 'Spain', 'ES', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (151, 'Sri Lanka', 'LK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (152, 'St.Lucia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (153, 'St.Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (154, 'Sudan', 'SD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (155, 'Suriname', 'SR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (156, 'Swaziland', 'SZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (157, 'Sweden', 'SE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (158, 'Switzerland', 'CH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (159, 'Syria', 'SY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (160, 'Taiwan', 'TW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (161, 'Tajikstan', 'TJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (162, 'Tanzania', 'TZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (163, 'Thailand', 'TH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (164, 'Togo', 'TG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (165, 'Tonga', 'TO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (166, 'Trinidad and Tobago', 'TT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (167, 'Tunisia', 'TN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (168, 'Turkey', 'TR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (169, 'Turkmenistan', 'TM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (170, 'Uganda', 'UG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (171, 'Ukraine', 'UA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (172, 'United Arab Emirates', 'AE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (173, 'United Kiongdom', 'GB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (174, 'United States of America', 'US', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (175, 'Uruguay', 'UY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (176, 'Uzbekistan', 'UZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (177, 'Venezuela', 'VE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (178, 'Vietnam', 'VN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (179, 'Yemen', 'YE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (180, 'Yugoslavia', 'YU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (181, 'Zimbabwe', 'ZW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (182, 'Zaire', 'ZR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (183, 'Zambia', 'ZM', 1); \ No newline at end of file diff --git a/spring/src/test/resources/log4j.properties b/spring/src/test/resources/log4j.properties deleted file mode 100644 index e6f28c382..000000000 --- a/spring/src/test/resources/log4j.properties +++ /dev/null @@ -1,35 +0,0 @@ -# -# The MIT License (MIT) -# -# Copyright (c) 2018 abel533@gmail.com -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -log4j.rootLogger=INFO, stdout - -log4j.logger.tk.mybatis.mapper=DEBUG -log4j.logger.org.apache.ibatis=DEBUG - -log4j.logger.tk.mybatis.mapper.mapper = TRACE - -### Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n \ No newline at end of file diff --git a/spring/src/test/resources/logback.xml b/spring/src/test/resources/logback.xml new file mode 100644 index 000000000..3b71bf41f --- /dev/null +++ b/spring/src/test/resources/logback.xml @@ -0,0 +1,10 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + \ No newline at end of file diff --git a/weekend/README.md b/weekend/README.md index 30cf641fe..d51defb66 100644 --- a/weekend/README.md +++ b/weekend/README.md @@ -19,6 +19,7 @@ 可以在 `Example.Criteria` 的条件方法里传 lambada(再也不用担心改数据库了......)。 栗子: + ```java UserMapper userMapper = sqlSession.getMapper(UserMapper.class); Weekend weekend = Weekend.of(User.class); @@ -28,7 +29,7 @@ weekend.weekendCriteria() .andIn(User::getUserName, Arrays.asList("a","b","c")); ``` -和(作者: [XuYin](https://github.com/chinaerserver)) +和(作者: [XuYin](https://github.com/chinaerserver)) ```java CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); diff --git a/weekend/pom.xml b/weekend/pom.xml index 5bef03f70..4712fade9 100644 --- a/weekend/pom.xml +++ b/weekend/pom.xml @@ -29,10 +29,11 @@ tk.mybatis mapper-parent - 3 + 8 + mapper-weekend - 4.2.1 + 4.2.2-SNAPSHOT weekend Mybatis通用Mapper扩展 - weekend @@ -54,7 +55,7 @@ 1.8 - 4.2.1 + 4.2.2-SNAPSHOT diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java index ef2fb5604..860ad34d2 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/SqlCriteriaHelper.java @@ -7,6 +7,7 @@ /** * sql 条件语句 + * * @author Cheng.Wei * @date 2019-04-15 10:26 */ @@ -22,7 +23,8 @@ public static SqlCriteriaHelper custom(Class clazz) { } /** - * AND column IS NULL + * AND column IS NULL + * * @param fn * @return */ @@ -34,6 +36,7 @@ public SqlCriteriaHelper andIsNull(Fn fn) { /** * AND column IS NOT NULL + * * @param fn * @return */ @@ -43,8 +46,9 @@ public SqlCriteriaHelper andIsNotNull(Fn fn) { } /** - * AND column = value - * 当value=null则不参与查询 + * AND column = value + * 当value=null则不参与查询 + * * @param fn * @param value * @return @@ -54,18 +58,19 @@ public SqlCriteriaHelper andEqualTo(Fn fn, Object value) { } /** - * AND column = value + * AND column = value + * * @param fn * @param value - * @param required false 当value=null 则不参与查询 ; - * true 当value = null 则转 is null 查询: AND column is null + * @param required false 当value=null 则不参与查询 ; + * true 当value = null 则转 is null 查询: AND column is null * @return */ public SqlCriteriaHelper andEqualTo(Fn fn, Object value, boolean required) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "=", "and")); - }else { - if(required){ + } else { + if (required) { // null属性查询 转 is null this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), "is null", "and")); } @@ -76,6 +81,7 @@ public SqlCriteriaHelper andEqualTo(Fn fn, Object value, boolean r /** * AND column != value * 默认 value=null 则不参与查询 + * * @param fn * @param value * @return @@ -85,19 +91,19 @@ public SqlCriteriaHelper andNotEqualTo(Fn fn, Object value) { } /** - * AND column != value + * AND column != value + * * @param fn * @param value * @param required false 当value=null 则不参与查询 ; * true 当value = null 则转 is not null 查询 : AND column is not null - * * @return */ public SqlCriteriaHelper andNotEqualTo(Fn fn, Object value, boolean required) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<>", "and")); - }else { - if(required){ + } else { + if (required) { //转非空查询 this.andIsNotNull(fn); } @@ -106,28 +112,30 @@ public SqlCriteriaHelper andNotEqualTo(Fn fn, Object value, boolea } /** - * AND column > value - * 当 value = null 则当前属性不参与查询 + * AND column > value + * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andGreaterThan(Fn fn, Object value) { - if (Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, ">", "and")); } return this; } /** - * AND column >= value - * 当 value = null 则当前属性不参与查询 + * AND column >= value + * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andGreaterThanOrEqualTo(Fn fn, Object value) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, ">=", "and")); } return this; @@ -135,13 +143,14 @@ public SqlCriteriaHelper andGreaterThanOrEqualTo(Fn fn, Object val /** * AND column < value - * 当 value = null 则当前属性不参与查询 + * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andLessThan(Fn fn, Object value) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<", "and")); } return this; @@ -149,13 +158,14 @@ public SqlCriteriaHelper andLessThan(Fn fn, Object value) { /** * AND column <= value - * 当 value = null 则当前属性不参与查询 + * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andLessThanOrEqualTo(Fn fn, Object value) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<=", "and")); } return this; @@ -163,13 +173,14 @@ public SqlCriteriaHelper andLessThanOrEqualTo(Fn fn, Object value) /** * AND column IN (#{item.value}) - * 当 values = null 则当前属性不参与查询 + * 当 values = null 则当前属性不参与查询 + * * @param fn * @param values * @return */ public SqlCriteriaHelper andIn(Fn fn, Iterable values) { - if(Optional.ofNullable(values).isPresent() && values.iterator().hasNext()){ + if (Optional.ofNullable(values).isPresent() && values.iterator().hasNext()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "in", "and")); } return this; @@ -177,13 +188,14 @@ public SqlCriteriaHelper andIn(Fn fn, Iterable values) { /** * AND column NOT IN (#{item.value}) - * 当 values = null 则当前属性不参与查询 + * 当 values = null 则当前属性不参与查询 + * * @param fn * @param values * @return */ public SqlCriteriaHelper andNotIn(Fn fn, Iterable values) { - if(Optional.ofNullable(values).isPresent() && values.iterator().hasNext()){ + if (Optional.ofNullable(values).isPresent() && values.iterator().hasNext()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "not in", "and")); } return this; @@ -192,13 +204,14 @@ public SqlCriteriaHelper andNotIn(Fn fn, Iterable values) { /** * AND column BETWEEN value1 AND value2 * 当 value1 或 value2 为空 则当前属性不参与查询 + * * @param fn * @param value1 * @param value2 * @return */ public SqlCriteriaHelper andBetween(Fn fn, Object value1, Object value2) { - if(Optional.ofNullable(value1).isPresent()&& Optional.ofNullable(value2).isPresent()){ + if (Optional.ofNullable(value1).isPresent() && Optional.ofNullable(value2).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value1, value2, "between", "and")); } return this; @@ -207,13 +220,14 @@ public SqlCriteriaHelper andBetween(Fn fn, Object value1, Object v /** * AND column NOT BETWEEN value1 AND value2 * 当 value1 或 value2 为空 则当前属性不参与查询 + * * @param fn * @param value1 * @param value2 * @return */ public SqlCriteriaHelper andNotBetween(Fn fn, Object value1, Object value2) { - if(Optional.ofNullable(value1).isPresent()&& Optional.ofNullable(value2).isPresent()){ + if (Optional.ofNullable(value1).isPresent() && Optional.ofNullable(value2).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value1, value2, "not between", "and")); } return this; @@ -222,13 +236,14 @@ public SqlCriteriaHelper andNotBetween(Fn fn, Object value1, Objec /** * AND column LIKE %value% * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andLike(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = "%"+value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = "%" + value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "and")); } return this; @@ -238,13 +253,14 @@ public SqlCriteriaHelper andLike(Fn fn, String value) { /** * AND column LIKE %value * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andLikeLeft(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = "%"+value; + if (Optional.ofNullable(value).isPresent()) { + value = "%" + value; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "and")); } return this; @@ -253,13 +269,14 @@ public SqlCriteriaHelper andLikeLeft(Fn fn, String value) { /** * AND column LIKE value% * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andLikeRight(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "and")); } return this; @@ -268,13 +285,14 @@ public SqlCriteriaHelper andLikeRight(Fn fn, String value) { /** * AND column NOT LIKE %value% * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andNotLike(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = "%"+value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = "%" + value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "and")); } return this; @@ -283,13 +301,14 @@ public SqlCriteriaHelper andNotLike(Fn fn, String value) { /** * AND column NOT LIKE %value * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andNotLikeLeft(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = "%"+value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = "%" + value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "and")); } return this; @@ -298,13 +317,14 @@ public SqlCriteriaHelper andNotLikeLeft(Fn fn, String value) { /** * AND column NOT LIKE value% * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper andNotLikeRight(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "and")); } return this; @@ -313,6 +333,7 @@ public SqlCriteriaHelper andNotLikeRight(Fn fn, String value) { /** * OR column IS NULL * 当 value = null 则当前属性不参与查询 + * * @param fn * @return */ @@ -324,6 +345,7 @@ public SqlCriteriaHelper orIsNull(Fn fn) { /** * OR column IS NOT NULL * 当 value = null 则当前属性不参与查询 + * * @param fn * @return */ @@ -334,8 +356,9 @@ public SqlCriteriaHelper orIsNotNull(Fn fn) { /** - * OR column = value + * OR column = value * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return @@ -347,16 +370,17 @@ public SqlCriteriaHelper orEqualTo(Fn fn, Object value) { /** * OR column = value * 当request = true 且 value = null时 转 #{@link #orIsNull(Fn)} + * * @param fn * @param value * @param required * @return */ public SqlCriteriaHelper orEqualTo(Fn fn, Object value, boolean required) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "=", "or")); - }else { - if(required){ + } else { + if (required) { //转 or null this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), "is null", "or")); } @@ -367,6 +391,7 @@ public SqlCriteriaHelper orEqualTo(Fn fn, Object value, boolean re /** * OR column <> value * 当value = null 则当前属性不参与查询 + * * @param fn * @param value * @return @@ -377,17 +402,18 @@ public SqlCriteriaHelper orNotEqualTo(Fn fn, Object value) { /** * OR column <> value - * 当request = true 且 value = null时 转 #{@link #orIsNotNull(Fn)} + * 当request = true 且 value = null时 转 #{@link #orIsNotNull(Fn)} + * * @param fn * @param value * @param required * @return */ public SqlCriteriaHelper orNotEqualTo(Fn fn, Object value, boolean required) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<>", "or")); - }else { - if(required){ + } else { + if (required) { // 转 or is not null this.orIsNotNull(fn); } @@ -398,12 +424,13 @@ public SqlCriteriaHelper orNotEqualTo(Fn fn, Object value, boolean /** * OR column > value * 当value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orGreaterThan(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, ">", "or")); } return this; @@ -412,12 +439,13 @@ public SqlCriteriaHelper orGreaterThan(Fn fn, String value) { /** * OR column >= value * 当value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orGreaterThanOrEqualTo(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, ">=", "or")); } return this; @@ -426,12 +454,13 @@ public SqlCriteriaHelper orGreaterThanOrEqualTo(Fn fn, String valu /** * OR column < value * 当value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orLessThan(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<", "or")); } return this; @@ -440,12 +469,13 @@ public SqlCriteriaHelper orLessThan(Fn fn, String value) { /** * OR column <= value * 当value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orLessThanOrEqualTo(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ + if (Optional.ofNullable(value).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "<=", "or")); } return this; @@ -454,12 +484,13 @@ public SqlCriteriaHelper orLessThanOrEqualTo(Fn fn, String value) /** * OR column IN (#{item.value}) * 当value = null 则当前属性不参与查询 + * * @param fn * @param values * @return */ public SqlCriteriaHelper orIn(Fn fn, Iterable values) { - if(Optional.ofNullable(values).isPresent() && values.iterator().hasNext()){ + if (Optional.ofNullable(values).isPresent() && values.iterator().hasNext()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "in", "or")); } return this; @@ -468,12 +499,13 @@ public SqlCriteriaHelper orIn(Fn fn, Iterable values) { /** * OR column NOT IN (#{item.value}) * 当value = null 则当前属性不参与查询 + * * @param fn * @param values * @return */ public SqlCriteriaHelper orNotIn(Fn fn, Iterable values) { - if(Optional.ofNullable(values).isPresent() && values.iterator().hasNext()){ + if (Optional.ofNullable(values).isPresent() && values.iterator().hasNext()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), values, "not in", "or")); } return this; @@ -482,13 +514,14 @@ public SqlCriteriaHelper orNotIn(Fn fn, Iterable values) { /** * OR column BETWEEN value1 AND value2 * 当 value1 或 value2 为空 则当前属性不参与查询 + * * @param fn * @param value1 * @param value2 * @return */ public SqlCriteriaHelper orBetween(Fn fn, Object value1, Object value2) { - if(Optional.ofNullable(value1).isPresent()&& Optional.ofNullable(value2).isPresent()){ + if (Optional.ofNullable(value1).isPresent() && Optional.ofNullable(value2).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value1, value2, "between", "or")); } return this; @@ -497,13 +530,14 @@ public SqlCriteriaHelper orBetween(Fn fn, Object value1, Object va /** * OR column NOT BETWEEN value1 AND value2 * 当 value1 或 value2 为空 则当前属性不参与查询 + * * @param fn * @param value1 * @param value2 * @return */ public SqlCriteriaHelper orNotBetween(Fn fn, Object value1, Object value2) { - if(Optional.ofNullable(value1).isPresent()&& Optional.ofNullable(value2).isPresent()){ + if (Optional.ofNullable(value1).isPresent() && Optional.ofNullable(value2).isPresent()) { this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value1, value2, "not between", "or")); } return this; @@ -513,13 +547,14 @@ public SqlCriteriaHelper orNotBetween(Fn fn, Object value1, Object /** * OR column LIKE value * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orLike(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = "%"+value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = "%" + value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "or")); } return this; @@ -529,31 +564,31 @@ public SqlCriteriaHelper orLike(Fn fn, String value) { /** * OR column LIKE %value * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orLikeLeft(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = "%"+value; + if (Optional.ofNullable(value).isPresent()) { + value = "%" + value; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "or")); } return this; } - - /** * OR column LIKE value% * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orLikeRight(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "like", "or")); } return this; @@ -563,30 +598,31 @@ public SqlCriteriaHelper orLikeRight(Fn fn, String value) { /** * OR column NOT LIKE value * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orNotLike(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = "%"+value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = "%" + value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "or")); } return this; } - /** * OR column NOT LIKE %value * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orNotLikeLeft(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = "%"+value; + if (Optional.ofNullable(value).isPresent()) { + value = "%" + value; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "or")); } return this; @@ -595,13 +631,14 @@ public SqlCriteriaHelper orNotLikeLeft(Fn fn, String value) { /** * OR column NOT LIKE value% * 当 value = null 则当前属性不参与查询 + * * @param fn * @param value * @return */ public SqlCriteriaHelper orNotLikeRight(Fn fn, String value) { - if(Optional.ofNullable(value).isPresent()){ - value = value+"%"; + if (Optional.ofNullable(value).isPresent()) { + value = value + "%"; this.criteria.getCriterions().add(new Sqls.Criterion(Reflections.fnToFieldName(fn), value, "not like", "or")); } return this; diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/reflection/Reflections.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/reflection/Reflections.java index f48fe0ea4..4df0864e0 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/reflection/Reflections.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/reflection/Reflections.java @@ -37,7 +37,7 @@ */ public class Reflections { private static final Pattern GET_PATTERN = Pattern.compile("^get[A-Z].*"); - private static final Pattern IS_PATTERN = Pattern.compile("^is[A-Z].*"); + private static final Pattern IS_PATTERN = Pattern.compile("^is[A-Z].*"); private Reflections() { } diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/MybatisHelper.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/MybatisHelper.java index 258877b49..07f6aaf91 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/MybatisHelper.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/MybatisHelper.java @@ -116,9 +116,10 @@ public class MybatisHelper { /** * 获取Session + * * @return */ - public static SqlSession getSqlSession(){ + public static SqlSession getSqlSession() { return sqlSessionFactory.openSession(); } } diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java index 46f627afb..d89ad7359 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/SqlCriteriaHelperTest.java @@ -24,9 +24,9 @@ public void ignore() { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); List selectBySqlCriteriaHelper = mapper.selectByExample(new Example.Builder(Country.class) - .where(SqlCriteriaHelper.custom(Country.class) - .andEqualTo(Country::getCountryname, null) - .andLike(Country::getCountryname, "China")).build()); + .where(SqlCriteriaHelper.custom(Country.class) + .andEqualTo(Country::getCountryname, null) + .andLike(Country::getCountryname, "China")).build()); Assert.assertNotNull(selectBySqlCriteriaHelper); Assert.assertEquals(1, selectBySqlCriteriaHelper.size()); /* 不支持忽略 null @@ -52,9 +52,9 @@ public void required() { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); List selectBySqlCriteriaHelper = mapper.selectByExample(new Example.Builder(Country.class) - .where(SqlCriteriaHelper.custom(Country.class) - // required = true 则继续查询 - .andEqualTo(Country::getCountryname, null, true)).build()); + .where(SqlCriteriaHelper.custom(Country.class) + // required = true 则继续查询 + .andEqualTo(Country::getCountryname, null, true)).build()); Assert.assertEquals(0, selectBySqlCriteriaHelper.size()); /*List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) .where(WeekendSqls.custom() @@ -74,9 +74,9 @@ public void like() { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); List selectBySqlCriteriaHelper = mapper.selectByExample(new Example.Builder(Country.class) - .where(SqlCriteriaHelper.custom(Country.class) - .andLike(Country::getCountryname, "Chin") - .orLike(Country::getCountryname, "A")).build()); + .where(SqlCriteriaHelper.custom(Country.class) + .andLike(Country::getCountryname, "Chin") + .orLike(Country::getCountryname, "A")).build()); Assert.assertEquals(18, selectBySqlCriteriaHelper.size()); /* 不支持自动带 % List selectByWeekendSqls = mapper.selectByExample(new Example.Builder(Country.class) @@ -100,9 +100,9 @@ public void list() { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); List selectBySqlCriteriaHelper = mapper.selectByExample(new Example.Builder(Country.class) - .where(SqlCriteriaHelper.custom(Country.class) - .andIn(Country::getCountryname, new ArrayList()) - .orLike(Country::getCountryname, "A")).build()); + .where(SqlCriteriaHelper.custom(Country.class) + .andIn(Country::getCountryname, new ArrayList()) + .orLike(Country::getCountryname, "A")).build()); Assert.assertNotNull(selectBySqlCriteriaHelper); Assert.assertEquals(17, selectBySqlCriteriaHelper.size()); //WeekendSqls 不支持空集合 diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java index 6617c120f..c87eea04e 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java @@ -49,35 +49,36 @@ public class UserMapperTest { * 执行,然后看日志打出来的SQL */ @Test - public void testSelectIdIsNull(){ - SqlSession sqlSession = MybatisHelper.getSqlSession(); + public void testSelectIdIsNull() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); UserMapper userMapper = sqlSession.getMapper(UserMapper.class); Weekend weekend = Weekend.of(User.class); weekend.weekendCriteria() .andIsNull(User::getId) - .andBetween(User::getId,0,10) - .andIn(User::getUserName, Arrays.asList("a","b","c")); + .andBetween(User::getId, 0, 10) + .andIn(User::getUserName, Arrays.asList("a", "b", "c")); List users = userMapper.selectByExample(weekend); for (User user : users) { System.out.println(user.getUserName()); } } + @Test - public void testExcludeAndSelectProperties(){ - SqlSession sqlSession = MybatisHelper.getSqlSession(); + public void testExcludeAndSelectProperties() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class); Weekend weekend1 = Weekend.of(Country.class); - weekend1.excludeProperties(Country::getId,Country::getCountryname); + weekend1.excludeProperties(Country::getId, Country::getCountryname); //查看日志执行的sql countryMapper.selectByExample(weekend1); Weekend weekend2 = Weekend.of(Country.class); weekend2.selectProperties(Country::getId); //查看日志执行的sql countryMapper.selectByExample(weekend2); - //count 查询 - weekend2.withCountProperty(Country::getCountryname); - countryMapper.selectCountByExample(weekend2); + //count 查询 + weekend2.withCountProperty(Country::getCountryname); + countryMapper.selectCountByExample(weekend2); } } diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/Country.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/Country.java index 05ae4c31f..62e7700c8 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/Country.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/Country.java @@ -34,7 +34,7 @@ public class Country implements Serializable { private static final long serialVersionUID = 1L; @Id private Integer id; - private String countryname; + private String countryname; private String countrycode; diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/User.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/User.java index 9b32a6bef..8766af9d3 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/User.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/User.java @@ -32,7 +32,7 @@ */ @Table(name = "user") public class User { - private Long id; + private Long id; private String userName; public Long getId() { diff --git a/weekend/src/test/resources/CreateDB.sql b/weekend/src/test/resources/CreateDB.sql index 8ee1e67d0..e36b9b2fb 100644 --- a/weekend/src/test/resources/CreateDB.sql +++ b/weekend/src/test/resources/CreateDB.sql @@ -1,197 +1,381 @@ drop table user if exists; CREATE table user ( - id int not null, + id int not null, user_name varchar(100) not null ); -CREATE TABLE country ( - id INTEGER NOT NULL PRIMARY KEY, - countryname VARCHAR(32), - countrycode VARCHAR(2) DEFAULT 'HH', - version INTEGER DEFAULT 1 NOT NULL +CREATE TABLE country +( + id INTEGER NOT NULL PRIMARY KEY, + countryname VARCHAR(32), + countrycode VARCHAR(2) DEFAULT 'HH', + version INTEGER DEFAULT 1 NOT NULL ); -INSERT INTO country (id, countryname, countrycode, version) VALUES (1, 'Angola', 'AO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (2, 'Afghanistan', 'AF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (3, 'Albania', 'AL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (4, 'Algeria', 'DZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (5, 'Andorra', 'AD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (6, 'Anguilla', 'AI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (7, 'Antigua and Barbuda', 'AG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (8, 'Argentina', 'AR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (9, 'Armenia', 'AM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (10, 'Australia', 'AU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (11, 'Austria', 'AT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (12, 'Azerbaijan', 'AZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (13, 'Bahamas', 'BS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (14, 'Bahrain', 'BH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (15, 'Bangladesh', 'BD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (16, 'Barbados', 'BB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (17, 'Belarus', 'BY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (18, 'Belgium', 'BE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (19, 'Belize', 'BZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (20, 'Benin', 'BJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (21, 'Bermuda Is.', 'BM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (22, 'Bolivia', 'BO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (23, 'Botswana', 'BW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (24, 'Brazil', 'BR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (25, 'Brunei', 'BN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (26, 'Bulgaria', 'BG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (27, 'Burkina-faso', 'BF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (28, 'Burma', 'MM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (29, 'Burundi', 'BI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (30, 'Cameroon', 'CM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (31, 'Canada', 'CA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (32, 'Central African Republic', 'CF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (33, 'Chad', 'TD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (34, 'Chile', 'CL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (35, 'China', 'CN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (36, 'Colombia', 'CO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (37, 'Congo', 'CG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (38, 'Cook Is.', 'CK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (39, 'Costa Rica', 'CR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (40, 'Cuba', 'CU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (41, 'Cyprus', 'CY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (42, 'Czech Republic', 'CZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (43, 'Denmark', 'DK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (44, 'Djibouti', 'DJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (45, 'Dominica Rep.', 'DO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (46, 'Ecuador', 'EC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (47, 'Egypt', 'EG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (48, 'EI Salvador', 'SV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (49, 'Estonia', 'EE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (50, 'Ethiopia', 'ET', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (51, 'Fiji', 'FJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (52, 'Finland', 'FI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (53, 'France', 'FR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (54, 'French Guiana', 'GF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (55, 'Gabon', 'GA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (56, 'Gambia', 'GM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (57, 'Georgia', 'GE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (58, 'Germany', 'DE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (59, 'Ghana', 'GH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (60, 'Gibraltar', 'GI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (61, 'Greece', 'GR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (62, 'Grenada', 'GD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (63, 'Guam', 'GU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (64, 'Guatemala', 'GT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (65, 'Guinea', 'GN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (66, 'Guyana', 'GY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (67, 'Haiti', 'HT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (68, 'Honduras', 'HN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (69, 'Hongkong', 'HK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (70, 'Hungary', 'HU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (71, 'Iceland', 'IS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (72, 'India', 'IN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (73, 'Indonesia', 'ID', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (74, 'Iran', 'IR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (75, 'Iraq', 'IQ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (76, 'Ireland', 'IE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (77, 'Israel', 'IL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (78, 'Italy', 'IT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (79, 'Jamaica', 'JM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (80, 'Japan', 'JP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (81, 'Jordan', 'JO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (83, 'Kazakstan', 'KZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (84, 'Kenya', 'KE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (85, 'Korea', 'KR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (86, 'Kuwait', 'KW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (87, 'Kyrgyzstan', 'KG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (88, 'Laos', 'LA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (89, 'Latvia', 'LV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (90, 'Lebanon', 'LB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (91, 'Lesotho', 'LS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (92, 'Liberia', 'LR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (93, 'Libya', 'LY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (94, 'Liechtenstein', 'LI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (95, 'Lithuania', 'LT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (96, 'Luxembourg', 'LU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (97, 'Macao', 'MO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (98, 'Madagascar', 'MG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (99, 'Malawi', 'MW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (100, 'Malaysia', 'MY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (101, 'Maldives', 'MV', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (102, 'Mali', 'ML', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (103, 'Malta', 'MT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (104, 'Mauritius', 'MU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (105, 'Mexico', 'MX', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (106, 'Moldova, Republic of', 'MD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (107, 'Monaco', 'MC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (108, 'Mongolia', 'MN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (109, 'Montserrat Is', 'MS', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (110, 'Morocco', 'MA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (111, 'Mozambique', 'MZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (112, 'Namibia', 'NA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (113, 'Nauru', 'NR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (114, 'Nepal', 'NP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (115, 'Netherlands', 'NL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (116, 'New Zealand', 'NZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (117, 'Nicaragua', 'NI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (118, 'Niger', 'NE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (119, 'Nigeria', 'NG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (120, 'North Korea', 'KP', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (121, 'Norway', 'NO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (122, 'Oman', 'OM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (123, 'Pakistan', 'PK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (124, 'Panama', 'PA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (125, 'Papua New Cuinea', 'PG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (126, 'Paraguay', 'PY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (127, 'Peru', 'PE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (128, 'Philippines', 'PH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (129, 'Poland', 'PL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (130, 'French Polynesia', 'PF', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (131, 'Portugal', 'PT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (132, 'Puerto Rico', 'PR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (133, 'Qatar', 'QA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (134, 'Romania', 'RO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (135, 'Russia', 'RU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (136, 'Saint Lueia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (137, 'Saint Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (138, 'San Marino', 'SM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (139, 'Sao Tome and Principe', 'ST', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (140, 'Saudi Arabia', 'SA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (141, 'Senegal', 'SN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (142, 'Seychelles', 'SC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (143, 'Sierra Leone', 'SL', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (144, 'Singapore', 'SG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (145, 'Slovakia', 'SK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (146, 'Slovenia', 'SI', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (147, 'Solomon Is', 'SB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (148, 'Somali', 'SO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (149, 'South Africa', 'ZA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (150, 'Spain', 'ES', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (151, 'Sri Lanka', 'LK', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (152, 'St.Lucia', 'LC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (153, 'St.Vincent', 'VC', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (154, 'Sudan', 'SD', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (155, 'Suriname', 'SR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (156, 'Swaziland', 'SZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (157, 'Sweden', 'SE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (158, 'Switzerland', 'CH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (159, 'Syria', 'SY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (160, 'Taiwan', 'TW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (161, 'Tajikstan', 'TJ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (162, 'Tanzania', 'TZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (163, 'Thailand', 'TH', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (164, 'Togo', 'TG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (165, 'Tonga', 'TO', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (166, 'Trinidad and Tobago', 'TT', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (167, 'Tunisia', 'TN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (168, 'Turkey', 'TR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (169, 'Turkmenistan', 'TM', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (170, 'Uganda', 'UG', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (171, 'Ukraine', 'UA', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (172, 'United Arab Emirates', 'AE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (173, 'United Kiongdom', 'GB', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (174, 'United States of America', 'US', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (175, 'Uruguay', 'UY', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (176, 'Uzbekistan', 'UZ', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (177, 'Venezuela', 'VE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (178, 'Vietnam', 'VN', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (179, 'Yemen', 'YE', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (180, 'Yugoslavia', 'YU', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (181, 'Zimbabwe', 'ZW', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (182, 'Zaire', 'ZR', 1); -INSERT INTO country (id, countryname, countrycode, version) VALUES (183, 'Zambia', 'ZM', 1); \ No newline at end of file +INSERT INTO country (id, countryname, countrycode, version) +VALUES (1, 'Angola', 'AO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (2, 'Afghanistan', 'AF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (3, 'Albania', 'AL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (4, 'Algeria', 'DZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (5, 'Andorra', 'AD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (6, 'Anguilla', 'AI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (7, 'Antigua and Barbuda', 'AG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (8, 'Argentina', 'AR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (9, 'Armenia', 'AM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (10, 'Australia', 'AU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (11, 'Austria', 'AT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (12, 'Azerbaijan', 'AZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (13, 'Bahamas', 'BS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (14, 'Bahrain', 'BH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (15, 'Bangladesh', 'BD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (16, 'Barbados', 'BB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (17, 'Belarus', 'BY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (18, 'Belgium', 'BE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (19, 'Belize', 'BZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (20, 'Benin', 'BJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (21, 'Bermuda Is.', 'BM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (22, 'Bolivia', 'BO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (23, 'Botswana', 'BW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (24, 'Brazil', 'BR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (25, 'Brunei', 'BN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (26, 'Bulgaria', 'BG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (27, 'Burkina-faso', 'BF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (28, 'Burma', 'MM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (29, 'Burundi', 'BI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (30, 'Cameroon', 'CM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (31, 'Canada', 'CA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (32, 'Central African Republic', 'CF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (33, 'Chad', 'TD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (34, 'Chile', 'CL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (35, 'China', 'CN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (36, 'Colombia', 'CO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (37, 'Congo', 'CG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (38, 'Cook Is.', 'CK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (39, 'Costa Rica', 'CR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (40, 'Cuba', 'CU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (41, 'Cyprus', 'CY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (42, 'Czech Republic', 'CZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (43, 'Denmark', 'DK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (44, 'Djibouti', 'DJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (45, 'Dominica Rep.', 'DO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (46, 'Ecuador', 'EC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (47, 'Egypt', 'EG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (48, 'EI Salvador', 'SV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (49, 'Estonia', 'EE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (50, 'Ethiopia', 'ET', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (51, 'Fiji', 'FJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (52, 'Finland', 'FI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (53, 'France', 'FR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (54, 'French Guiana', 'GF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (55, 'Gabon', 'GA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (56, 'Gambia', 'GM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (57, 'Georgia', 'GE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (58, 'Germany', 'DE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (59, 'Ghana', 'GH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (60, 'Gibraltar', 'GI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (61, 'Greece', 'GR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (62, 'Grenada', 'GD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (63, 'Guam', 'GU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (64, 'Guatemala', 'GT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (65, 'Guinea', 'GN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (66, 'Guyana', 'GY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (67, 'Haiti', 'HT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (68, 'Honduras', 'HN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (69, 'Hongkong', 'HK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (70, 'Hungary', 'HU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (71, 'Iceland', 'IS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (72, 'India', 'IN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (73, 'Indonesia', 'ID', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (74, 'Iran', 'IR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (75, 'Iraq', 'IQ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (76, 'Ireland', 'IE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (77, 'Israel', 'IL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (78, 'Italy', 'IT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (79, 'Jamaica', 'JM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (80, 'Japan', 'JP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (81, 'Jordan', 'JO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (82, 'Kampuchea (Cambodia )', 'KH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (83, 'Kazakstan', 'KZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (84, 'Kenya', 'KE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (85, 'Korea', 'KR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (86, 'Kuwait', 'KW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (87, 'Kyrgyzstan', 'KG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (88, 'Laos', 'LA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (89, 'Latvia', 'LV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (90, 'Lebanon', 'LB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (91, 'Lesotho', 'LS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (92, 'Liberia', 'LR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (93, 'Libya', 'LY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (94, 'Liechtenstein', 'LI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (95, 'Lithuania', 'LT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (96, 'Luxembourg', 'LU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (97, 'Macao', 'MO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (98, 'Madagascar', 'MG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (99, 'Malawi', 'MW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (100, 'Malaysia', 'MY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (101, 'Maldives', 'MV', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (102, 'Mali', 'ML', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (103, 'Malta', 'MT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (104, 'Mauritius', 'MU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (105, 'Mexico', 'MX', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (106, 'Moldova, Republic of', 'MD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (107, 'Monaco', 'MC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (108, 'Mongolia', 'MN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (109, 'Montserrat Is', 'MS', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (110, 'Morocco', 'MA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (111, 'Mozambique', 'MZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (112, 'Namibia', 'NA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (113, 'Nauru', 'NR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (114, 'Nepal', 'NP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (115, 'Netherlands', 'NL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (116, 'New Zealand', 'NZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (117, 'Nicaragua', 'NI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (118, 'Niger', 'NE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (119, 'Nigeria', 'NG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (120, 'North Korea', 'KP', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (121, 'Norway', 'NO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (122, 'Oman', 'OM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (123, 'Pakistan', 'PK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (124, 'Panama', 'PA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (125, 'Papua New Cuinea', 'PG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (126, 'Paraguay', 'PY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (127, 'Peru', 'PE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (128, 'Philippines', 'PH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (129, 'Poland', 'PL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (130, 'French Polynesia', 'PF', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (131, 'Portugal', 'PT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (132, 'Puerto Rico', 'PR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (133, 'Qatar', 'QA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (134, 'Romania', 'RO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (135, 'Russia', 'RU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (136, 'Saint Lueia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (137, 'Saint Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (138, 'San Marino', 'SM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (139, 'Sao Tome and Principe', 'ST', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (140, 'Saudi Arabia', 'SA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (141, 'Senegal', 'SN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (142, 'Seychelles', 'SC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (143, 'Sierra Leone', 'SL', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (144, 'Singapore', 'SG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (145, 'Slovakia', 'SK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (146, 'Slovenia', 'SI', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (147, 'Solomon Is', 'SB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (148, 'Somali', 'SO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (149, 'South Africa', 'ZA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (150, 'Spain', 'ES', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (151, 'Sri Lanka', 'LK', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (152, 'St.Lucia', 'LC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (153, 'St.Vincent', 'VC', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (154, 'Sudan', 'SD', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (155, 'Suriname', 'SR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (156, 'Swaziland', 'SZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (157, 'Sweden', 'SE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (158, 'Switzerland', 'CH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (159, 'Syria', 'SY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (160, 'Taiwan', 'TW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (161, 'Tajikstan', 'TJ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (162, 'Tanzania', 'TZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (163, 'Thailand', 'TH', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (164, 'Togo', 'TG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (165, 'Tonga', 'TO', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (166, 'Trinidad and Tobago', 'TT', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (167, 'Tunisia', 'TN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (168, 'Turkey', 'TR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (169, 'Turkmenistan', 'TM', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (170, 'Uganda', 'UG', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (171, 'Ukraine', 'UA', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (172, 'United Arab Emirates', 'AE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (173, 'United Kiongdom', 'GB', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (174, 'United States of America', 'US', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (175, 'Uruguay', 'UY', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (176, 'Uzbekistan', 'UZ', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (177, 'Venezuela', 'VE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (178, 'Vietnam', 'VN', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (179, 'Yemen', 'YE', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (180, 'Yugoslavia', 'YU', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (181, 'Zimbabwe', 'ZW', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (182, 'Zaire', 'ZR', 1); +INSERT INTO country (id, countryname, countrycode, version) +VALUES (183, 'Zambia', 'ZM', 1); \ No newline at end of file diff --git a/weekend/src/test/resources/log4j.properties b/weekend/src/test/resources/log4j.properties deleted file mode 100644 index db1c64a5b..000000000 --- a/weekend/src/test/resources/log4j.properties +++ /dev/null @@ -1,36 +0,0 @@ -# -# The MIT License (MIT) -# -# Copyright (c) 2014-2017 the original author or authors. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# - -log4j.rootLogger=INFO, stdout - -log4j.logger.tk.mybatis.mapper=DEBUG -log4j.logger.org.apache.ibatis=DEBUG - -log4j.logger.cn.xiaocuoben.mapper.addon.mapper = TRACE - -### Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n \ No newline at end of file diff --git a/weekend/src/test/resources/logback.xml b/weekend/src/test/resources/logback.xml new file mode 100644 index 000000000..3b71bf41f --- /dev/null +++ b/weekend/src/test/resources/logback.xml @@ -0,0 +1,10 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + \ No newline at end of file diff --git a/weekend/src/test/resources/mybatis-java.xml b/weekend/src/test/resources/mybatis-java.xml index 764e48999..743453c3a 100644 --- a/weekend/src/test/resources/mybatis-java.xml +++ b/weekend/src/test/resources/mybatis-java.xml @@ -33,7 +33,7 @@ - + @@ -50,9 +50,9 @@ --> - - - + + + diff --git a/generator/pom.xml b/generator/pom.xml index 906a28216..10e58e576 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.2-SNAPSHOT + ${revision} mapper-generator jar @@ -37,7 +37,6 @@ Mybatis 通用 Mapper 代码生成器 - 4.2.2-SNAPSHOT 2.3.28 1.3.7 @@ -81,7 +80,7 @@ tk.mybatis mapper-base - ${mapper-module.version} + ${project.version} test diff --git a/pom.xml b/pom.xml index d84254b36..54e9317dd 100644 --- a/pom.xml +++ b/pom.xml @@ -25,20 +25,32 @@ 4.0.0 - - tk.mybatis - mapper-parent - 8 - - + tk.mybatis mapper-modules - 4.2.2-SNAPSHOT + ${revision} pom - mapper-parent + mapper-modules Mybatis 通用 Mapper 聚合模块 https://mybatis.io + + 4.2.2-SNAPSHOT + 8 + 8 + UTF-8 + UTF-8 + -Dfile.encoding=UTF-8 + + 2.2 + 1.7.26 + 3.5.9 + + 4.13.2 + 2.5.2 + 1.2.11 + + The MIT License (MIT) @@ -53,6 +65,67 @@ + + + + javax.persistence + javax.persistence-api + ${jpa.version} + + + + + + org.mybatis + mybatis + ${mybatis.version} + provided + + + org.slf4j + slf4j-api + ${slf4j.version} + provided + + + + + junit + junit + ${junit.version} + test + + + ch.qos.logback + logback-classic + ${logback.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + + + + + + junit + junit + + + ch.qos.logback + logback-classic + + + org.hsqldb + hsqldb + + + scm:git@github.com:abel533/mapper.git scm:git@github.com:abel533/mapper.git @@ -69,4 +142,138 @@ generator spring-boot-starter + + + + + src/test/resources + + + src/test/java + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + -parameters + + + + + + + + + release + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + package + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + + -Xdoclint:none + + + + + package + + jar + + + + + + org.codehaus.mojo + flatten-maven-plugin + 1.1.0 + + true + resolveCiFriendliesOnly + + expand + + + + + flatten + process-resources + + flatten + + + + flatten.clean + clean + + clean + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + --pinentry-mode + loopback + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + true + + ossrh + https://oss.sonatype.org/ + true + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots/ + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml index 75e36e1e4..e3d165441 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.2-SNAPSHOT + ${revision} mapper-spring-boot-autoconfigure mapper-spring-boot-autoconfigure diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml index 006382390..64759783a 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot-samples - 4.2.2-SNAPSHOT + ${revision} mapper-spring-boot-sample-annotation jar diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml index 656602bd8..553cccfa2 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot-samples - 4.2.2-SNAPSHOT + ${revision} mapper-spring-boot-sample-xml jar diff --git a/spring-boot-starter/mapper-spring-boot-samples/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/pom.xml index fad3c0241..09fad8219 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-samples/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.2-SNAPSHOT + ${revision} mapper-spring-boot-samples pom diff --git a/spring-boot-starter/mapper-spring-boot-starter/pom.xml b/spring-boot-starter/mapper-spring-boot-starter/pom.xml index 0c975e2ba..fca070709 100644 --- a/spring-boot-starter/mapper-spring-boot-starter/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-starter/pom.xml @@ -29,7 +29,7 @@ tk.mybatis mapper-spring-boot - 4.2.2-SNAPSHOT + ${revision} mapper-spring-boot-starter mapper-spring-boot-starter diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml index 35712a128..25c3a2995 100644 --- a/spring-boot-starter/pom.xml +++ b/spring-boot-starter/pom.xml @@ -28,12 +28,10 @@ 4.0.0 tk.mybatis - mapper-parent - 8 - + mapper-modules + ${revision} mapper-spring-boot - 4.2.2-SNAPSHOT pom mapper-spring-boot @@ -47,8 +45,6 @@ - 4.2.2-SNAPSHOT - 4.2.2-SNAPSHOT 3.5.9 2.0.7 2.6.4 @@ -84,27 +80,27 @@ tk.mybatis mapper-core - ${mapper-module.version} + ${project.version} tk.mybatis mapper-base - ${mapper-module.version} + ${project.version} tk.mybatis mapper-weekend - ${mapper-weekend.version} + ${project.version} tk.mybatis mapper-spring - ${mapper-module.version} + ${project.version} tk.mybatis mapper-extra - ${mapper-module.version} + ${project.version} org.mybatis diff --git a/spring/pom.xml b/spring/pom.xml index 0f09f4245..923e0fe7d 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -28,7 +28,7 @@ tk.mybatis mapper-modules - 4.2.2-SNAPSHOT + ${revision} mapper-spring jar diff --git a/weekend/pom.xml b/weekend/pom.xml index 4712fade9..8aa0b3a8f 100644 --- a/weekend/pom.xml +++ b/weekend/pom.xml @@ -28,12 +28,10 @@ 4.0.0 tk.mybatis - mapper-parent - 8 - + mapper-modules + ${revision} mapper-weekend - 4.2.2-SNAPSHOT weekend Mybatis通用Mapper扩展 - weekend @@ -53,11 +51,6 @@ - - 1.8 - 4.2.2-SNAPSHOT - - org.mybatis @@ -66,13 +59,13 @@ tk.mybatis mapper-core - ${mapper-module.version} + ${project.version} provided tk.mybatis mapper-base - ${mapper-module.version} + ${project.version} test From 33bfb3491f4b811e8a853446a20e58eb168af5e2 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sat, 9 Apr 2022 15:11:20 +0800 Subject: [PATCH 035/109] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E7=89=88=E6=9C=AC=E5=8F=B7=EF=BC=8Cmysql?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=9D=E8=B5=96=E5=8D=87=E7=BA=A7=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/{verify.yml => test.yml} | 4 ++-- all/mapper/pom.xml | 1 + base/pom.xml | 2 +- pom.xml | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) rename .github/workflows/{verify.yml => test.yml} (82%) diff --git a/.github/workflows/verify.yml b/.github/workflows/test.yml similarity index 82% rename from .github/workflows/verify.yml rename to .github/workflows/test.yml index 5fe434172..460dee580 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Maven verify +name: Maven test on: pull_request: types: [ opened, reopened, edited ] @@ -15,4 +15,4 @@ jobs: java-version: '8' distribution: 'adopt' - name: Run the Maven verify phase - run: mvn --batch-mode --update-snapshots -P dev verify \ No newline at end of file + run: mvn --batch-mode --update-snapshots -P dev test \ No newline at end of file diff --git a/all/mapper/pom.xml b/all/mapper/pom.xml index 34cac3638..c09413976 100644 --- a/all/mapper/pom.xml +++ b/all/mapper/pom.xml @@ -79,6 +79,7 @@ org.apache.maven.plugins maven-shade-plugin + 3.3.0 package diff --git a/base/pom.xml b/base/pom.xml index bfb8b0664..3b63c4ef0 100644 --- a/base/pom.xml +++ b/base/pom.xml @@ -60,7 +60,7 @@ mysql mysql-connector-java - 5.1.45 + 8.0.21 test diff --git a/pom.xml b/pom.xml index 54e9317dd..8bbb42892 100644 --- a/pom.xml +++ b/pom.xml @@ -236,6 +236,7 @@ org.apache.maven.plugins maven-gpg-plugin + 3.0.1 sign-artifacts @@ -255,6 +256,7 @@ org.sonatype.plugins nexus-staging-maven-plugin + 1.6.12 true ossrh From 2b8ad3b5655575a07766c1a70730fa16e626f549 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sat, 23 Apr 2022 15:36:08 +0800 Subject: [PATCH 036/109] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 63 +++++++------------------------------------------------ 1 file changed, 7 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index d71fe8b5d..f72d51a64 100644 --- a/README.md +++ b/README.md @@ -10,67 +10,20 @@ **通用 Mapper 支持 Mybatis-3.2.4 及以上版本。** -## 4.2.2-SNAPSHOT - 2022-04-06 - -- 更新 parent 依赖版本 -- 升级 mybatis 为 3.5.9 -- 升级 hsqldb 为 2.5.2 -- 升级 jps 依赖,使用 2.2 (GAV全变了) -- 修改 test 中的 log4j 为 logback -- 格式化代码 - -## 4.2.1 - 2022-2-27 - -4.2.0 版本中缺少了 gitee 仓库中的两个合并请求,针对这部分代码,再次发布 4.2.1 版本。 - -- `orderByDesc`只有最后一个字段是倒序,改为所有参与`orderby`的字段都倒序 Mr 轩少/V1.1.5-orderByDesc-fix -- 增加Lombok 的`@SuperBuilder、@NoArgsConstructor、@AllArgsConstructor` 注解 tingwen 2020/12/26 18:29 8c816794 - -## 4.2.0 - 2022-2-26 - -本次更新最大改动就是统一了所有模块的版本,所有版本都升级为 4.2.0,在之前本项目一共有3个版本号,本次升级前后的版本如下: - -- mapper, mapper-all, mapper-all-dependencies 从 4.1.5 升级为 4.2.0 -- mapper-core, mapper-base, mapper-extra, mapper-generator, mapper-spring, mapper-weekend 从 1.1.5 升级为 4.2.0 -- mapper-spring-boot-starter 相关模块从 2.1.5 升级为 4.2.0 - -本次更新是 2019年1月28日发布 4.1.5 之后的首次发布,此次更新的内容基本上都来自所有热心开发人员的PR,大部分PR都是功能增强或新功能。 - -- `WeekendSqls` or部分方法参数 String->Object taiyi* 2021/11/29 19:39 1aa5eff6 -- 改进对null的查询 改进对空集合的查询 改进对like的查询 Cheng.Wei* 2020/3/19 0:24 1523d57f -- 改进查询对null值的处理策略 Cheng.Wei* 2020/3/19 0:07 afb6ffc8 -- Update FieldHelper.java kong-ly* 2020/3/17 16:06 4a5675d6 -- 修复一个错误,该错误可能导致 `EntityHelper.entityTableMap` 被错误清空 glacier* 2020/4/1 18:29 8c57af04 -- 扩展一些根据属性及条件值删除的通用方法 jingkaihui* 2020/7/20 17:25 3bf2e1a0 -- 修复 `Example.Criteria` 未设置 `where` 条件查询时,带有逻辑删除注解的表报错问题,fixed #722 jingkaihui* 2020/7/20 15:31 570ef154 -- 修改生成的getter方法注释中@return 列名为@return 属性名 wanglei* 2018/1/24 11:04 b08258bc -- 更新地址 https://mybatis.io abel533 2020/7/27 21:52 ba417dc3 -- 扩展一些根据属性及条件值查询的通用方法 jingkaihui* 2019/10/19 22:14 bd101038 -- 添加日志输出异常和警告信息,fixed #IXNLU isea533 2019/6/18 22:03 1764748e -- 合并 pr #17 isea533 2019/5/30 21:53 8d7819e3 -- [新增] `Weekend`对象增加`excludeProperties、selectProperties、orderBy、withCountProperty` 支持lambda表达式写属性名 - 使用withXXXXX的命名方式链式设置属性 wugh 2019/5/30 14:41 3e25bb9b -- [bug修复] 修复`generateDefaultInstanceMethod`参数,生成的实体类的`defaultInstance`静态方式. 1.存在默认值为''::character varying问题 2.支持基本类型 - wugh 2019/5/30 13:58 cf3e40aa -- [新增] 生成实体类的时候,使用表注释创建类的注释 wugh 2019/5/30 11:28 b4acbf48 -- 增加`lombokEqualsAndHashCodeCallSuper`配置,当使用lombok扩展的`EqualsAndHashCode`注解时,可通过此配置(true)为此注解添加`“callSuper = true”` - ,这对于有继承父类的实体类,如增加支持动态表名时,有用。 calvinit 2019/2/14 13:52 ae901608 - -## 还会有 MyBatis 通用 Mapper5 吗? +## [下一代 通用 Mapper5?](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) 通用 Mapper 每次大的版本,基本上都是底层上的大变化,在使用通用 Mapper 的过程中,有很多人遇到过配置的问题,因为底层实现的方式,所以无法避免配置,而且随着功能的增加,配置也增加了不少。 为了从根本上简化通用方法的实现,从2018年就开始思考如何让实现和MyBatis的兼容性更好,让实现变的更简单,为了从 MyBatis 根本解决问题,给官方提过好几个 PR,在 2019年3月份给 MyBatis 提交的 [pr#1391](https://github.com/mybatis/mybatis-3/pull/1391) 合并后(对应 3.5.1 版本,最低要求版本),终于能以更简单的方式来实现通用 Mapper 了。 -由于此次变动太大,因此不打算对 **通用Mapper4** 进行任何改动,从头实现了一个新的项目,名字仍然没有新意的使用了 `mybatis-mapper`,这个项目也发布很久了,由于工作太忙,没精力像以前那样频繁更新, 所以一直没推广新版 -mybatis-mapper,如果你动手能力强,喜欢看源码,你也可以试试这个项目: +由于此次变动太大,因此不打算对 **通用Mapper4** 进行任何改动,从头实现了一个新的项目,名字仍然没有新意的使用了 `mybatis-mapper`,推荐在新项目中使用: -- [GitHub](https://github.com/mybatis-mapper/mapper) -- [Gitee](https://gitee.com/mybatis-mapper/mapper) +- [GitHub - https://github.com/mybatis-mapper/mapper](https://github.com/mybatis-mapper/mapper) +- [Gitee - https://gitee.com/mybatis-mapper/mapper](https://gitee.com/mybatis-mapper/mapper) - [文档: https://mapper.mybatis.io](https://mapper.mybatis.io/) -- [开发过程](https://mapper.mybatis.io/releases/1.0.0.html) -- [快速上手](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) +- [开发过程 - https://mapper.mybatis.io/releases/1.0.0.html](https://mapper.mybatis.io/releases/1.0.0.html) +- [快速上手 - https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) 另外,通用 Mapper 中的大量 PR 都是增加的新方法和代码生成器相关的注解,这些和核心无关,因此 mybaits-mapper 会提供独立的项目接收所有新增的通用方法, 和代码生成器相关的 lombok 注解完全不需要了,使用新版本中提供的代码生成器可以更方便的进行定制。 @@ -105,11 +58,9 @@ MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) 作者邮箱: abel533@gmail.com -如需加群,请通过 https://mybatis.io 首页按钮加群。 - 推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper) -## 作者新书:《MyBatis 从入门到精通》 +## 《MyBatis 从入门到精通》 ![MyBatis 从入门到精通](https://github.com/mybatis-book/book/raw/master/book.png) From afa72408c470713772d6787ae69171a6b2d66412 Mon Sep 17 00:00:00 2001 From: abel533 Date: Fri, 9 Sep 2022 21:37:55 +0800 Subject: [PATCH 037/109] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20SelectByIdListMapp?= =?UTF-8?q?er=E4=B8=ADselectByIdList=E6=96=B9=E6=B3=95=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E8=AF=AF=E5=AF=BC=E8=87=B4=E6=9F=A5=E5=85=A8=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?fixed=20#865?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/additional/idlist/IdListProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/idlist/IdListProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/idlist/IdListProvider.java index a8a7561ed..cef7c0d0d 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/idlist/IdListProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/idlist/IdListProvider.java @@ -87,7 +87,7 @@ public String selectByIdList(MappedStatement ms) { StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectAllColumns(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); - appendWhereIdList(sql, entityClass, false); + appendWhereIdList(sql, entityClass, isNotEmpty()); return sql.toString(); } From c21a5871a851cb43663ca7605bf76f8ad962791c Mon Sep 17 00:00:00 2001 From: abel533 Date: Tue, 13 Sep 2022 23:59:30 +0800 Subject: [PATCH 038/109] =?UTF-8?q?generator=E5=85=BC=E5=AE=B91.4.x?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E5=92=8C1.3.x=E4=B8=8D=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=EF=BC=8C=E7=89=88=E6=9C=AC=E9=9C=80=E8=A6=81=E5=8C=B9?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generator/pom.xml | 2 +- .../mapper/generator/TemplateFilePlugin.java | 4 +- .../mapper/generator/TkMyBatis3Impl.java | 67 ++++++++++++------- .../generator/TkMyBatis3SimpleImpl.java | 67 ++++++++++++------- .../file/GenerateByListTemplateFile.java | 1 - .../file/GenerateByTemplateFile.java | 1 - 6 files changed, 88 insertions(+), 54 deletions(-) diff --git a/generator/pom.xml b/generator/pom.xml index cb3c1543f..58872fbea 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -69,7 +69,7 @@ org.hsqldb sqltool - 2.3.3 + 2.5.2 test diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java index a690e1f79..6e0bfec64 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java @@ -113,10 +113,8 @@ public class TemplateFilePlugin extends PluginAdapter { public static Field convertToJavaBeansField(IntrospectedColumn introspectedColumn) { FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType(); String property = introspectedColumn.getJavaProperty(); - Field field = new Field(); + Field field = new Field(property, fqjt); field.setVisibility(JavaVisibility.PRIVATE); - field.setType(fqjt); - field.setName(property); return field; } diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/TkMyBatis3Impl.java b/generator/src/main/java/tk/mybatis/mapper/generator/TkMyBatis3Impl.java index c074d6034..cbc78e7fa 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/TkMyBatis3Impl.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/TkMyBatis3Impl.java @@ -25,6 +25,7 @@ package tk.mybatis.mapper.generator; import org.mybatis.generator.codegen.mybatis3.IntrospectedTableMyBatis3Impl; +import org.mybatis.generator.internal.util.StringUtility; import java.text.MessageFormat; @@ -71,41 +72,59 @@ protected void calculateJavaClientAttributes() { } StringBuilder sb = new StringBuilder(); - sb.append(calculateJavaClientImplementationPackage()); + sb.append(this.calculateJavaClientInterfacePackage()); sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("DAOImpl"); //$NON-NLS-1$ - setDAOImplementationType(sb.toString()); - - sb.setLength(0); - sb.append(calculateJavaClientInterfacePackage()); - sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("DAO"); //$NON-NLS-1$ - setDAOInterfaceType(sb.toString()); - - sb.setLength(0); - sb.append(calculateJavaClientInterfacePackage()); - sb.append('.'); - if (stringHasValue(tableConfiguration.getMapperName())) { + if (StringUtility.stringHasValue(this.tableConfiguration.getMapperName())) { //支持mapperName = "{0}Dao" 等用法 sb.append(MessageFormat.format(tableConfiguration.getMapperName(), fullyQualifiedTable.getDomainObjectName())); } else { - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("Mapper"); //$NON-NLS-1$ + if (StringUtility.stringHasValue(this.fullyQualifiedTable.getDomainObjectSubPackage())) { + sb.append(this.fullyQualifiedTable.getDomainObjectSubPackage()); + sb.append('.'); + } + + sb.append(this.fullyQualifiedTable.getDomainObjectName()); + sb.append("Mapper"); } - setMyBatis3JavaMapperType(sb.toString()); + this.setMyBatis3JavaMapperType(sb.toString()); sb.setLength(0); - sb.append(calculateJavaClientInterfacePackage()); + sb.append(this.calculateJavaClientInterfacePackage()); sb.append('.'); - if (stringHasValue(tableConfiguration.getSqlProviderName())) { + if (StringUtility.stringHasValue(this.tableConfiguration.getSqlProviderName())) { //支持mapperName = "{0}SqlProvider" 等用法 sb.append(MessageFormat.format(tableConfiguration.getSqlProviderName(), fullyQualifiedTable.getDomainObjectName())); } else { - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("SqlProvider"); //$NON-NLS-1$ + if (StringUtility.stringHasValue(this.fullyQualifiedTable.getDomainObjectSubPackage())) { + sb.append(this.fullyQualifiedTable.getDomainObjectSubPackage()); + sb.append('.'); + } + + sb.append(this.fullyQualifiedTable.getDomainObjectName()); + sb.append("SqlProvider"); + } + + this.setMyBatis3SqlProviderType(sb.toString()); + sb.setLength(0); + sb.append(this.calculateDynamicSqlSupportPackage()); + sb.append('.'); + if (StringUtility.stringHasValue(this.tableConfiguration.getDynamicSqlSupportClassName())) { + sb.append(this.tableConfiguration.getDynamicSqlSupportClassName()); + } else { + if (StringUtility.stringHasValue(this.fullyQualifiedTable.getDomainObjectSubPackage())) { + sb.append(this.fullyQualifiedTable.getDomainObjectSubPackage()); + sb.append('.'); + } + + sb.append(this.fullyQualifiedTable.getDomainObjectName()); + sb.append("DynamicSqlSupport"); + } + + this.setMyBatisDynamicSqlSupportType(sb.toString()); + if (StringUtility.stringHasValue(this.tableConfiguration.getDynamicSqlTableObjectName())) { + this.setMyBatisDynamicSQLTableObjectName(this.tableConfiguration.getDynamicSqlTableObjectName()); + } else { + this.setMyBatisDynamicSQLTableObjectName(this.fullyQualifiedTable.getDomainObjectName()); } - setMyBatis3SqlProviderType(sb.toString()); } } diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/TkMyBatis3SimpleImpl.java b/generator/src/main/java/tk/mybatis/mapper/generator/TkMyBatis3SimpleImpl.java index 455b1e247..2ce415110 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/TkMyBatis3SimpleImpl.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/TkMyBatis3SimpleImpl.java @@ -25,6 +25,7 @@ package tk.mybatis.mapper.generator; import org.mybatis.generator.codegen.mybatis3.IntrospectedTableMyBatis3SimpleImpl; +import org.mybatis.generator.internal.util.StringUtility; import java.text.MessageFormat; @@ -71,41 +72,59 @@ protected void calculateJavaClientAttributes() { } StringBuilder sb = new StringBuilder(); - sb.append(calculateJavaClientImplementationPackage()); + sb.append(this.calculateJavaClientInterfacePackage()); sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("DAOImpl"); //$NON-NLS-1$ - setDAOImplementationType(sb.toString()); - - sb.setLength(0); - sb.append(calculateJavaClientInterfacePackage()); - sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("DAO"); //$NON-NLS-1$ - setDAOInterfaceType(sb.toString()); - - sb.setLength(0); - sb.append(calculateJavaClientInterfacePackage()); - sb.append('.'); - if (stringHasValue(tableConfiguration.getMapperName())) { + if (StringUtility.stringHasValue(this.tableConfiguration.getMapperName())) { //支持mapperName = "{0}Dao" 等用法 sb.append(MessageFormat.format(tableConfiguration.getMapperName(), fullyQualifiedTable.getDomainObjectName())); } else { - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("Mapper"); //$NON-NLS-1$ + if (StringUtility.stringHasValue(this.fullyQualifiedTable.getDomainObjectSubPackage())) { + sb.append(this.fullyQualifiedTable.getDomainObjectSubPackage()); + sb.append('.'); + } + + sb.append(this.fullyQualifiedTable.getDomainObjectName()); + sb.append("Mapper"); } - setMyBatis3JavaMapperType(sb.toString()); + this.setMyBatis3JavaMapperType(sb.toString()); sb.setLength(0); - sb.append(calculateJavaClientInterfacePackage()); + sb.append(this.calculateJavaClientInterfacePackage()); sb.append('.'); - if (stringHasValue(tableConfiguration.getSqlProviderName())) { + if (StringUtility.stringHasValue(this.tableConfiguration.getSqlProviderName())) { //支持mapperName = "{0}SqlProvider" 等用法 sb.append(MessageFormat.format(tableConfiguration.getSqlProviderName(), fullyQualifiedTable.getDomainObjectName())); } else { - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("SqlProvider"); //$NON-NLS-1$ + if (StringUtility.stringHasValue(this.fullyQualifiedTable.getDomainObjectSubPackage())) { + sb.append(this.fullyQualifiedTable.getDomainObjectSubPackage()); + sb.append('.'); + } + + sb.append(this.fullyQualifiedTable.getDomainObjectName()); + sb.append("SqlProvider"); + } + + this.setMyBatis3SqlProviderType(sb.toString()); + sb.setLength(0); + sb.append(this.calculateDynamicSqlSupportPackage()); + sb.append('.'); + if (StringUtility.stringHasValue(this.tableConfiguration.getDynamicSqlSupportClassName())) { + sb.append(this.tableConfiguration.getDynamicSqlSupportClassName()); + } else { + if (StringUtility.stringHasValue(this.fullyQualifiedTable.getDomainObjectSubPackage())) { + sb.append(this.fullyQualifiedTable.getDomainObjectSubPackage()); + sb.append('.'); + } + + sb.append(this.fullyQualifiedTable.getDomainObjectName()); + sb.append("DynamicSqlSupport"); + } + + this.setMyBatisDynamicSqlSupportType(sb.toString()); + if (StringUtility.stringHasValue(this.tableConfiguration.getDynamicSqlTableObjectName())) { + this.setMyBatisDynamicSQLTableObjectName(this.tableConfiguration.getDynamicSqlTableObjectName()); + } else { + this.setMyBatisDynamicSQLTableObjectName(this.fullyQualifiedTable.getDomainObjectName()); } - setMyBatis3SqlProviderType(sb.toString()); } } diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/file/GenerateByListTemplateFile.java b/generator/src/main/java/tk/mybatis/mapper/generator/file/GenerateByListTemplateFile.java index df419706f..7653ec509 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/file/GenerateByListTemplateFile.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/file/GenerateByListTemplateFile.java @@ -53,7 +53,6 @@ public class GenerateByListTemplateFile extends GeneratedJavaFile { public GenerateByListTemplateFile(Set tableClassSet, ListTemplateFormatter templateFormatter, Properties properties, String targetProject, String targetPackage, String fileNameTemplate, String templateContent) { super(null, targetProject, ENCODING, null); - this.targetProject = targetProject; this.targetPackage = targetPackage; this.fileNameTemplate = fileNameTemplate; this.templateContent = templateContent; diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/file/GenerateByTemplateFile.java b/generator/src/main/java/tk/mybatis/mapper/generator/file/GenerateByTemplateFile.java index 0fa76950f..c86f61fb4 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/file/GenerateByTemplateFile.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/file/GenerateByTemplateFile.java @@ -52,7 +52,6 @@ public class GenerateByTemplateFile extends GeneratedJavaFile { public GenerateByTemplateFile(TableClass tableClass, TemplateFormatter templateFormatter, Properties properties, String targetProject, String targetPackage, String fileName, String templateContent) { super(null, targetProject, ENCODING, null); - this.targetProject = targetProject; this.targetPackage = targetPackage; this.fileName = fileName; this.templateContent = templateContent; From 4a17dff1e62f6ccae75af2390588d68d6240cdb3 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Mon, 3 Oct 2022 22:37:40 +0000 Subject: [PATCH 039/109] vuln-fix: Use HTTPS instead of HTTP to resolve dependencies This fixes a security vulnerability in this project where the `build.gradle` files were configuring Gradle to resolve dependencies over HTTP instead of HTTPS. Weakness: CWE-829: Inclusion of Functionality from Untrusted Control Sphere Severity: High CVSSS: 8.1 Detection: OpenRewrite Reported-by: Jonathan Leitschuh Signed-off-by: Jonathan Leitschuh Bug-tracker: https://github.com/JLLeitschuh/security-research/issues/9 Co-authored-by: Moderne --- spring-boot-starter/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml index 25c3a2995..b10847a46 100644 --- a/spring-boot-starter/pom.xml +++ b/spring-boot-starter/pom.xml @@ -53,25 +53,25 @@ spring-snapshots - http://repo.spring.io/snapshot + https://repo.spring.io/snapshot true spring-milestones - http://repo.spring.io/milestone + https://repo.spring.io/milestone spring-snapshots - http://repo.spring.io/snapshot + https://repo.spring.io/snapshot spring-milestones - http://repo.spring.io/milestone + https://repo.spring.io/milestone From 08f4f7a5c0149b187d91a2c3ee1bd8390df2315a Mon Sep 17 00:00:00 2001 From: Talank Baral Date: Sun, 3 Oct 2021 16:16:24 +0545 Subject: [PATCH 040/109] Fixed OD flaky tests in tk.mybatis.mapper.test.country.TestDeleteByPrimaryKey --- .../test/country/TestDeleteByPrimaryKey.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/base/src/test/java/tk/mybatis/mapper/test/country/TestDeleteByPrimaryKey.java b/base/src/test/java/tk/mybatis/mapper/test/country/TestDeleteByPrimaryKey.java index 488931d52..79738f83c 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/country/TestDeleteByPrimaryKey.java +++ b/base/src/test/java/tk/mybatis/mapper/test/country/TestDeleteByPrimaryKey.java @@ -24,13 +24,18 @@ package tk.mybatis.mapper.test.country; +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import tk.mybatis.mapper.mapper.CountryMapper; import tk.mybatis.mapper.mapper.MybatisHelper; import tk.mybatis.mapper.model.Country; - +import java.io.IOException; +import java.io.Reader; +import java.sql.Connection; import java.util.HashMap; import java.util.Map; @@ -40,7 +45,22 @@ * @author liuzh */ public class TestDeleteByPrimaryKey { - + @Before + public void setupDB() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + Connection conn = sqlSession.getConnection(); + Reader reader = Resources.getResourceAsReader("CreateDB.sql"); + ScriptRunner runner = new ScriptRunner(conn); + runner.setLogWriter(null); + runner.runScript(reader); + reader.close(); + } catch (IOException e) {} + finally { + sqlSession.close(); + } + } + /** * 主要测试删除 */ From ee139d6919c590cb8d774361ac2724b3ab5c33f2 Mon Sep 17 00:00:00 2001 From: Talank Baral Date: Tue, 12 Oct 2021 16:32:37 +0545 Subject: [PATCH 041/109] Fixed indentation --- .../mapper/test/country/TestDeleteByPrimaryKey.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/base/src/test/java/tk/mybatis/mapper/test/country/TestDeleteByPrimaryKey.java b/base/src/test/java/tk/mybatis/mapper/test/country/TestDeleteByPrimaryKey.java index 79738f83c..53f3c4dda 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/country/TestDeleteByPrimaryKey.java +++ b/base/src/test/java/tk/mybatis/mapper/test/country/TestDeleteByPrimaryKey.java @@ -33,6 +33,7 @@ import tk.mybatis.mapper.mapper.CountryMapper; import tk.mybatis.mapper.mapper.MybatisHelper; import tk.mybatis.mapper.model.Country; + import java.io.IOException; import java.io.Reader; import java.sql.Connection; @@ -45,8 +46,9 @@ * @author liuzh */ public class TestDeleteByPrimaryKey { - @Before - public void setupDB() { + + @Before + public void setupDB() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { Connection conn = sqlSession.getConnection(); @@ -55,11 +57,11 @@ public void setupDB() { runner.setLogWriter(null); runner.runScript(reader); reader.close(); - } catch (IOException e) {} + } catch (IOException e) {} finally { sqlSession.close(); } - } + } /** * 主要测试删除 From dcd21a90faa52efa34aeb9d4d5f1ba11519c4f2a Mon Sep 17 00:00:00 2001 From: yangb <523084685@qq.com> Date: Tue, 12 May 2020 18:02:41 +0800 Subject: [PATCH 042/109] =?UTF-8?q?feature:=20:tada:=20=E9=80=9A=E7=94=A8M?= =?UTF-8?q?apper=E6=8E=A5=E5=8F=A3,=E4=BF=9D=E5=AD=98(save).=20

?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=B8=BB=E9=94=AE=E6=98=AF=E5=90=A6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8,=20=E5=A6=82=E6=9E=9C=E5=AD=98=E5=9C=A8=E4=B8=94?= =?UTF-8?q?=E4=B8=8D=E4=B8=BA=E7=A9=BA=E6=89=A7=E8=A1=8Cupdate=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5,=E5=A6=82=E6=9E=9C=E4=B8=BB=E9=94=AE=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=88=96=E4=B8=BA=E7=A9=BA,=20=E6=89=A7?= =?UTF-8?q?=E8=A1=8Cinsert=E8=AF=AD=E5=8F=A5

?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/tk/mybatis/mapper/common/Mapper.java | 1 + .../tk/mybatis/mapper/common/SaveMapper.java | 22 +++ .../mybatis/mapper/provider/SaveProvider.java | 130 ++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 base/src/main/java/tk/mybatis/mapper/common/SaveMapper.java create mode 100644 base/src/main/java/tk/mybatis/mapper/provider/SaveProvider.java diff --git a/base/src/main/java/tk/mybatis/mapper/common/Mapper.java b/base/src/main/java/tk/mybatis/mapper/common/Mapper.java index ef12ffd66..41b0fd994 100644 --- a/base/src/main/java/tk/mybatis/mapper/common/Mapper.java +++ b/base/src/main/java/tk/mybatis/mapper/common/Mapper.java @@ -39,6 +39,7 @@ public interface Mapper extends BaseMapper, ExampleMapper, RowBoundsMapper, + SaveMapper, Marker { } \ No newline at end of file diff --git a/base/src/main/java/tk/mybatis/mapper/common/SaveMapper.java b/base/src/main/java/tk/mybatis/mapper/common/SaveMapper.java new file mode 100644 index 000000000..1612a2c1b --- /dev/null +++ b/base/src/main/java/tk/mybatis/mapper/common/SaveMapper.java @@ -0,0 +1,22 @@ +package tk.mybatis.mapper.common; + +import org.apache.ibatis.annotations.InsertProvider; +import tk.mybatis.mapper.provider.SaveProvider; + +/** + * 通用Mapper接口,保存 + *

判断主键是否存在, 如果存在且不为空执行update语句,如果主键不存在或为空, 执行insert语句

+ * Created by YangBin on 2020/5/12 + * Copyright (c) 2020 杨斌 All rights reserved. + */ +public interface SaveMapper { + + /** + * 保存一个实体,如果实体的主键不为null则更新记录, 主键不存在或主键为null, 则插入记录 + * + * @param record 不能为空 + * @return + */ + @InsertProvider(type = SaveProvider.class, method = "dynamicSQL") + int save(T record); +} diff --git a/base/src/main/java/tk/mybatis/mapper/provider/SaveProvider.java b/base/src/main/java/tk/mybatis/mapper/provider/SaveProvider.java new file mode 100644 index 000000000..9438d2346 --- /dev/null +++ b/base/src/main/java/tk/mybatis/mapper/provider/SaveProvider.java @@ -0,0 +1,130 @@ +package tk.mybatis.mapper.provider; + +import org.apache.ibatis.mapping.MappedStatement; +import tk.mybatis.mapper.MapperException; +import tk.mybatis.mapper.entity.EntityColumn; +import tk.mybatis.mapper.mapperhelper.*; + +import java.lang.reflect.Field; +import java.util.Set; + +/** + * 保存实现类 + * Created by YangBin on 2020/5/12 + * Copyright (c) 2020 杨斌 All rights reserved. + */ +public class SaveProvider extends MapperTemplate { + + + public SaveProvider(Class mapperClass, MapperHelper mapperHelper) { + super(mapperClass, mapperHelper); + } + + /** + * 保存策略: 如果主键不为空则更新记录, 如果没有主键或者主键为空,则插入. + * @param ms + * @return + */ + public String save(MappedStatement ms){ + + Class entityClass = getEntityClass(ms); + Field[] fields = entityClass.getFields(); + StringBuilder sql = new StringBuilder(); + + Set columnList = EntityHelper.getPKColumns(entityClass); + if (columnList.size() == 1) { + EntityColumn column = (EntityColumn)columnList.iterator().next(); + String id = column.getColumn(); + sql.append(""); + sql.append(""); + sql.append(updateByPrimaryKey(ms)); + sql.append(""); + sql.append(""); + sql.append(insert(ms)); + sql.append(""); + sql.append(""); + return sql.toString(); + } + return insert(ms); + } + + /** + * 通过主键更新全部字段 + * + * @param ms + */ + public String updateByPrimaryKey(MappedStatement ms) { + Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass))); + sql.append(SqlHelper.updateSetColumns(entityClass, null, false, false)); + sql.append(SqlHelper.wherePKColumns(entityClass, true)); + return sql.toString(); + } + + public String insert(MappedStatement ms) { + Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + //获取全部列 + Set columnList = EntityHelper.getColumns(entityClass); + processKey(sql, entityClass, ms, columnList); + sql.append(SqlHelper.insertIntoTable(entityClass, tableName(entityClass))); + sql.append(SqlHelper.insertColumns(entityClass, false, false, false)); + sql.append(""); + for (EntityColumn column : columnList) { + if (!column.isInsertable()) { + continue; + } + //优先使用传入的属性值,当原属性property!=null时,用原属性 + //自增的情况下,如果默认有值,就会备份到property_cache中,所以这里需要先判断备份的值是否存在 + if (column.isIdentity()) { + sql.append(SqlHelper.getIfCacheNotNull(column, column.getColumnHolder(null, "_cache", ","))); + } else { + //其他情况值仍然存在原property中 + sql.append(SqlHelper.getIfNotNull(column, column.getColumnHolder(null, null, ","), isNotEmpty())); + } + //当属性为null时,如果存在主键策略,会自动获取值,如果不存在,则使用null + if (column.isIdentity()) { + sql.append(SqlHelper.getIfCacheIsNull(column, column.getColumnHolder() + ",")); + } else { + //当null的时候,如果不指定jdbcType,oracle可能会报异常,指定VARCHAR不影响其他 + sql.append(SqlHelper.getIfIsNull(column, column.getColumnHolder(null, null, ","), isNotEmpty())); + } + } + sql.append(""); + return sql.toString(); + } + + private void processKey(StringBuilder sql, Class entityClass, MappedStatement ms, Set columnList){ + //Identity列只能有一个 + Boolean hasIdentityKey = false; + //先处理cache或bind节点 + for (EntityColumn column : columnList) { + if (column.isIdentity()) { + //这种情况下,如果原先的字段有值,需要先缓存起来,否则就一定会使用自动增长 + //这是一个bind节点 + sql.append(SqlHelper.getBindCache(column)); + //如果是Identity列,就需要插入selectKey + //如果已经存在Identity列,抛出异常 + if (hasIdentityKey) { + //jdbc类型只需要添加一次 + if (column.getGenerator() != null && column.getGenerator().equals("JDBC")) { + continue; + } + throw new MapperException(ms.getId() + "对应的实体类" + entityClass.getCanonicalName() + "中包含多个MySql的自动增长列,最多只能有一个!"); + } + //插入selectKey + SelectKeyHelper.newSelectKeyMappedStatement(ms, column, entityClass, isBEFORE(), getIDENTITY(column)); + hasIdentityKey = true; + } else if(column.getGenIdClass() != null){ + sql.append(""); + } + + } + } +} From 57102f1f4dec8965076edbec8da07e4c284f55b7 Mon Sep 17 00:00:00 2001 From: huangkaifeng Date: Tue, 7 Apr 2020 11:19:41 +0800 Subject: [PATCH 043/109] align mybatis-spring to 1.3.2 in all modules --- spring/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring/pom.xml b/spring/pom.xml index 923e0fe7d..e68ae59e5 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -38,7 +38,7 @@ 4.3.8.RELEASE - 1.3.1 + 1.3.2 From beec5fd947446faeb361c129b68881aa5c66324b Mon Sep 17 00:00:00 2001 From: contextshuffling Date: Sat, 21 Sep 2019 18:54:52 -0500 Subject: [PATCH 044/109] sorting fields for deterministic order --- .../java/tk/mybatis/mapper/mapperhelper/FieldHelper.java | 6 ++++++ .../java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java index 4868fc84b..df7594a4e 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java @@ -188,6 +188,12 @@ private List _getFields(Class entityClass, List fie return fieldList; } Field[] fields = entityClass.getDeclaredFields(); + Arrays.sort(fields, new Comparator() { + @Override + public int compare(Object a, Object b) { + return a.toString().compareTo(b.toString()); + } + }); int index = 0; for (int i = 0; i < fields.length; i++) { Field field = fields[i]; diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java index 78308e53a..1589e20de 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java @@ -35,7 +35,7 @@ public void testLogicDeleteSql() { Assert.assertEquals(" AND is_valid = 1", notLogicDeletedColumn); String updateSetColumns = SqlHelper.updateSetColumns(User.class, null, false, false); - Assert.assertEquals("username = #{username},is_valid = 1,", updateSetColumns); + Assert.assertEquals("is_valid = 1,username = #{username},", updateSetColumns); } } From c5733f8a3fb9dfdc64a6e3638fd1d59b3a397e28 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 11:45:51 +0800 Subject: [PATCH 045/109] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E8=A1=A8=E5=AF=B9=E5=BA=94=E7=9A=84drop=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/src/test/resources/CreateDB.sql | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/base/src/test/resources/CreateDB.sql b/base/src/test/resources/CreateDB.sql index b7eb2ef1e..de85a83e6 100644 --- a/base/src/test/resources/CreateDB.sql +++ b/base/src/test/resources/CreateDB.sql @@ -8,38 +8,43 @@ create table country version INTEGER DEFAULT 1 NOT NULL ); +drop table country2 if exists; create table country2 ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, + id integer GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY, countryname varchar(32), countrycode varchar(2) DEFAULT 'HH' ); +drop table country_t if exists; create table country_t ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, + id integer GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY, countryname varchar(32) ); +drop table country_jdbc if exists; create table country_jdbc ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, + id integer GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY, countryname varchar(128), countrycode varchar(2) ); +drop table country_i if exists; create table country_i ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, + id integer GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY, countryname varchar(128), countrycode varchar(2) DEFAULT 'HH' ); --用户信息表 +drop table user_info if exists; create table user_info ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, - username varchar(32) NOT NULL, + id integer GENERATED BY DEFAULT AS IDENTITY (START WITH 6) NOT NULL PRIMARY KEY, + username varchar(32) NOT NULL, password varchar(32) DEFAULT '12345678', usertype varchar(2), enabled integer, @@ -51,10 +56,11 @@ create table user_info ); --用户信息表 +drop table user_info_map if exists; create table user_info_map ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, - user_name varchar(32) NOT NULL, + id integer GENERATED BY DEFAULT AS IDENTITY (START WITH 6) NOT NULL PRIMARY KEY, + user_name varchar(32) NOT NULL, password varchar(32) DEFAULT '12345678', user_type varchar(2), real_name varchar(50) @@ -84,10 +90,11 @@ values (5, 'test5', 'dddd', '1'); --用户登录表,logid和username联合主键 +drop table user_login if exists; create table user_login ( - logid integer GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL, - username varchar(32) NOT NULL, + logid integer GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL, + username varchar(32) NOT NULL, logindate DATETIME, loginip varchar(16), PRIMARY KEY (logid, username) @@ -489,10 +496,11 @@ values (174, 'United States of America'); --用户信息表 +drop table tb_user if exists; create table tb_user ( - id integer GENERATED BY DEFAULT AS IDENTITY(START WITH 6) NOT NULL PRIMARY KEY, - username varchar(32) NOT NULL, + id integer GENERATED BY DEFAULT AS IDENTITY (START WITH 6) NOT NULL PRIMARY KEY, + username varchar(32) NOT NULL, password varchar(32) DEFAULT '12345678', is_valid integer ); From 4d6ac91a3f20f28f51684bf646d4fd52a13d131b Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 11:46:47 +0800 Subject: [PATCH 046/109] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20pr#664=20=E4=B8=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=AD=97=E6=AE=B5=E4=BD=8D=E7=BD=AE=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=AF=BC=E8=87=B4=20and=20=E6=8B=BC=E6=8E=A5=E6=9C=89?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java index 1094a60ea..1c86fdd1d 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java @@ -944,6 +944,7 @@ public static String exampleCheck(Class entityClass) { public static String exampleWhereClause() { return "" + "\n" + + " ${@tk.mybatis.mapper.util.OGNL@andNotLogicDelete(_parameter)}" + " \n" + " \n" + " \n" + @@ -972,7 +973,6 @@ public static String exampleWhereClause() { " \n" + " \n" + " \n" + - " ${@tk.mybatis.mapper.util.OGNL@andNotLogicDelete(_parameter)}" + "" + ""; } @@ -984,6 +984,7 @@ public static String exampleWhereClause() { */ public static String updateByExampleWhereClause() { return "\n" + + " ${@tk.mybatis.mapper.util.OGNL@andNotLogicDelete(example)}" + " \n" + " \n" + " \n" + @@ -1012,7 +1013,6 @@ public static String updateByExampleWhereClause() { " \n" + " \n" + " \n" + - " ${@tk.mybatis.mapper.util.OGNL@andNotLogicDelete(example)}" + ""; } From 79d313a7ca6cba6c5d5323746fb83ed5744180a1 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 13:39:03 +0800 Subject: [PATCH 047/109] =?UTF-8?q?=E5=8E=BB=E6=8E=89=20#666=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9A=84=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/tk/mybatis/mapper/mapperhelper/FieldHelper.java | 6 ------ .../java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java index df7594a4e..4868fc84b 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java @@ -188,12 +188,6 @@ private List _getFields(Class entityClass, List fie return fieldList; } Field[] fields = entityClass.getDeclaredFields(); - Arrays.sort(fields, new Comparator() { - @Override - public int compare(Object a, Object b) { - return a.toString().compareTo(b.toString()); - } - }); int index = 0; for (int i = 0; i < fields.length; i++) { Field field = fields[i]; diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java index 1589e20de..78308e53a 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java @@ -35,7 +35,7 @@ public void testLogicDeleteSql() { Assert.assertEquals(" AND is_valid = 1", notLogicDeletedColumn); String updateSetColumns = SqlHelper.updateSetColumns(User.class, null, false, false); - Assert.assertEquals("is_valid = 1,username = #{username},", updateSetColumns); + Assert.assertEquals("username = #{username},is_valid = 1,", updateSetColumns); } } From 240cf745122f7cfff80f80eeb504a74529fdb9aa Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 13:39:25 +0800 Subject: [PATCH 048/109] =?UTF-8?q?=E5=AE=8C=E5=96=84=20flatten-maven-plug?= =?UTF-8?q?in=20=E6=8F=92=E4=BB=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- all/pom.xml | 30 ++++++++++++++++++++++++++++++ pom.xml | 53 +++++++++++++++++++++++++---------------------------- 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/all/pom.xml b/all/pom.xml index 740484133..d360522f3 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -81,4 +81,34 @@ + + + + + org.codehaus.mojo + flatten-maven-plugin + 1.1.0 + + true + bom + + + + flatten + process-resources + + flatten + + + + flatten.clean + clean + + clean + + + + + + diff --git a/pom.xml b/pom.xml index 8bbb42892..5cd233647 100644 --- a/pom.xml +++ b/pom.xml @@ -163,6 +163,31 @@ + + org.codehaus.mojo + flatten-maven-plugin + 1.1.0 + + true + resolveCiFriendliesOnly + + + + flatten + process-resources + + flatten + + + + flatten.clean + clean + + clean + + + + @@ -204,34 +229,6 @@ - - org.codehaus.mojo - flatten-maven-plugin - 1.1.0 - - true - resolveCiFriendliesOnly - - expand - - - - - flatten - process-resources - - flatten - - - - flatten.clean - clean - - clean - - - - org.apache.maven.plugins From 7859ca3dd389c5010aa9f5ac2b5c4d2d475f4700 Mon Sep 17 00:00:00 2001 From: wendell Date: Wed, 18 Sep 2019 12:31:46 +0800 Subject: [PATCH 049/109] =?UTF-8?q?=E5=AF=B9=E8=8E=B7=E5=8F=96=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E5=AD=97=E6=AE=B5=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java index 4868fc84b..99de8d063 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java @@ -155,6 +155,7 @@ static class Jdk8FieldHelper implements IFieldHelper { @Override public List getFields(Class entityClass) { List fields = _getFields(entityClass, null, null); + fields = new ArrayList(new LinkedHashSet(fields)); List properties = getProperties(entityClass); Set usedSet = new HashSet(); for (EntityField field : fields) { @@ -251,7 +252,7 @@ static class Jdk6_7FieldHelper implements IFieldHelper { public List getFields(Class entityClass) { List fieldList = new ArrayList(); _getFields(entityClass, fieldList, _getGenericTypeMap(entityClass), null); - return fieldList; + return new ArrayList(new LinkedHashSet(fieldList)); } /** From a065368a1ba2beafe2beaa28c01bb814b3a5a537 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 14:26:04 +0800 Subject: [PATCH 050/109] =?UTF-8?q?=E8=A7=A3=E5=86=B3if=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E6=B7=B7=E4=B9=B1=EF=BC=8C=E6=94=B9=E4=B8=BA=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E5=B9=B6=E4=B8=94=E5=AE=B9=E6=98=93=E7=90=86=E8=A7=A3=E7=9A=84?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E5=92=8C=E6=96=B9=E5=BC=8F=EF=BC=8Cfixed=20#?= =?UTF-8?q?637=20#644?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapperhelper/resolve/DefaultEntityResolve.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java index f4751eed3..1b1c534b3 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java @@ -75,15 +75,13 @@ public EntityTable resolveEntity(Class entityClass, Config config) { //如果启用了简单类型,就做简单类型校验,如果不是简单类型,直接跳过 //3.5.0 如果启用了枚举作为简单类型,就不会自动忽略枚举类型 //4.0 如果标记了 Column 或 ColumnType 注解,也不忽略 - if (config.isUseSimpleType() - && !field.isAnnotationPresent(Column.class) - && !field.isAnnotationPresent(ColumnType.class) - && !(SimpleTypeUtil.isSimpleType(field.getJavaType()) - || - (config.isEnumAsSimpleType() && Enum.class.isAssignableFrom(field.getJavaType())))) { - continue; + if (!config.isUseSimpleType() //关闭简单类型限制时,所有字段都处理 + || (config.isUseSimpleType() && SimpleTypeUtil.isSimpleType(field.getJavaType())) //开启简单类型时只处理包含的简单类型 + || field.isAnnotationPresent(Column.class) //有注解的处理,不考虑类型 + || field.isAnnotationPresent(ColumnType.class) //有注解的处理,不考虑类型 + || (config.isEnumAsSimpleType() && Enum.class.isAssignableFrom(field.getJavaType()))) { //开启枚举作为简单类型时处理 + processField(entityTable, field, config, style); } - processField(entityTable, field, config, style); } //当pk.size=0的时候使用所有列作为主键 if (entityTable.getEntityClassPKColumns().size() == 0) { From 0f8216e8496a5ffa55d2f623c9dc966ab9f44973 Mon Sep 17 00:00:00 2001 From: Eric Hettiaratchi <35978114+Braavos96@users.noreply.github.com> Date: Mon, 1 Jul 2019 17:46:32 +0100 Subject: [PATCH 051/109] Add unit tests for tk.mybatis.mapper.util.StringUtil These tests were written using Diffblue Cover. --- .../mybatis/mapper/util/StringUtilTest.java | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 core/src/test/java/tk/mybatis/mapper/util/StringUtilTest.java diff --git a/core/src/test/java/tk/mybatis/mapper/util/StringUtilTest.java b/core/src/test/java/tk/mybatis/mapper/util/StringUtilTest.java new file mode 100644 index 000000000..15f21246d --- /dev/null +++ b/core/src/test/java/tk/mybatis/mapper/util/StringUtilTest.java @@ -0,0 +1,104 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014-2019 abel533@gmail.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package tk.mybatis.mapper.util; + +import org.junit.Test; +import org.junit.Assert; +import tk.mybatis.mapper.code.Style; + +public class StringUtilTest { + + @Test + public void testIsEmpty() { + Assert.assertTrue(StringUtil.isEmpty(null)); + Assert.assertTrue(StringUtil.isEmpty("")); + + Assert.assertFalse(StringUtil.isEmpty(" ")); + Assert.assertFalse(StringUtil.isEmpty("foo")); + } + + @Test + public void testIsNotEmpty() { + Assert.assertFalse(StringUtil.isNotEmpty(null)); + Assert.assertFalse(StringUtil.isNotEmpty("")); + + Assert.assertTrue(StringUtil.isNotEmpty(" ")); + Assert.assertTrue(StringUtil.isNotEmpty("foo")); + } + + @Test + public void testConvertByStyle() { + Assert.assertEquals("fOo", + StringUtil.convertByStyle("fOo", Style.normal)); + Assert.assertEquals("f_oo", + StringUtil.convertByStyle("fOo", Style.camelhump)); + Assert.assertEquals("FOO", + StringUtil.convertByStyle("fOo", Style.uppercase)); + Assert.assertEquals("foo", + StringUtil.convertByStyle("FoO", Style.lowercase)); + Assert.assertEquals("fo_o", + StringUtil.convertByStyle("FoO", Style.camelhumpAndLowercase)); + Assert.assertEquals("F_OO", + StringUtil.convertByStyle("fOo", Style.camelhumpAndUppercase)); + } + + @Test + public void testCamelhumpToUnderline() { + Assert.assertEquals("foo", StringUtil.camelhumpToUnderline("foo")); + Assert.assertEquals("f_oo", StringUtil.camelhumpToUnderline("fOo")); + } + + @Test + public void testUnderlineToCamelhump() { + Assert.assertEquals("foo", StringUtil.underlineToCamelhump("foo")); + Assert.assertEquals("foo", StringUtil.underlineToCamelhump("Foo")); + } + + @Test + public void testIsUppercaseAlpha() { + Assert.assertTrue(StringUtil.isUppercaseAlpha('F')); + + Assert.assertFalse(StringUtil.isUppercaseAlpha('f')); + } + + @Test + public void testIsLowercaseAlpha() { + Assert.assertTrue(StringUtil.isLowercaseAlpha('f')); + + Assert.assertFalse(StringUtil.isLowercaseAlpha('F')); + } + + @Test + public void testToUpperAscii() { + Assert.assertEquals('F', StringUtil.toUpperAscii('f')); + Assert.assertEquals('F', StringUtil.toUpperAscii('F')); + } + + @Test + public void testToLowerAscii() { + Assert.assertEquals('f', StringUtil.toLowerAscii('f')); + Assert.assertEquals('f', StringUtil.toLowerAscii('F')); + } +} From 719f4151f8ce981cb333b95ab0e414f1b1b0e1ca Mon Sep 17 00:00:00 2001 From: linweichao <934971538@qq.com> Date: Mon, 20 May 2019 20:41:24 +0800 Subject: [PATCH 052/109] =?UTF-8?q?=E6=B7=BB=E5=8A=A0WeekendSqls=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=EF=BC=8C=E6=8F=90=E4=BE=9B=E4=B8=80?= =?UTF-8?q?=E7=B3=BB=E5=88=97=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E6=B3=9B=E5=9E=8B=E5=8F=82=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=EF=BC=8C=E4=BD=BF=E4=BB=A3=E7=A0=81=E6=9B=B4?= =?UTF-8?q?=E7=AE=80=E6=B4=81=E3=80=81=E6=B8=85=E6=99=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/weekend/WeekendSqlsUtils.java | 279 ++++++++++++++++++ .../mapper/weekend/WeekendSqlsUtilsTest.java | 92 ++++++ 2 files changed, 371 insertions(+) create mode 100644 weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java create mode 100644 weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsUtilsTest.java diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java new file mode 100644 index 000000000..e87305153 --- /dev/null +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java @@ -0,0 +1,279 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014-2017 the original author or authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package tk.mybatis.mapper.weekend; + +/** + * {@link WeekendSqls} 的工具类,提供一系列静态方法,减少泛型参数的指定,使代码更简洁、清晰 + * + * 直接使用WeekSqls,以下的查询需要指定两次泛型参数: + * List selectByWeekendSql = mapper.selectByExample(new Example.Builder(Country.class) + * .where(WeekendSqls.custom().andLike(Country::getCountryname, "%a%") + * .andGreaterThan(Country::getCountrycode, "123")) + * .build()); + * + * 使用 WeekendSqlsUtils,只需指定一次泛型参数: + * List selectByWeekendSql = mapper.selectByExample(new Example.Builder(Country.class) + * .where(WeekendSqlsUtils.andLike(Country::getCountryname, "%a%") + * .andGreaterThan(Country::getCountrycode, "123")) + * .build()); + * + * 建议使用 import static,代码会简洁一些 + * import static tk.mybatis.mapper.weekend.WeekendSqlsUtils.andLike; + * + * List selectByWeekendSql = mapper.selectByExample(new Example.Builder(Country.class) + * .where(andLike(Country::getCountryname, "%a%") + * .andGreaterThan(Country::getCountrycode, "123")) + * .build()); + * @author linweichao + * @date 2019/5/20 + */ +public class WeekendSqlsUtils { + + public static WeekendSqls andIsNull(String property) { + return WeekendSqls.custom().andIsNull(property); + } + + public static WeekendSqls andIsNull(Fn fn) { + return WeekendSqls.custom().andIsNull(fn); + } + + public static WeekendSqls andIsNotNull(String property) { + return WeekendSqls.custom().andIsNotNull(property); + } + + public static WeekendSqls andIsNotNull(Fn fn) { + return WeekendSqls.custom().andIsNotNull(fn); + } + + public static WeekendSqls andEqualTo(String property, Object value) { + return WeekendSqls.custom().andEqualTo(property, value); + } + + public static WeekendSqls andEqualTo(Fn fn, Object value) { + return WeekendSqls.custom().andEqualTo(fn, value); + } + + public static WeekendSqls andNotEqualTo(String property, Object value) { + return WeekendSqls.custom().andNotEqualTo(property, value); + } + + public static WeekendSqls andNotEqualTo(Fn fn, Object value) { + return WeekendSqls.custom().andNotEqualTo(fn, value); + } + + public static WeekendSqls andGreaterThan(String property, Object value) { + return WeekendSqls.custom().andGreaterThan(property, value); + } + + public static WeekendSqls andGreaterThan(Fn fn, Object value) { + return WeekendSqls.custom().andGreaterThan(fn, value); + } + + public static WeekendSqls andGreaterThanOrEqualTo(String property, Object value) { + return WeekendSqls.custom().andGreaterThanOrEqualTo(property, value); + } + + public static WeekendSqls andGreaterThanOrEqualTo(Fn fn, Object value) { + return WeekendSqls.custom().andGreaterThanOrEqualTo(fn, value); + } + + public static WeekendSqls andLessThan(String property, Object value) { + return WeekendSqls.custom().andLessThan(property, value); + } + + public static WeekendSqls andLessThan(Fn fn, Object value) { + return WeekendSqls.custom().andLessThan(fn, value); + } + + public static WeekendSqls andLessThanOrEqualTo(String property, Object value) { + return WeekendSqls.custom().andLessThanOrEqualTo(property, value); + } + + public static WeekendSqls andLessThanOrEqualTo(Fn fn, Object value) { + return WeekendSqls.custom().andLessThanOrEqualTo(fn, value); + } + + public static WeekendSqls andIn(String property, Iterable values) { + return WeekendSqls.custom().andIn(property, values); + } + + public static WeekendSqls andIn(Fn fn, Iterable values) { + return WeekendSqls.custom().andIn(fn, values); + } + + public static WeekendSqls andNotIn(String property, Iterable values) { + return WeekendSqls.custom().andNotIn(property, values); + } + + public static WeekendSqls andNotIn(Fn fn, Iterable values) { + return WeekendSqls.custom().andNotIn(fn, values); + } + + public static WeekendSqls andBetween(String property, Object value1, Object value2) { + return WeekendSqls.custom().andBetween(property, value1, value2); + } + + public static WeekendSqls andBetween(Fn fn, Object value1, Object value2) { + return WeekendSqls.custom().andBetween(fn, value1, value2); + } + + public static WeekendSqls andNotBetween(String property, Object value1, Object value2) { + return WeekendSqls.custom().andNotBetween(property, value1, value2); + } + + public static WeekendSqls andNotBetween(Fn fn, Object value1, Object value2) { + return WeekendSqls.custom().andNotBetween(fn, value1, value2); + } + + public static WeekendSqls andLike(String property, String value) { + return WeekendSqls.custom().andLike(property, value); + } + + public static WeekendSqls andLike(Fn fn, String value) { + return WeekendSqls.custom().andLike(fn, value); + } + + public static WeekendSqls andNotLike(String property, String value) { + return WeekendSqls.custom().andNotLike(property, value); + } + + public static WeekendSqls andNotLike(Fn fn, String value) { + return WeekendSqls.custom().andNotLike(fn ,value); + } + + public static WeekendSqls orIsNull(String property) { + return WeekendSqls.custom().orIsNull(property); + } + + public static WeekendSqls orIsNull(Fn fn) { + return WeekendSqls.custom().orIsNull(fn); + } + + public static WeekendSqls orIsNotNull(String property) { + return WeekendSqls.custom().orIsNotNull(property); + } + + public static WeekendSqls orIsNotNull(Fn fn) { + return WeekendSqls.custom().orIsNotNull(fn); + } + + public static WeekendSqls orEqualTo(String property, Object value) { + return WeekendSqls.custom().orEqualTo(property, value); + } + + public static WeekendSqls orEqualTo(Fn fn, String value) { + return WeekendSqls.custom().orEqualTo(fn, value); + } + + public static WeekendSqls orNotEqualTo(String property, Object value) { + return WeekendSqls.custom().orNotEqualTo(property, value); + } + + public static WeekendSqls orNotEqualTo(Fn fn, String value) { + return WeekendSqls.custom().orNotEqualTo(fn, value); + } + + public static WeekendSqls orGreaterThan(String property, Object value) { + return WeekendSqls.custom().orGreaterThan(property, value); + } + + public static WeekendSqls orGreaterThan(Fn fn, String value) { + return WeekendSqls.custom().orGreaterThan(fn, value); + } + + public static WeekendSqls orGreaterThanOrEqualTo(String property, Object value) { + return WeekendSqls.custom().orGreaterThanOrEqualTo(property, value); + } + + public static WeekendSqls orGreaterThanOrEqualTo(Fn fn, String value) { + return WeekendSqls.custom().orGreaterThanOrEqualTo(fn, value); + } + + public static WeekendSqls orLessThan(String property, Object value) { + return WeekendSqls.custom().orLessThan(property, value); + } + + public static WeekendSqls orLessThan(Fn fn, String value) { + return WeekendSqls.custom().orLessThan(fn, value); + } + + public static WeekendSqls orLessThanOrEqualTo(String property, Object value) { + return WeekendSqls.custom().orLessThanOrEqualTo(property, value); + } + + public static WeekendSqls orLessThanOrEqualTo(Fn fn, String value) { + return WeekendSqls.custom().orLessThanOrEqualTo(fn, value); + } + + public static WeekendSqls orIn(String property, Iterable values) { + return WeekendSqls.custom().orIn(property, values); + } + + public static WeekendSqls orIn(Fn fn, Iterable values) { + return WeekendSqls.custom().orIn(fn, values); + } + + public static WeekendSqls orNotIn(String property, Iterable values) { + return WeekendSqls.custom().orNotIn(property, values); + } + + public static WeekendSqls orNotIn(Fn fn, Iterable values) { + return WeekendSqls.custom().orNotIn(fn, values); + } + + public static WeekendSqls orBetween(String property, Object value1, Object value2) { + return WeekendSqls.custom().orBetween(property, value1, value2); + } + + public static WeekendSqls orBetween(Fn fn, Object value1, Object value2) { + return WeekendSqls.custom().orBetween(fn, value1, value2); + } + + public static WeekendSqls orNotBetween(String property, Object value1, Object value2) { + return WeekendSqls.custom().orNotBetween(property, value1, value2); + } + + public static WeekendSqls orNotBetween(Fn fn, Object value1, Object value2) { + return WeekendSqls.custom().orNotBetween(fn, value1, value2); + } + + public static WeekendSqls orLike(String property, String value) { + return WeekendSqls.custom().orLike(property, value); + } + + public static WeekendSqls orLike(Fn fn, String value) { + return WeekendSqls.custom().orLike(fn, value); + } + + public static WeekendSqls orNotLike(String property, String value) { + return WeekendSqls.custom().orNotLike(property, value); + } + + public static WeekendSqls orNotLike(Fn fn, String value) { + return WeekendSqls.custom().orNotLike(fn, value); + } + +} diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsUtilsTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsUtilsTest.java new file mode 100644 index 000000000..00775c994 --- /dev/null +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsUtilsTest.java @@ -0,0 +1,92 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014-2017 the original author or authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package tk.mybatis.mapper.weekend; + +import org.apache.ibatis.session.SqlSession; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import tk.mybatis.mapper.entity.Example; +import tk.mybatis.mapper.util.Sqls; +import tk.mybatis.mapper.weekend.entity.Country; +import tk.mybatis.mapper.weekend.mapper.CountryMapper; + +import java.util.List; + +import static tk.mybatis.mapper.weekend.WeekendSqlsUtils.andLike; + +/** + * @author linweichao + * @date 2019/5/20 + */ +public class WeekendSqlsUtilsTest { + + @Rule + public TestRule runJava8 = new UseJava8Rule(); + + @Test + public void testWeekend() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); + + List selectByWeekendSql = mapper.selectByExample(new Example.Builder(Country.class) + .where(andLike(Country::getCountryname, "China")).build()); + + List selectByExample = mapper.selectByExample( + new Example.Builder(Country.class).where(Sqls.custom().andLike("countryname", "China")).build()); + + //判断两个结果数组内容是否相同 + Assert.assertArrayEquals(selectByExample.toArray(), selectByWeekendSql.toArray()); + } finally { + sqlSession.close(); + } + } + + @Test + public void testWeekendComplex() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); + + List selectByWeekendSql = mapper.selectByExample(new Example.Builder(Country.class) + .where(andLike(Country::getCountryname, "%a%") + .andGreaterThan(Country::getCountrycode, "123")) + .build()); + + + List selectByExample = mapper.selectByExample(new Example.Builder(Country.class) + .where(Sqls.custom().andLike("countryname", "%a%").andGreaterThan("countrycode", "123")).build()); + + // 判断两个结果数组内容是否相同 + Assert.assertArrayEquals(selectByExample.toArray(), selectByWeekendSql.toArray()); + } finally { + sqlSession.close(); + } + } + +} From b17d4f04b7b778ebb45055262ec0edf4b58dbee0 Mon Sep 17 00:00:00 2001 From: linweichao <934971538@qq.com> Date: Mon, 20 May 2019 20:58:17 +0800 Subject: [PATCH 053/109] =?UTF-8?q?=E4=BF=AE=E6=94=B9WeekendSqlsUtils?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java index e87305153..62dd274f1 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java @@ -28,13 +28,13 @@ /** * {@link WeekendSqls} 的工具类,提供一系列静态方法,减少泛型参数的指定,使代码更简洁、清晰 * - * 直接使用WeekSqls,以下的查询需要指定两次泛型参数: + * 直接使用WeekSqls,以下的查询需要指定两次Country类: * List selectByWeekendSql = mapper.selectByExample(new Example.Builder(Country.class) * .where(WeekendSqls.custom().andLike(Country::getCountryname, "%a%") * .andGreaterThan(Country::getCountrycode, "123")) * .build()); * - * 使用 WeekendSqlsUtils,只需指定一次泛型参数: + * 使用 WeekendSqlsUtils,只需指定一次Country类: * List selectByWeekendSql = mapper.selectByExample(new Example.Builder(Country.class) * .where(WeekendSqlsUtils.andLike(Country::getCountryname, "%a%") * .andGreaterThan(Country::getCountrycode, "123")) From 89916963a30c56b9d48aa25c3886bf122f6e6a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=81=E7=8E=89?= <924120316@qq.com> Date: Sat, 29 Dec 2018 15:32:58 +0800 Subject: [PATCH 054/109] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86SelectByPrim?= =?UTF-8?q?aryKeyMapper=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这个地方如果不为Entity的主键字段加上注解很容易出现错误,tkMapper无法识别哪个字段是主键,用Entity中的每个字段都去匹配。 --- .../mapper/common/base/select/SelectByPrimaryKeyMapper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base/src/main/java/tk/mybatis/mapper/common/base/select/SelectByPrimaryKeyMapper.java b/base/src/main/java/tk/mybatis/mapper/common/base/select/SelectByPrimaryKeyMapper.java index 9e1af6582..08d8cdcdc 100644 --- a/base/src/main/java/tk/mybatis/mapper/common/base/select/SelectByPrimaryKeyMapper.java +++ b/base/src/main/java/tk/mybatis/mapper/common/base/select/SelectByPrimaryKeyMapper.java @@ -30,6 +30,8 @@ /** * 通用Mapper接口,其他接口继承该接口即可 + * 需要在Entity类中为主键字段加上@javax.persistence.Id注解,声明主键 + * 否则无法确认实体类哪个属性是主键 *

*

这是一个例子,自己扩展时可以参考

*

@@ -50,4 +52,4 @@ public interface SelectByPrimaryKeyMapper { @SelectProvider(type = BaseSelectProvider.class, method = "dynamicSQL") T selectByPrimaryKey(Object key); -} \ No newline at end of file +} From 7c042b601b791477326c19be6211b92f18aaaee9 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 15:27:12 +0800 Subject: [PATCH 055/109] =?UTF-8?q?=E5=8E=BB=E6=8E=89=20#386=20=E7=9A=84?= =?UTF-8?q?=E4=B8=A4=E4=B8=AATODO=EF=BC=8C=E6=89=B9=E9=87=8F=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E4=B8=8D=E8=80=83=E8=99=91=E4=B9=90=E8=A7=82=E9=94=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/provider/ExampleProvider.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java b/base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java index 420d9b20c..dcd4dbca8 100644 --- a/base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java +++ b/base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java @@ -144,11 +144,6 @@ public String updateByExampleSelective(MappedStatement ms) { sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass), "example")); sql.append(SqlHelper.updateSetColumnsIgnoreVersion(entityClass, "record", true, isNotEmpty())); sql.append(SqlHelper.updateByExampleWhereClause()); - //TODO 加入乐观锁查询条件 - //乐观锁条件,加在example后面,有两个问题 - // 1.会和example的条件混在一起,导致or和and逻辑混乱 - // 2.如果example为空,会缺少WHERE - //sql.append(SqlHelper.whereVersion(entityClass, "record")); return sql.toString(); } @@ -171,11 +166,6 @@ public String updateByExample(MappedStatement ms) { sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass), "example")); sql.append(SqlHelper.updateSetColumnsIgnoreVersion(entityClass, "record", false, false)); sql.append(SqlHelper.updateByExampleWhereClause()); - //TODO 加入乐观锁查询条件 - //乐观锁条件,加在example后面,有两个问题 - // 1.会和example的条件混在一起,导致or和and逻辑混乱 - // 2.如果example为空,会缺少WHERE - //sql.append(SqlHelper.whereVersion(entityClass, "record")); return sql.toString(); } From ac0d4ecd1cc5f6d50ac2258f4682efbc33e9e4ff Mon Sep 17 00:00:00 2001 From: korov9 Date: Sat, 29 May 2021 16:47:41 +0800 Subject: [PATCH 056/109] =?UTF-8?q?fix:=E4=BD=BF=E7=94=A8Example.buidler?= =?UTF-8?q?=E5=88=9B=E5=BB=BAExample=E6=97=B6=E4=BD=BF=E7=94=A8orderBy?= =?UTF-8?q?=E6=8A=A5NullPointerException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/tk/mybatis/mapper/entity/Example.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/tk/mybatis/mapper/entity/Example.java b/core/src/main/java/tk/mybatis/mapper/entity/Example.java index 982464db3..c9c635fc8 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/Example.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/Example.java @@ -118,6 +118,7 @@ private Example(Builder builder) { this.oredCriteria = builder.exampleCriterias; this.forUpdate = builder.forUpdate; this.tableName = builder.tableName; + this.ORDERBY = new OrderBy(this, propertyMap); if (!StringUtil.isEmpty(builder.orderByClause.toString())) { this.orderByClause = builder.orderByClause.toString(); From 4501fdbab890d3110aafbf9214a86958750725a2 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 16:50:51 +0800 Subject: [PATCH 057/109] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20virtual=20?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97,=20fixed=20#272?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java b/core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java index 7559203b2..fc9179aa4 100644 --- a/core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java +++ b/core/src/main/java/tk/mybatis/mapper/util/SqlReservedWords.java @@ -932,6 +932,7 @@ public class SqlReservedWords { "VCAT", // DB2 //$NON-NLS-1$ "VERBOSE", //$NON-NLS-1$ "VIEW", // DB2 //$NON-NLS-1$ + "VIRTUAL", //MySQL #272 "VOLATILE", //$NON-NLS-1$ "VOLUMES", // DB2 //$NON-NLS-1$ "WAITFOR", //$NON-NLS-1$ From 612504e85a2a31cfbdeb36a8b135a51144015a92 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 18:50:28 +0800 Subject: [PATCH 058/109] =?UTF-8?q?=E6=89=80=E6=9C=89=20class.getCanonical?= =?UTF-8?q?Name=20=E6=94=B9=E4=B8=BA=20class.getName=20fixed=20gitee#I1B8K?= =?UTF-8?q?L?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/provider/IdsProvider.java | 4 ++-- .../tk/mybatis/mapper/provider/SaveProvider.java | 4 ++-- .../mapper/provider/base/BaseInsertProvider.java | 4 ++-- .../tk/mybatis/mapper/entity/EntityColumn.java | 4 ++-- .../mybatis/mapper/mapperhelper/EntityHelper.java | 2 +- .../mybatis/mapper/mapperhelper/MapperHelper.java | 10 +++++----- .../tk/mybatis/mapper/mapperhelper/SqlHelper.java | 14 +++++++------- .../mapperhelper/resolve/DefaultEntityResolve.java | 2 +- .../src/main/java/tk/mybatis/mapper/util/OGNL.java | 6 +++--- .../aggregation/AggregationProvider.java | 4 ++-- .../additional/dialect/oracle/OracleProvider.java | 2 +- .../mapper/additional/idlist/IdListProvider.java | 2 +- .../additional/insert/InsertListProvider.java | 2 +- .../update/differ/UpdateByDifferProvider.java | 6 +++--- .../UpdateByPrimaryKeySelectiveForceProvider.java | 4 ++-- .../tk/mybatis/mapper/generator/MapperPlugin.java | 2 +- .../mapper/autoconfigure/MapperCacheDisabler.java | 4 ++-- 17 files changed, 38 insertions(+), 38 deletions(-) diff --git a/base/src/main/java/tk/mybatis/mapper/provider/IdsProvider.java b/base/src/main/java/tk/mybatis/mapper/provider/IdsProvider.java index 335368b98..f9b28d333 100644 --- a/base/src/main/java/tk/mybatis/mapper/provider/IdsProvider.java +++ b/base/src/main/java/tk/mybatis/mapper/provider/IdsProvider.java @@ -64,7 +64,7 @@ public String deleteByIds(MappedStatement ms) { sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { - throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); + throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); } @@ -89,7 +89,7 @@ public String selectByIds(MappedStatement ms) { sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { - throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); + throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); } diff --git a/base/src/main/java/tk/mybatis/mapper/provider/SaveProvider.java b/base/src/main/java/tk/mybatis/mapper/provider/SaveProvider.java index 9438d2346..32acd7ea3 100644 --- a/base/src/main/java/tk/mybatis/mapper/provider/SaveProvider.java +++ b/base/src/main/java/tk/mybatis/mapper/provider/SaveProvider.java @@ -111,7 +111,7 @@ private void processKey(StringBuilder sql, Class entityClass, MappedStatement if (column.getGenerator() != null && column.getGenerator().equals("JDBC")) { continue; } - throw new MapperException(ms.getId() + "对应的实体类" + entityClass.getCanonicalName() + "中包含多个MySql的自动增长列,最多只能有一个!"); + throw new MapperException(ms.getId() + "对应的实体类" + entityClass.getName() + "中包含多个MySql的自动增长列,最多只能有一个!"); } //插入selectKey SelectKeyHelper.newSelectKeyMappedStatement(ms, column, entityClass, isBEFORE(), getIDENTITY(column)); @@ -119,7 +119,7 @@ private void processKey(StringBuilder sql, Class entityClass, MappedStatement } else if(column.getGenIdClass() != null){ sql.append(""); diff --git a/base/src/main/java/tk/mybatis/mapper/provider/base/BaseInsertProvider.java b/base/src/main/java/tk/mybatis/mapper/provider/base/BaseInsertProvider.java index 7d42856a2..af00190fe 100644 --- a/base/src/main/java/tk/mybatis/mapper/provider/base/BaseInsertProvider.java +++ b/base/src/main/java/tk/mybatis/mapper/provider/base/BaseInsertProvider.java @@ -148,7 +148,7 @@ private void processKey(StringBuilder sql, Class entityClass, MappedStatement if (column.getGenerator() != null && "JDBC".equals(column.getGenerator())) { continue; } - throw new MapperException(ms.getId() + "对应的实体类" + entityClass.getCanonicalName() + "中包含多个MySql的自动增长列,最多只能有一个!"); + throw new MapperException(ms.getId() + "对应的实体类" + entityClass.getName() + "中包含多个MySql的自动增长列,最多只能有一个!"); } //插入selectKey SelectKeyHelper.newSelectKeyMappedStatement(ms, column, entityClass, isBEFORE(), getIDENTITY(column)); @@ -156,7 +156,7 @@ private void processKey(StringBuilder sql, Class entityClass, MappedStatement } else if (column.getGenIdClass() != null) { sql.append(""); diff --git a/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java b/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java index bc36f13f8..4e1401157 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java @@ -140,13 +140,13 @@ public String getColumnHolder(String entityName, String suffix, String separator //为了以后定制类型处理方式,你也可以指定一个特殊的类型处理器类,例如枚举 if (this.typeHandler != null) { sb.append(", typeHandler="); - sb.append(this.typeHandler.getCanonicalName()); + sb.append(this.typeHandler.getName()); } //3.4.0 以前的 mybatis 无法获取父类中泛型的 javaType,所以如果使用低版本,就需要设置 useJavaType = true //useJavaType 默认 false,没有 javaType 限制时,对 ByPrimaryKey 方法的参数校验就放宽了,会自动转型 if (useJavaType && !this.javaType.isArray()) {//当类型为数组时,不设置javaType#103 sb.append(", javaType="); - sb.append(javaType.getCanonicalName()); + sb.append(javaType.getName()); } sb.append("}"); if (StringUtil.isNotEmpty(separator)) { diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/EntityHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/EntityHelper.java index 35369f10e..b345bbe76 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/EntityHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/EntityHelper.java @@ -66,7 +66,7 @@ public class EntityHelper { public static EntityTable getEntityTable(Class entityClass) { EntityTable entityTable = entityTableMap.get(entityClass); if (entityTable == null) { - throw new MapperException("无法获取实体类" + entityClass.getCanonicalName() + "对应的表名!"); + throw new MapperException("无法获取实体类" + entityClass.getName() + "对应的表名!"); } return entityTable; } diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java index 5340f49ec..800aad6aa 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java @@ -140,8 +140,8 @@ private MapperTemplate fromMapperClass(Class mapperClass) { try { mapperTemplate.addMethodMap(methodName, templateClass.getMethod(methodName, MappedStatement.class)); } catch (NoSuchMethodException e) { - log.error(templateClass.getCanonicalName() + "中缺少" + methodName + "方法!", e); - throw new MapperException(templateClass.getCanonicalName() + "中缺少" + methodName + "方法!"); + log.error(templateClass.getName() + "中缺少" + methodName + "方法!", e); + throw new MapperException(templateClass.getName() + "中缺少" + methodName + "方法!"); } } return mapperTemplate; @@ -281,7 +281,7 @@ public void processConfiguration(Configuration configuration) { public void processConfiguration(Configuration configuration, Class mapperInterface) { String prefix; if (mapperInterface != null) { - prefix = mapperInterface.getCanonicalName(); + prefix = mapperInterface.getName(); } else { prefix = ""; } @@ -327,9 +327,9 @@ public void setConfig(Config config) { try { EntityHelper.setResolve(config.getResolveClass().newInstance()); } catch (Exception e) { - log.error("创建 " + config.getResolveClass().getCanonicalName() + log.error("创建 " + config.getResolveClass().getName() + " 实例失败,请保证该类有默认的构造方法!", e); - throw new MapperException("创建 " + config.getResolveClass().getCanonicalName() + throw new MapperException("创建 " + config.getResolveClass().getName() + " 实例失败,请保证该类有默认的构造方法!", e); } } diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java index 3ed1e5a3f..949a44042 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java @@ -476,20 +476,20 @@ public static String updateSetColumns(Class entityClass, String entityName, b for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(Version.class)) { if (versionColumn != null) { - throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); + throw new VersionException(entityClass.getName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); } versionColumn = column; } if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) { if (logicDeleteColumn != null) { - throw new LogicDeleteException(entityClass.getCanonicalName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!"); + throw new LogicDeleteException(entityClass.getName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!"); } logicDeleteColumn = column; } if (!column.isId() && column.isUpdatable()) { if (column == versionColumn) { Version version = versionColumn.getEntityField().getAnnotation(Version.class); - String versionClass = version.nextVersion().getCanonicalName(); + String versionClass = version.nextVersion().getName(); sql.append(" entityClass, String for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) { if (logicDeleteColumn != null) { - throw new LogicDeleteException(entityClass.getCanonicalName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!"); + throw new LogicDeleteException(entityClass.getName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!"); } logicDeleteColumn = column; } @@ -716,7 +716,7 @@ public static String whereVersion(Class entityClass,String entityName) { for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(Version.class)) { if (hasVersion) { - throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); + throw new VersionException(entityClass.getName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); } hasVersion = true; result = " AND " + column.getColumnEqualsHolder(entityName); @@ -822,7 +822,7 @@ public static EntityColumn getLogicDeleteColumn(Class entityClass) { for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) { if (hasLogicDelete) { - throw new LogicDeleteException(entityClass.getCanonicalName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!"); + throw new LogicDeleteException(entityClass.getName() + " 中包含多个带有 @LogicDelete 注解的字段,一个类中只能存在一个带有 @LogicDelete 注解的字段!"); } hasLogicDelete = true; logicDeleteColumn = column; @@ -945,7 +945,7 @@ public static String exampleForUpdate() { public static String exampleCheck(Class entityClass) { StringBuilder sql = new StringBuilder(); sql.append(""); return sql.toString(); } diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java index 1b1c534b3..7097f6394 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java @@ -286,7 +286,7 @@ protected void processKeySql(EntityTable entityTable, EntityColumn entityColumn, entityColumn.setIdentity(false); entityColumn.setGenIdClass(keySql.genId()); } else { - throw new MapperException(entityTable.getEntityClass().getCanonicalName() + throw new MapperException(entityTable.getEntityClass().getName() + " 类中的 @KeySql 注解配置无效!"); } } diff --git a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java index 9b10c247c..a5e4a8959 100644 --- a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java +++ b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java @@ -55,9 +55,9 @@ public static boolean checkExampleEntityClass(Object parameter, String entityFul if (parameter != null && parameter instanceof Example && StringUtil.isNotEmpty(entityFullName)) { Example example = (Example) parameter; Class entityClass = example.getEntityClass(); - if (!entityClass.getCanonicalName().equals(entityFullName)) { + if (!entityClass.getName().equals(entityFullName)) { throw new MapperException("当前 Example 方法对应实体为:" + entityFullName - + ", 但是参数 Example 中的 entityClass 为:" + entityClass.getCanonicalName()); + + ", 但是参数 Example 中的 entityClass 为:" + entityClass.getName()); } } return true; @@ -220,7 +220,7 @@ public static String andOr(Object parameter) { return ((Example.Criteria) parameter).getAndOr(); } else if (parameter instanceof Example.Criterion) { return ((Example.Criterion) parameter).getAndOr(); - } else if (parameter.getClass().getCanonicalName().endsWith("Criteria")) { + } else if (parameter.getClass().getName().endsWith("Criteria")) { return "or"; } else { return "and"; diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/aggregation/AggregationProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/aggregation/AggregationProvider.java index 4b1086826..9175ca1c5 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/aggregation/AggregationProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/aggregation/AggregationProvider.java @@ -87,14 +87,14 @@ public String selectAggregationByExample(MappedStatement ms) { sql.append(SqlHelper.exampleCheck(entityClass)); } sql.append("SELECT ${@tk.mybatis.mapper.additional.aggregation.AggregationProvider@aggregationSelectClause("); - sql.append("@").append(entityClass.getCanonicalName()).append("@class"); + sql.append("@").append(entityClass.getName()).append("@class"); sql.append(", '").append(getConfig().getWrapKeyword()).append("'"); sql.append(", aggregateCondition"); sql.append(")} "); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); sql.append(SqlHelper.updateByExampleWhereClause()); sql.append(" ${@tk.mybatis.mapper.additional.aggregation.AggregationProvider@aggregationGroupBy("); - sql.append("@").append(entityClass.getCanonicalName()).append("@class"); + sql.append("@").append(entityClass.getName()).append("@class"); sql.append(", '").append(getConfig().getWrapKeyword()).append("'"); sql.append(", aggregateCondition"); sql.append(")} "); diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/OracleProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/OracleProvider.java index 951ba369a..9c881d317 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/OracleProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/dialect/oracle/OracleProvider.java @@ -59,7 +59,7 @@ public String insertList(MappedStatement ms) { if (column.getGenIdClass() != null) { sql.append(""); diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/idlist/IdListProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/idlist/IdListProvider.java index cef7c0d0d..b48ef470c 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/idlist/IdListProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/idlist/IdListProvider.java @@ -114,7 +114,7 @@ private void appendWhereIdList(StringBuilder sql, Class entityClass, boolean sql.append(""); sql.append(""); } else { - throw new MapperException("继承 ByIdList 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); + throw new MapperException("继承 ByIdList 方法的实体类[" + entityClass.getName() + "]中必须只有一个带有 @Id 注解的字段"); } } } diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/insert/InsertListProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/insert/InsertListProvider.java index 9341cffab..03976ae0a 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/insert/InsertListProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/insert/InsertListProvider.java @@ -64,7 +64,7 @@ public String insertList(MappedStatement ms) { if (column.getGenIdClass() != null) { sql.append(""); diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java index e58955126..104b3937f 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/differ/UpdateByDifferProvider.java @@ -96,7 +96,7 @@ public String whereVersion(Class entityClass) { for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(Version.class)) { if (hasVersion) { - throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); + throw new VersionException(entityClass.getName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); } hasVersion = true; result = " AND " + column.getColumnEqualsHolder(NEWER); @@ -122,14 +122,14 @@ public String updateSetColumnsByDiffer(Class entityClass) { for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(Version.class)) { if (versionColumn != null) { - throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); + throw new VersionException(entityClass.getName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); } versionColumn = column; } if (!column.isId() && column.isUpdatable()) { if (column == versionColumn) { Version version = versionColumn.getEntityField().getAnnotation(Version.class); - String versionClass = version.nextVersion().getCanonicalName(); + String versionClass = version.nextVersion().getName(); //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)} sql.append(column.getColumn()) .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java index ec658ba7e..8e4ee24ac 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/force/UpdateByPrimaryKeySelectiveForceProvider.java @@ -80,14 +80,14 @@ public String updateSetColumnsForce(Class entityClass, String entityName, boo for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(Version.class)) { if (versionColumn != null) { - throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); + throw new VersionException(entityClass.getName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); } versionColumn = column; } if (!column.isId() && column.isUpdatable()) { if (column == versionColumn) { Version version = versionColumn.getEntityField().getAnnotation(Version.class); - String versionClass = version.nextVersion().getCanonicalName(); + String versionClass = version.nextVersion().getName(); //version = ${@tk.mybatis.mapper.version@nextVersionClass("versionClass", version)} sql.append(column.getColumn()) .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(") diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index f6a84d21c..5cde8edff 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -396,7 +396,7 @@ public void setContext(Context context) { useMapperCommentGenerator = !"FALSE".equalsIgnoreCase(context.getProperty("useMapperCommentGenerator")); if (useMapperCommentGenerator) { commentCfg = new CommentGeneratorConfiguration(); - commentCfg.setConfigurationType(MapperCommentGenerator.class.getCanonicalName()); + commentCfg.setConfigurationType(MapperCommentGenerator.class.getName()); context.setCommentGeneratorConfiguration(commentCfg); } diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java index e2881a5b2..4f27bd970 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperCacheDisabler.java @@ -57,10 +57,10 @@ private void removeStaticCache(Class utilClass, String fieldName) { throw new UnsupportedOperationException("cache field must be a java.util.Map " + "or org.apache.ibatis.cache.Cache instance"); } - logger.info("Clear " + utilClass.getCanonicalName() + " " + fieldName + " cache."); + logger.info("Clear " + utilClass.getName() + " " + fieldName + " cache."); } } catch (Exception ex) { - logger.warn("Failed to disable " + utilClass.getCanonicalName() + " " + logger.warn("Failed to disable " + utilClass.getName() + " " + fieldName + " cache. ClassCastExceptions may occur", ex); } } From 4f5fd4f0edf78274bf8288e12c08c8e6d015a9f6 Mon Sep 17 00:00:00 2001 From: Nonlone Date: Mon, 4 Nov 2019 14:28:34 +0800 Subject: [PATCH 059/109] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8DWeekendSql?= =?UTF-8?q?=E4=B8=8Bor=E6=93=8D=E4=BD=9Cvalue=E4=B8=BAString=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/tk/mybatis/mapper/weekend/WeekendSqls.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java index 7ecbe4c5d..9684d520f 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java @@ -278,21 +278,21 @@ public WeekendSqls orNotBetween(Fn fn, Object value1, Object value return this.orNotBetween(Reflections.fnToFieldName(fn), value1, value2); } - public WeekendSqls orLike(String property, String value) { + public WeekendSqls orLike(String property, Object value) { this.criteria.getCriterions().add(new Criterion(property, value, "like", "or")); return this; } - public WeekendSqls orLike(Fn fn, String value) { + public WeekendSqls orLike(Fn fn, Object value) { return this.orLike(Reflections.fnToFieldName(fn), value); } - public WeekendSqls orNotLike(String property, String value) { + public WeekendSqls orNotLike(String property, Object value) { this.criteria.getCriterions().add(new Criterion(property, value, "not like", "or")); return this; } - public WeekendSqls orNotLike(Fn fn, String value) { + public WeekendSqls orNotLike(Fn fn, Object value) { return this.orNotLike(Reflections.fnToFieldName(fn), value); } From 1a99fe60630aabeedcf0c23a065973040da653c2 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 19:43:11 +0800 Subject: [PATCH 060/109] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20pr#685=20=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java index 9684d520f..0e31b464f 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqls.java @@ -278,12 +278,12 @@ public WeekendSqls orNotBetween(Fn fn, Object value1, Object value return this.orNotBetween(Reflections.fnToFieldName(fn), value1, value2); } - public WeekendSqls orLike(String property, Object value) { + public WeekendSqls orLike(String property, String value) { this.criteria.getCriterions().add(new Criterion(property, value, "like", "or")); return this; } - public WeekendSqls orLike(Fn fn, Object value) { + public WeekendSqls orLike(Fn fn, String value) { return this.orLike(Reflections.fnToFieldName(fn), value); } From 433edf28619895243ec3815a28d57cde143e2a7b Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 20:13:08 +0800 Subject: [PATCH 061/109] =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E9=94=99=E8=AF=AF,=20fixed=20#515?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index 5cde8edff..2f2bfcc7c 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -242,7 +242,7 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i field.setStatic(true); field.setFinal(true); field.setInitializationString("\"" + introspectedColumn.getJavaProperty() + "\""); - context.getCommentGenerator().addClassComment(topLevelClass, introspectedTable); + context.getCommentGenerator().addFieldComment(field, introspectedTable, introspectedColumn); topLevelClass.addField(field); //增加字段名常量,用于pageHelper String columnFieldName = "DB_" + introspectedColumn.getActualColumnName().toUpperCase(); //$NON-NLS-1$ From 2fcefe65e1e77db1e53edb33290cd0e347ecaec8 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 20:22:17 +0800 Subject: [PATCH 062/109] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20class.getCanonical?= =?UTF-8?q?Name=20=E6=94=B9=E4=B8=BA=20class.getName=20=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java index 5d07777cd..1ecd948f0 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java @@ -156,7 +156,7 @@ public void test() { "" + " AND id = #{id}" + " AND user_name = #{userName}" + - " AND address = #{address, typeHandler=tk.mybatis.mapper.mapperhelper.ComplexEntityTest.AddressHandler}" + + " AND address = #{address, typeHandler=tk.mybatis.mapper.mapperhelper.ComplexEntityTest$AddressHandler}" + " AND state = #{state}", sql); final ResultMap resultMap = entityTable.getResultMap(configuration); From db8d4b8b288a07f601f2ddca2962cad7e0c470d8 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 20:40:02 +0800 Subject: [PATCH 063/109] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E6=9C=80=E4=BD=8E=E6=94=AF=E6=8C=81?= =?UTF-8?q?jdk6,=20extra=20=E5=92=8C=20weekend=20=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=9C=80=E8=A6=81=20jdk8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/pom.xml | 5 +++++ pom.xml | 6 +++--- spring/pom.xml | 4 ++-- weekend/pom.xml | 5 +++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/extra/pom.xml b/extra/pom.xml index 4be2443f9..f95bf743b 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -36,6 +36,11 @@ mapper-extra Mybatis 通用 Mapper 扩展方法 + + 8 + 8 + + org.mybatis diff --git a/pom.xml b/pom.xml index 5cd233647..91e57b79f 100644 --- a/pom.xml +++ b/pom.xml @@ -36,15 +36,15 @@ 4.2.2-SNAPSHOT - 8 - 8 + 1.6 + 1.6 UTF-8 UTF-8 -Dfile.encoding=UTF-8 2.2 1.7.26 - 3.5.9 + 3.5.11 4.13.2 2.5.2 diff --git a/spring/pom.xml b/spring/pom.xml index e68ae59e5..a5389039f 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -37,8 +37,8 @@ Mybatis 通用 Mapper 和 Spring 集成 - 4.3.8.RELEASE - 1.3.2 + 4.3.30.RELEASE + 1.3.3 diff --git a/weekend/pom.xml b/weekend/pom.xml index 8aa0b3a8f..d29e496cf 100644 --- a/weekend/pom.xml +++ b/weekend/pom.xml @@ -51,6 +51,11 @@ + + 8 + 8 + + org.mybatis From 749deee33ae897fe77e796c8d1a62cd5c220a5d1 Mon Sep 17 00:00:00 2001 From: ZhaoPengfei Date: Sun, 16 Oct 2022 20:49:34 +0800 Subject: [PATCH 064/109] =?UTF-8?q?pr#711=20=E4=BF=AE=E8=AE=A2=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=8F=92=E5=85=A5=EF=BC=8C=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=80=BB=E8=BE=91=E5=88=A0=E9=99=A4=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=EF=BC=9B=E6=89=A9=E5=B1=95=E6=94=AF=E6=8C=81=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=9B=B4=E6=96=B0=EF=BC=9B=E6=94=AF=E6=8C=81PostgreSQ?= =?UTF-8?q?L=20UPSERT=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../additional/insert/InsertListProvider.java | 11 +++- .../update/batch/BatchUpdateMapper.java | 17 +++++ .../update/batch/BatchUpdateProvider.java | 35 ++++++++++ .../batch/BatchUpdateSelectiveMapper.java | 17 +++++ .../additional/upsert/BatchUpsertMapper.java | 17 +++++ .../upsert/BatchUpsertProvider.java | 65 +++++++++++++++++++ .../additional/upsert/UpsertMapper.java | 12 ++++ .../additional/upsert/UpsertProvider.java | 63 ++++++++++++++++++ 8 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateMapper.java create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateProvider.java create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateSelectiveMapper.java create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/upsert/BatchUpsertMapper.java create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/upsert/BatchUpsertProvider.java create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java create mode 100644 extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertProvider.java diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/insert/InsertListProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/insert/InsertListProvider.java index 03976ae0a..95631118b 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/insert/InsertListProvider.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/insert/InsertListProvider.java @@ -59,6 +59,8 @@ public String insertList(MappedStatement ms) { sql.append(""); //获取全部列 Set columnList = EntityHelper.getColumns(entityClass); + //获取逻辑删除列 + EntityColumn logicDeleteColumn = SqlHelper.getLogicDeleteColumn(entityClass); //单独增加对 genId 方式的支持 for (EntityColumn column : columnList) { if (column.getGenIdClass() != null) { @@ -72,9 +74,14 @@ public String insertList(MappedStatement ms) { } //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值 for (EntityColumn column : columnList) { - if (column.isInsertable()) { - sql.append(column.getColumnHolder("record") + ","); + if (!column.isInsertable()) { + continue; } + if (logicDeleteColumn != null && logicDeleteColumn == column) { + sql.append(SqlHelper.getLogicDeletedValue(column, false)).append(","); + continue; + } + sql.append(column.getColumnHolder("record") + ","); } sql.append(""); sql.append(""); diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateMapper.java new file mode 100644 index 000000000..cae84786f --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateMapper.java @@ -0,0 +1,17 @@ +package tk.mybatis.mapper.additional.update.batch; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.UpdateProvider; +import tk.mybatis.mapper.annotation.RegisterMapper; + +import java.util.List; + +@RegisterMapper +public interface BatchUpdateMapper { + + @UpdateProvider( + type = BatchUpdateProvider.class, + method = "dynamicSQL" + ) + void batchUpdate(@Param("list") List recordList); +} diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateProvider.java new file mode 100644 index 000000000..892affe66 --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateProvider.java @@ -0,0 +1,35 @@ +package tk.mybatis.mapper.additional.update.batch; + +import org.apache.ibatis.mapping.MappedStatement; +import tk.mybatis.mapper.mapperhelper.MapperHelper; +import tk.mybatis.mapper.mapperhelper.MapperTemplate; +import tk.mybatis.mapper.mapperhelper.SqlHelper; + +public class BatchUpdateProvider extends MapperTemplate { + + public BatchUpdateProvider(Class mapperClass, MapperHelper mapperHelper) { + super(mapperClass, mapperHelper); + } + + public String batchUpdate(MappedStatement ms) { + final Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + sql.append(""); + sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass))); + sql.append(SqlHelper.updateSetColumns(entityClass, "record", false, false)); + sql.append(SqlHelper.wherePKColumns(entityClass, "record", true)); + sql.append(""); + return sql.toString(); + } + + public String batchUpdateSelective(MappedStatement ms) { + final Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + sql.append(""); + sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass))); + sql.append(SqlHelper.updateSetColumns(entityClass, "record", true, isNotEmpty())); + sql.append(SqlHelper.wherePKColumns(entityClass, "record", true)); + sql.append(""); + return sql.toString(); + } +} diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateSelectiveMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateSelectiveMapper.java new file mode 100644 index 000000000..712ed186f --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/update/batch/BatchUpdateSelectiveMapper.java @@ -0,0 +1,17 @@ +package tk.mybatis.mapper.additional.update.batch; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.UpdateProvider; +import tk.mybatis.mapper.annotation.RegisterMapper; + +import java.util.List; + +@RegisterMapper +public interface BatchUpdateSelectiveMapper { + + @UpdateProvider( + type = BatchUpdateProvider.class, + method = "dynamicSQL" + ) + void batchUpdateSelective(@Param("list") List recordList); +} diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/upsert/BatchUpsertMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/BatchUpsertMapper.java new file mode 100644 index 000000000..f4381e9d4 --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/BatchUpsertMapper.java @@ -0,0 +1,17 @@ +package tk.mybatis.mapper.additional.upsert; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.UpdateProvider; +import tk.mybatis.mapper.annotation.RegisterMapper; + +import java.util.List; + +@RegisterMapper +public interface BatchUpsertMapper { + + @UpdateProvider( + type = BatchUpsertProvider.class, + method = "dynamicSQL" + ) + void batchUpsert(@Param("list") List recordList); +} diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/upsert/BatchUpsertProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/BatchUpsertProvider.java new file mode 100644 index 000000000..6513e908c --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/BatchUpsertProvider.java @@ -0,0 +1,65 @@ +package tk.mybatis.mapper.additional.upsert; + +import org.apache.ibatis.mapping.MappedStatement; +import tk.mybatis.mapper.entity.EntityColumn; +import tk.mybatis.mapper.mapperhelper.EntityHelper; +import tk.mybatis.mapper.mapperhelper.MapperHelper; +import tk.mybatis.mapper.mapperhelper.MapperTemplate; +import tk.mybatis.mapper.mapperhelper.SqlHelper; + +import java.util.Set; + +public class BatchUpsertProvider extends MapperTemplate { + + public BatchUpsertProvider(Class mapperClass, MapperHelper mapperHelper) { + super(mapperClass, mapperHelper); + } + + public String batchUpsert(MappedStatement ms) { + final Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + sql.append(""); + sql.append("INSERT INTO "); + sql.append(tableName(entityClass)); + Set columns = EntityHelper.getColumns(entityClass); + String primaryKeyColumn = null; + EntityColumn logicDeleteColumn = SqlHelper.getLogicDeleteColumn(entityClass); + sql.append(""); + for (EntityColumn column : columns) { + if (column.isId()) { + primaryKeyColumn = column.getColumn(); + } + if (column.isInsertable()) { + sql.append(column.getColumn() + ","); + } + } + sql.append(""); + sql.append(" VALUES "); + sql.append(""); + for (EntityColumn column : columns) { + if (column.getGenIdClass() != null) { + sql.append(""); + } + } + for (EntityColumn column : columns) { + if (!column.isInsertable()) { + continue; + } + if (logicDeleteColumn != null && logicDeleteColumn == column) { + sql.append(SqlHelper.getLogicDeletedValue(column, false)).append(","); + continue; + } + sql.append(column.getColumnHolder("record") + ","); + } + sql.append(""); + sql.append(" ON CONFLICT (" + primaryKeyColumn + ") DO UPDATE "); + sql.append(SqlHelper.updateSetColumns(entityClass, "record", true, isNotEmpty())); + sql.append(""); + return sql.toString(); + } +} diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java new file mode 100644 index 000000000..66bd8972c --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java @@ -0,0 +1,12 @@ +package tk.mybatis.mapper.additional.upsert; + +import org.apache.ibatis.annotations.UpdateProvider; + +public interface UpsertMapper { + + @UpdateProvider( + type = UpsertProvider.class, + method = "dynamicSQL" + ) + void upsert(T record); +} diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertProvider.java b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertProvider.java new file mode 100644 index 000000000..cd446e10e --- /dev/null +++ b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertProvider.java @@ -0,0 +1,63 @@ +package tk.mybatis.mapper.additional.upsert; + +import org.apache.ibatis.mapping.MappedStatement; +import tk.mybatis.mapper.entity.EntityColumn; +import tk.mybatis.mapper.mapperhelper.EntityHelper; +import tk.mybatis.mapper.mapperhelper.MapperHelper; +import tk.mybatis.mapper.mapperhelper.MapperTemplate; +import tk.mybatis.mapper.mapperhelper.SqlHelper; + +import java.util.Set; + +public class UpsertProvider extends MapperTemplate { + + public UpsertProvider(Class mapperClass, MapperHelper mapperHelper) { + super(mapperClass, mapperHelper); + } + + public String upsert(MappedStatement ms) { + final Class entityClass = getEntityClass(ms); + StringBuilder sql = new StringBuilder(); + sql.append("INSERT INTO "); + sql.append(tableName(entityClass)); + Set columns = EntityHelper.getColumns(entityClass); + String primaryKeyColumn = null; + EntityColumn logicDeleteColumn = SqlHelper.getLogicDeleteColumn(entityClass); + sql.append(""); + for (EntityColumn column : columns) { + if (column.isId()) { + primaryKeyColumn = column.getColumn(); + } + if (column.isInsertable()) { + sql.append(column.getColumn() + ","); + } + } + sql.append(""); + sql.append(" VALUES "); + sql.append(""); + for (EntityColumn column : columns) { + if (column.getGenIdClass() != null) { + sql.append(""); + } + } + for (EntityColumn column : columns) { + if (!column.isInsertable()) { + continue; + } + if (logicDeleteColumn != null && logicDeleteColumn == column) { + sql.append(SqlHelper.getLogicDeletedValue(column, false)).append(","); + continue; + } + sql.append(column.getColumnHolder() + ","); + } + sql.append(""); + sql.append(" ON CONFLICT (" + primaryKeyColumn + ") DO UPDATE "); + sql.append(SqlHelper.updateSetColumns(entityClass, null, true, isNotEmpty())); + return sql.toString(); + } +} From a29b37dc9b9b76290329603aa467d92e16c53978 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 21:09:27 +0800 Subject: [PATCH 065/109] =?UTF-8?q?=E5=8F=91=E5=B8=83=204.2.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 91e57b79f..51c42c9db 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 4.2.2-SNAPSHOT + 4.2.2 1.6 1.6 UTF-8 From 737b3617f580d053736a84e55eef34b2c39293fb Mon Sep 17 00:00:00 2001 From: abel533 Date: Sun, 16 Oct 2022 21:13:12 +0800 Subject: [PATCH 066/109] 4.2.3-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 51c42c9db..904372932 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 4.2.2 + 4.2.3-SNAPSHOT 1.6 1.6 UTF-8 From 1a27d25b8a0c0bcb7e8ab8394a417ae37f6aeb6b Mon Sep 17 00:00:00 2001 From: kesyou1991 <1198985362@qq.com> Date: Sun, 11 Dec 2022 23:57:46 +0800 Subject: [PATCH 067/109] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9Emapper=20bean?= =?UTF-8?q?=E6=87=92=E5=8A=A0=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapperAutoConfiguration.java | 6 +++++ .../mybatis/spring/annotation/MapperScan.java | 7 ++++++ .../annotation/MapperScannerRegistrar.java | 6 +++++ .../spring/mapper/ClassPathMapperScanner.java | 8 +++++++ .../mapper/MapperScannerConfigurer.java | 23 +++++++++++++++++++ 5 files changed, 50 insertions(+) diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java index 2f4631c4c..ad420d889 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java @@ -221,6 +221,12 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B //设置了包名的情况下,不需要指定该注解 scanner.setAnnotationClass(Mapper.class); } + + String lazyInitialization = environment.getProperty("mybatis.lazy-initialization"); + if (StringUtils.hasText(lazyInitialization)) { + scanner.setLazyInitialization(Boolean.valueOf(lazyInitialization)); + } + scanner.registerFilters(); scanner.doScan(StringUtils.toStringArray(packages)); } catch (IllegalStateException ex) { diff --git a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java index 12522df89..0dab98301 100644 --- a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java +++ b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java @@ -150,4 +150,11 @@ * @return */ String mapperHelperRef() default ""; + + /** + * Whether enable lazy initialization of mapper bean. + * Default is {@code false}. + * @return set {@code true} to enable lazy initialization + */ + String lazyInitialization() default ""; } \ No newline at end of file diff --git a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java index 953ff4728..a06bb6a55 100644 --- a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java +++ b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java @@ -107,6 +107,12 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B "如果你使用 tk.mybatis.mapper.session.Configuration 配置的通用 Mapper,你可以忽略该错误!", e); } } + + String lazyInitialization = annoAttrs.getString("lazyInitialization"); + if (StringUtils.hasText(lazyInitialization)) { + scanner.setLazyInitialization(Boolean.valueOf(lazyInitialization)); + } + scanner.registerFilters(); scanner.doScan(StringUtils.toStringArray(basePackages)); } diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java b/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java index 0fb49279f..11279ddb8 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java @@ -62,6 +62,8 @@ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner { private boolean addToConfig = true; + private boolean lazyInitialization; + private SqlSessionFactory sqlSessionFactory; private SqlSessionTemplate sqlSessionTemplate; @@ -207,6 +209,8 @@ private void processBeanDefinitions(Set beanDefinitions) { } definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); } + + definition.setLazyInit(lazyInitialization); } } @@ -249,6 +253,10 @@ public void setAnnotationClass(Class annotationClass) { this.annotationClass = annotationClass; } + public void setLazyInitialization(boolean lazyInitialization) { + this.lazyInitialization = lazyInitialization; + } + /** * 配置通用 Mapper * diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java b/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java index 1a3fda4ab..75c77d2d2 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java @@ -32,12 +32,14 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; import tk.mybatis.mapper.common.Marker; import tk.mybatis.mapper.mapperhelper.MapperHelper; import java.lang.annotation.Annotation; import java.util.Map; +import java.util.Optional; import java.util.Properties; import static org.springframework.util.Assert.notNull; @@ -100,6 +102,8 @@ public class MapperScannerConfigurer implements BeanDefinitionRegistryPostProces private boolean addToConfig = true; + private String lazyInitialization; + private SqlSessionFactory sqlSessionFactory; private SqlSessionTemplate sqlSessionTemplate; @@ -167,6 +171,9 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) { scanner.setSqlSessionTemplateBeanName(this.sqlSessionTemplateBeanName); scanner.setResourceLoader(this.applicationContext); scanner.setBeanNameGenerator(this.nameGenerator); + if (StringUtils.hasText(lazyInitialization)) { + scanner.setLazyInitialization(Boolean.valueOf(lazyInitialization)); + } scanner.registerFilters(); //设置通用 Mapper scanner.setMapperHelper(this.mapperHelper); @@ -202,7 +209,14 @@ private void processPropertyPlaceHolders() { this.basePackage = updatePropertyValue("basePackage", values); this.sqlSessionFactoryBeanName = updatePropertyValue("sqlSessionFactoryBeanName", values); this.sqlSessionTemplateBeanName = updatePropertyValue("sqlSessionTemplateBeanName", values); + this.lazyInitialization = updatePropertyValue("lazyInitialization", values); } + this.lazyInitialization = Optional.ofNullable(this.lazyInitialization).map(getEnvironment()::resolvePlaceholders) + .orElse(null); + } + + private Environment getEnvironment() { + return this.applicationContext.getEnvironment(); } private String updatePropertyValue(String propertyName, PropertyValues values) { @@ -255,6 +269,15 @@ public void setAddToConfig(boolean addToConfig) { this.addToConfig = addToConfig; } + /** + * Set whether enable lazy initialization for mapper bean. + * Default is {@code false}. + * @param lazyInitialization Set the @{code true} to enable + */ + public void setLazyInitialization(String lazyInitialization) { + this.lazyInitialization = lazyInitialization; + } + /** * This property specifies the annotation that the scanner will search for. *

From 7d7987d07b52fcd4992c795a1a51be0f5d637756 Mon Sep 17 00:00:00 2001 From: kesyou1991 Date: Mon, 12 Dec 2022 14:04:38 +0800 Subject: [PATCH 068/109] =?UTF-8?q?fix:=E6=9B=BF=E4=BB=A3Optional=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8Clambda=E8=A1=A8=E8=BE=BE=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9jdk1.6=E4=BD=BF=E7=94=A8=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/spring/mapper/MapperScannerConfigurer.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java b/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java index 75c77d2d2..70970e278 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java @@ -39,7 +39,6 @@ import java.lang.annotation.Annotation; import java.util.Map; -import java.util.Optional; import java.util.Properties; import static org.springframework.util.Assert.notNull; @@ -211,8 +210,7 @@ private void processPropertyPlaceHolders() { this.sqlSessionTemplateBeanName = updatePropertyValue("sqlSessionTemplateBeanName", values); this.lazyInitialization = updatePropertyValue("lazyInitialization", values); } - this.lazyInitialization = Optional.ofNullable(this.lazyInitialization).map(getEnvironment()::resolvePlaceholders) - .orElse(null); + this.lazyInitialization = this.lazyInitialization == null ? null : getEnvironment().resolvePlaceholders(this.lazyInitialization); } private Environment getEnvironment() { From 2e631be0dd2bbc41f3ba5e907c44bfcf943a6535 Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Thu, 29 Dec 2022 09:44:19 +0000 Subject: [PATCH 069/109] update core/src/main/java/tk/mybatis/mapper/util/OGNL.java. paremeter -> parameter Signed-off-by: Ikko Ashimine --- core/src/main/java/tk/mybatis/mapper/util/OGNL.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java index a5e4a8959..b88794dd3 100644 --- a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java +++ b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java @@ -64,7 +64,7 @@ public static boolean checkExampleEntityClass(Object parameter, String entityFul } /** - * 检查 paremeter 对象中指定的 fields 是否全是 null,如果是则抛出异常 + * 检查 parameter 对象中指定的 fields 是否全是 null,如果是则抛出异常 * * @param parameter * @param fields @@ -105,7 +105,7 @@ public static boolean notEmptyCollectionCheck(Object parameter, String error) { } /** - * 检查 paremeter 对象中指定的 fields 是否全是 null,如果是则抛出异常 + * 检查 parameter 对象中指定的 fields 是否全是 null,如果是则抛出异常 * * @param parameter * @return From 0689b3b5062180fa99d2eb57bef4999cde1715d6 Mon Sep 17 00:00:00 2001 From: abel533 Date: Wed, 31 May 2023 21:06:16 +0800 Subject: [PATCH 070/109] =?UTF-8?q?=E8=A7=A3=E5=86=B3ColumnType=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E7=9A=84=E9=99=90=E5=88=B6=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?fixed=20#883?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/mapper/annotation/ColumnType.java | 3 +- .../mybatis/mapper/entity/EntityColumn.java | 7 ++- .../java/tk/mybatis/mapper/genid/GenId.java | 3 +- .../mapper/annotation/ColumnTypeTest.java | 45 +++++++++++++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/annotation/ColumnType.java b/core/src/main/java/tk/mybatis/mapper/annotation/ColumnType.java index de9f5c779..45ecc0dfb 100644 --- a/core/src/main/java/tk/mybatis/mapper/annotation/ColumnType.java +++ b/core/src/main/java/tk/mybatis/mapper/annotation/ColumnType.java @@ -25,7 +25,6 @@ package tk.mybatis.mapper.annotation; import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.TypeHandler; import org.apache.ibatis.type.UnknownTypeHandler; import java.lang.annotation.ElementType; @@ -53,5 +52,5 @@ JdbcType jdbcType() default JdbcType.UNDEFINED; - Class> typeHandler() default UnknownTypeHandler.class; + Class typeHandler() default UnknownTypeHandler.class; } diff --git a/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java b/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java index 4e1401157..3559739c9 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java @@ -25,7 +25,6 @@ package tk.mybatis.mapper.entity; import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.TypeHandler; import tk.mybatis.mapper.code.ORDER; import tk.mybatis.mapper.genid.GenId; import tk.mybatis.mapper.util.StringUtil; @@ -41,7 +40,7 @@ public class EntityColumn { private String column; private Class javaType; private JdbcType jdbcType; - private Class> typeHandler; + private Class typeHandler; private boolean id = false; private boolean identity = false; private Class genIdClass; @@ -272,11 +271,11 @@ public void setTable(EntityTable table) { this.table = table; } - public Class> getTypeHandler() { + public Class getTypeHandler() { return typeHandler; } - public void setTypeHandler(Class> typeHandler) { + public void setTypeHandler(Class typeHandler) { this.typeHandler = typeHandler; } diff --git a/core/src/main/java/tk/mybatis/mapper/genid/GenId.java b/core/src/main/java/tk/mybatis/mapper/genid/GenId.java index 7610d77da..c6a2151fc 100644 --- a/core/src/main/java/tk/mybatis/mapper/genid/GenId.java +++ b/core/src/main/java/tk/mybatis/mapper/genid/GenId.java @@ -5,7 +5,7 @@ *

* 在 Spring 集成环境中,可以通过配置静态方式获取 Spring 的 context 对象。
*

- * 如果使用 vesta(https://gitee.com/robertleepeak/vesta-id-generator) 来生成 ID,假设已经提供了 vesta 的 idService。
+ * 如果使用 vesta(https://gitee.com/free/vesta-id-generator) 来生成 ID,假设已经提供了 vesta 的 idService。
*

* 那么可以在实现中获取该类,然后生成 Id 返回,示例代码如下: * @@ -32,5 +32,4 @@ public Object genId(String table, String column) { } } - } diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTypeTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTypeTest.java index 21d9a18f8..6f2a0ecba 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTypeTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTypeTest.java @@ -4,6 +4,7 @@ import org.apache.ibatis.mapping.ResultMapping; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.type.BlobTypeHandler; +import org.apache.ibatis.type.EnumOrdinalTypeHandler; import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.StringTypeHandler; import org.junit.Assert; @@ -192,6 +193,50 @@ public void testTypehandler() { Assert.assertEquals(BlobTypeHandler.class, resultMapping.getTypeHandler().getClass()); } + enum UserEnum { + A, B + } + + class UserEnumOrdinalTypeHandler { + @ColumnType(typeHandler = EnumOrdinalTypeHandler.class) + private UserEnum name; + } + + @Test + public void testEnumOrdinalTypeHandler() { + EntityHelper.initEntityNameMap(UserEnumOrdinalTypeHandler.class, config); + EntityTable entityTable = EntityHelper.getEntityTable(UserEnumOrdinalTypeHandler.class); + Assert.assertNotNull(entityTable); + + Set columns = entityTable.getEntityClassColumns(); + Assert.assertEquals(1, columns.size()); + + for (EntityColumn column : columns) { + Assert.assertEquals("name", column.getColumn()); + Assert.assertEquals("name", column.getProperty()); + + Assert.assertEquals("name = #{name, typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}", column.getColumnEqualsHolder()); + Assert.assertEquals("name = #{record.name, typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}", column.getColumnEqualsHolder("record")); + Assert.assertEquals("#{name, typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}", column.getColumnHolder()); + Assert.assertEquals("#{record.name, typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}", column.getColumnHolder("record")); + Assert.assertEquals("#{record.name, typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}", column.getColumnHolder("record", "suffix")); + Assert.assertEquals("#{record.namesuffix, typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},", column.getColumnHolder("record", "suffix", ",")); + Assert.assertNotNull(column.getTypeHandler()); + } + + ResultMap resultMap = entityTable.getResultMap(configuration); + Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString()); + + Assert.assertEquals(1, resultMap.getResultMappings().size()); + + ResultMapping resultMapping = resultMap.getResultMappings().get(0); + Assert.assertEquals("name", resultMapping.getColumn()); + Assert.assertEquals("name", resultMapping.getProperty()); + Assert.assertNull(resultMapping.getJdbcType()); + Assert.assertEquals(EnumOrdinalTypeHandler.class, resultMapping.getTypeHandler().getClass()); + } + + class UserAll { @ColumnType(column = "user_name", jdbcType = JdbcType.BLOB, typeHandler = BlobTypeHandler.class) private String name; From 3ea472c41ff3e3343094090d75d5379111f60c4e Mon Sep 17 00:00:00 2001 From: abel533 Date: Wed, 31 May 2023 21:12:34 +0800 Subject: [PATCH 071/109] =?UTF-8?q?UpsertMapper=20=E6=B7=BB=E5=8A=A0@Regis?= =?UTF-8?q?terMapper=E6=B3=A8=E8=A7=A3=EF=BC=8Cfixed=20#878?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java index 66bd8972c..27b308744 100644 --- a/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java +++ b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java @@ -1,7 +1,9 @@ package tk.mybatis.mapper.additional.upsert; import org.apache.ibatis.annotations.UpdateProvider; +import tk.mybatis.mapper.annotation.RegisterMapper; +@RegisterMapper public interface UpsertMapper { @UpdateProvider( From 149755869356214274f2d035b5901c5e2dd41d4d Mon Sep 17 00:00:00 2001 From: abel533 Date: Sat, 3 Jun 2023 09:38:40 +0800 Subject: [PATCH 072/109] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index 64659cf0d..b9ea57e3e 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 64659cf0d3473a26fa0c5a6b60408136b5d42be2 +Subproject commit b9ea57e3e5e9a88fc2ae97add701d65da1bd8759 From 14a50a40b16d4f630165ea4c57d22b46575d2742 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sat, 3 Jun 2023 09:38:57 +0800 Subject: [PATCH 073/109] =?UTF-8?q?=E5=8F=91=E5=B8=834.2.3=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 904372932..68066788c 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 4.2.3-SNAPSHOT + 4.2.3 1.6 1.6 UTF-8 From f08d996f33dbf71997a460a102deda4147884d27 Mon Sep 17 00:00:00 2001 From: abel533 Date: Sat, 3 Jun 2023 09:51:00 +0800 Subject: [PATCH 074/109] =?UTF-8?q?4.3.0-SNAPSHOT=EF=BC=8C=E4=BB=8E4.3?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=9F=BA=E4=BA=8Ejdk8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/mapperhelper/FieldHelper.java | 153 +----------------- pom.xml | 6 +- weekend/pom.xml | 5 - .../mybatis/mapper/weekend/UseJava8Rule.java | 23 --- .../mapper/weekend/UserMapperTest.java | 5 - .../mapper/weekend/WeekendSqlsTest.java | 5 - .../mapper/weekend/WeekendSqlsUtilsTest.java | 5 - 7 files changed, 6 insertions(+), 196 deletions(-) delete mode 100644 weekend/src/test/java/tk/mybatis/mapper/weekend/UseJava8Rule.java diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java index 99de8d063..a9fe51e33 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java @@ -32,7 +32,8 @@ import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.*; /** @@ -43,16 +44,7 @@ */ public class FieldHelper { - private static final IFieldHelper fieldHelper; - - static { - String version = System.getProperty("java.version"); - if (version.contains("1.6.") || version.contains("1.7.")) { - fieldHelper = new Jdk6_7FieldHelper(); - } else { - fieldHelper = new Jdk8FieldHelper(); - } - } + private static final IFieldHelper fieldHelper = new Jdk8FieldHelper(); /** * 获取全部的Field @@ -243,143 +235,4 @@ public List getProperties(Class entityClass) { } } - /** - * 支持jdk6,7 - */ - static class Jdk6_7FieldHelper implements IFieldHelper { - - @Override - public List getFields(Class entityClass) { - List fieldList = new ArrayList(); - _getFields(entityClass, fieldList, _getGenericTypeMap(entityClass), null); - return new ArrayList(new LinkedHashSet(fieldList)); - } - - /** - * 通过方法获取属性 - * - * @param entityClass - * @return - */ - @Override - public List getProperties(Class entityClass) { - Map> genericMap = _getGenericTypeMap(entityClass); - List entityFields = new ArrayList(); - BeanInfo beanInfo; - try { - beanInfo = Introspector.getBeanInfo(entityClass); - } catch (IntrospectionException e) { - throw new MapperException(e); - } - PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); - for (PropertyDescriptor desc : descriptors) { - if (desc != null && !"class".equals(desc.getName())) { - EntityField entityField = new EntityField(null, desc); - if (desc.getReadMethod() != null - && desc.getReadMethod().getGenericReturnType() != null - && desc.getReadMethod().getGenericReturnType() instanceof TypeVariable) { - entityField.setJavaType(genericMap.get(((TypeVariable) desc.getReadMethod().getGenericReturnType()).getName())); - } else if (desc.getWriteMethod() != null - && desc.getWriteMethod().getGenericParameterTypes() != null - && desc.getWriteMethod().getGenericParameterTypes().length == 1 - && desc.getWriteMethod().getGenericParameterTypes()[0] instanceof TypeVariable) { - entityField.setJavaType(genericMap.get(((TypeVariable) desc.getWriteMethod().getGenericParameterTypes()[0]).getName())); - } - entityFields.add(entityField); - } - } - return entityFields; - } - - /** - * @param entityClass - * @param fieldList - * @param genericMap - * @param level - */ - private void _getFields(Class entityClass, List fieldList, Map> genericMap, Integer level) { - if (fieldList == null) { - throw new NullPointerException("fieldList参数不能为空!"); - } - if (level == null) { - level = 0; - } - if (entityClass == Object.class) { - return; - } - Field[] fields = entityClass.getDeclaredFields(); - int index = 0; - for (Field field : fields) { - //忽略static和transient字段#106 - if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) { - EntityField entityField = new EntityField(field, null); - if (field.getGenericType() != null && field.getGenericType() instanceof TypeVariable) { - if (genericMap == null || !genericMap.containsKey(((TypeVariable) field.getGenericType()).getName())) { - throw new MapperException(entityClass + "字段" + field.getName() + "的泛型类型无法获取!"); - } else { - entityField.setJavaType(genericMap.get(((TypeVariable) field.getGenericType()).getName())); - } - } else { - entityField.setJavaType(field.getType()); - } - //如果父类中包含与子类同名field,则跳过处理,允许子类进行覆盖 - if (FieldHelper.containFiled(fieldList, field.getName())) { - continue; - } - if (level.intValue() != 0) { - //将父类的字段放在前面 - fieldList.add(index, entityField); - index++; - } else { - fieldList.add(entityField); - } - } - } - //获取父类和泛型信息 - Class superClass = entityClass.getSuperclass(); - //判断superClass - if (superClass != null - && !superClass.equals(Object.class) - && (superClass.isAnnotationPresent(Entity.class) - || (!Map.class.isAssignableFrom(superClass) - && !Collection.class.isAssignableFrom(superClass)))) { - level++; - _getFields(superClass, fieldList, genericMap, level); - } - } - - /** - * 获取所有泛型类型映射 - * - * @param entityClass - */ - private Map> _getGenericTypeMap(Class entityClass) { - Map> genericMap = new HashMap>(); - if (entityClass == Object.class) { - return genericMap; - } - //获取父类和泛型信息 - Class superClass = entityClass.getSuperclass(); - //判断superClass - if (superClass != null - && !superClass.equals(Object.class) - && (superClass.isAnnotationPresent(Entity.class) - || (!Map.class.isAssignableFrom(superClass) - && !Collection.class.isAssignableFrom(superClass)))) { - if (entityClass.getGenericSuperclass() instanceof ParameterizedType) { - Type[] types = ((ParameterizedType) entityClass.getGenericSuperclass()).getActualTypeArguments(); - TypeVariable[] typeVariables = superClass.getTypeParameters(); - if (typeVariables.length > 0) { - for (int i = 0; i < typeVariables.length; i++) { - if (types[i] instanceof Class) { - genericMap.put(typeVariables[i].getName(), (Class) types[i]); - } - } - } - } - genericMap.putAll(_getGenericTypeMap(superClass)); - } - return genericMap; - } - } } diff --git a/pom.xml b/pom.xml index 68066788c..2f2fc2b34 100644 --- a/pom.xml +++ b/pom.xml @@ -35,9 +35,9 @@ https://mybatis.io - 4.2.3 - 1.6 - 1.6 + 4.3.0-SNAPSHOT + 8 + 8 UTF-8 UTF-8 -Dfile.encoding=UTF-8 diff --git a/weekend/pom.xml b/weekend/pom.xml index d29e496cf..8aa0b3a8f 100644 --- a/weekend/pom.xml +++ b/weekend/pom.xml @@ -51,11 +51,6 @@ - - 8 - 8 - - org.mybatis diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/UseJava8Rule.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/UseJava8Rule.java deleted file mode 100644 index bc00b65d3..000000000 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/UseJava8Rule.java +++ /dev/null @@ -1,23 +0,0 @@ -package tk.mybatis.mapper.weekend; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -/** - * @author liuzh - */ -public class UseJava8Rule implements TestRule { - @Override - public Statement apply(final Statement base, final Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - String version = System.getProperty("java.version"); - if (!version.contains("1.6.") && !version.contains("1.7.")) { - base.evaluate(); - } - } - }; - } -} diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java index c87eea04e..b57bb971c 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/UserMapperTest.java @@ -26,9 +26,7 @@ package tk.mybatis.mapper.weekend; import org.apache.ibatis.session.SqlSession; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TestRule; import tk.mybatis.mapper.weekend.entity.Country; import tk.mybatis.mapper.weekend.entity.User; import tk.mybatis.mapper.weekend.mapper.CountryMapper; @@ -42,9 +40,6 @@ */ public class UserMapperTest { - @Rule - public TestRule runJava8 = new UseJava8Rule(); - /** * 执行,然后看日志打出来的SQL */ diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsTest.java index 2b85b2286..dd0624fa2 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsTest.java @@ -27,9 +27,7 @@ import org.apache.ibatis.session.SqlSession; import org.junit.Assert; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TestRule; import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.util.Sqls; import tk.mybatis.mapper.weekend.entity.Country; @@ -44,9 +42,6 @@ */ public class WeekendSqlsTest { - @Rule - public TestRule runJava8 = new UseJava8Rule(); - @Test public void testWeekend() { SqlSession sqlSession = MybatisHelper.getSqlSession(); diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsUtilsTest.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsUtilsTest.java index 00775c994..2c2b3cb2e 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsUtilsTest.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/WeekendSqlsUtilsTest.java @@ -27,9 +27,7 @@ import org.apache.ibatis.session.SqlSession; import org.junit.Assert; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TestRule; import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.util.Sqls; import tk.mybatis.mapper.weekend.entity.Country; @@ -45,9 +43,6 @@ */ public class WeekendSqlsUtilsTest { - @Rule - public TestRule runJava8 = new UseJava8Rule(); - @Test public void testWeekend() { SqlSession sqlSession = MybatisHelper.getSqlSession(); From 50d9ebf2801d6c3c4d96105829a44d15696e135d Mon Sep 17 00:00:00 2001 From: samyge Date: Wed, 5 Jul 2023 23:05:43 +0800 Subject: [PATCH 075/109] =?UTF-8?q?=E8=A7=A3=E5=86=B3Mapper=E7=88=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E6=B3=9B=E5=9E=8B=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=9C=A8=E4=BD=BF=E7=94=A8=E6=B3=9B=E5=9E=8B=E7=9A=84=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E4=B8=8B=E6=8A=A5ClassCastException=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8Cfixed=20#886?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/mapper/mapperhelper/MapperTemplate.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java index 195c8333f..55a5fa253 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java @@ -167,7 +167,18 @@ public Class getEntityClass(MappedStatement ms) { if (type instanceof ParameterizedType) { ParameterizedType t = (ParameterizedType) type; if (t.getRawType() == this.mapperClass || this.mapperClass.isAssignableFrom((Class) t.getRawType())) { - Class returnType = (Class) t.getActualTypeArguments()[0]; + Type actualType = t.getActualTypeArguments()[0]; + Class returnType; + if (actualType instanceof Class) { + returnType = (Class) actualType; + } else if (actualType instanceof ParameterizedType) { + // 获取泛型信息后发现任然是泛型的场景 + returnType = (Class) ((ParameterizedType)actualType).getRawType(); + } else { + // GenericArrayType、TypeVariable以及WildcardType不受支持 + throw new MapperException(msId + " 方法的泛型信息不受支持!"); + } + //获取该类型后,第一次对该类型进行初始化 EntityHelper.initEntityNameMap(returnType, mapperHelper.getConfig()); entityClassMap.put(msId, returnType); From 7aabb8cc27bab734bcce439bb6c5f8bc23d75705 Mon Sep 17 00:00:00 2001 From: gonghao Date: Tue, 10 Oct 2023 10:50:18 +0800 Subject: [PATCH 076/109] =?UTF-8?q?generator=E6=96=B0=E5=A2=9E=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E5=BC=BA=E5=88=B6=E4=B8=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/MapperCommentGenerator.java | 22 +++++++++----- .../mapper/generator/MapperPlugin.java | 29 ++++++++++++------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java index f3388aeea..0f0ace449 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java @@ -45,6 +45,8 @@ public class MapperCommentGenerator implements CommentGenerator { private String endingDelimiter = ""; //强制生成注解 private boolean forceAnnotation; + //强制不生成注解 + private boolean forceNonAnnotation; //是否生成swagger注解 private boolean needsSwagger; //逻辑删除字段 @@ -93,6 +95,10 @@ public void addConfigurationProperties(Properties properties) { if (StringUtility.stringHasValue(forceAnnotation)) { this.forceAnnotation = "TRUE".equalsIgnoreCase(forceAnnotation); } + String forceNonAnnotation = properties.getProperty("forceNonAnnotation"); + if (StringUtility.stringHasValue(forceNonAnnotation)) { + this.forceNonAnnotation = "TRUE".equalsIgnoreCase(forceNonAnnotation); + } String needsSwagger = properties.getProperty("needsSwagger"); if (StringUtility.stringHasValue(needsSwagger)) { this.needsSwagger = "TRUE".equalsIgnoreCase(needsSwagger); @@ -175,13 +181,15 @@ public void addFieldComment(Field field, IntrospectedTable introspectedTable, In + column + introspectedColumn.getContext().getEndingDelimiter(); } - if (!column.equals(introspectedColumn.getJavaProperty())) { - //@Column - field.addAnnotation("@Column(name = \"" + getDelimiterName(column) + "\")"); - } else if (StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { - field.addAnnotation("@Column(name = \"" + getDelimiterName(column) + "\")"); - } else if (forceAnnotation) { - field.addAnnotation("@Column(name = \"" + getDelimiterName(column) + "\")"); + if (!forceNonAnnotation) { + if (!column.equals(introspectedColumn.getJavaProperty())) { + //@Column + field.addAnnotation("@Column(name = \"" + getDelimiterName(column) + "\")"); + } else if (StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { + field.addAnnotation("@Column(name = \"" + getDelimiterName(column) + "\")"); + } else if (forceAnnotation) { + field.addAnnotation("@Column(name = \"" + getDelimiterName(column) + "\")"); + } } // 添加逻辑删除注解 diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index 2f2bfcc7c..527299623 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -54,6 +54,8 @@ public class MapperPlugin extends FalseMethodPlugin { private CommentGeneratorConfiguration commentCfg; //强制生成注解 private boolean forceAnnotation; + //强制不生成注解 + private boolean forceNonAnnotation; //是否需要生成Data注解 private boolean needsData = false; @@ -222,16 +224,18 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i + context.getEndingDelimiter(); } //是否忽略大小写,对于区分大小写的数据库,会有用 - if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { - topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); - } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { - topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); - } else if (StringUtility.stringHasValue(schema) - || StringUtility.stringHasValue(beginningDelimiter) - || StringUtility.stringHasValue(endingDelimiter)) { - topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); - } else if (forceAnnotation) { - topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); + if (!forceNonAnnotation) { + if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { + topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); + } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { + topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); + } else if (StringUtility.stringHasValue(schema) + || StringUtility.stringHasValue(beginningDelimiter) + || StringUtility.stringHasValue(endingDelimiter)) { + topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); + } else if (forceAnnotation) { + topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); + } } if (generateColumnConsts) { for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { @@ -428,6 +432,7 @@ public void setProperties(Properties properties) { } this.caseSensitive = Boolean.parseBoolean(this.properties.getProperty("caseSensitive")); this.forceAnnotation = getPropertyAsBoolean("forceAnnotation"); + this.forceNonAnnotation = getPropertyAsBoolean("forceNonAnnotation"); this.beginningDelimiter = getProperty("beginningDelimiter", ""); this.endingDelimiter = getProperty("endingDelimiter", ""); this.schema = getProperty("schema"); @@ -461,6 +466,10 @@ public void setProperties(Properties properties) { if (StringUtility.stringHasValue(forceAnnotation)) { commentCfg.addProperty("forceAnnotation", forceAnnotation); } + String forceNonAnnotation = getProperty("forceNonAnnotation"); + if (StringUtility.stringHasValue(forceNonAnnotation)) { + commentCfg.addProperty("forceNonAnnotation", forceNonAnnotation); + } commentCfg.addProperty("needsSwagger", this.needsSwagger + ""); } this.generateColumnConsts = getPropertyAsBoolean("generateColumnConsts"); From 58c25cda001fb8268e65e49da61609e98f398fce Mon Sep 17 00:00:00 2001 From: wangyuhao12 Date: Fri, 3 Nov 2023 11:37:58 +0800 Subject: [PATCH 077/109] =?UTF-8?q?=E4=B8=BA@LogicDelete=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E4=B8=A4=E4=B8=AA=E5=AD=97=E6=AE=B5=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=A4=84=E7=90=86=E5=B8=8C=E6=9C=9Bnull=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E9=80=BB=E8=BE=91=E5=88=A0=E9=99=A4=E7=9A=84=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E7=9A=84=E8=83=BD=E5=8A=9B=E3=80=82=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E4=BB=A5null=E4=BD=9C=E4=B8=BA=E5=88=A0=E9=99=A4/=E6=9C=AA?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AE=B0=E5=BD=95=E7=9A=84=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/annotation/LogicDelete.java | 8 ++++++++ .../tk/mybatis/mapper/mapperhelper/SqlHelper.java | 13 +++++++++---- core/src/main/java/tk/mybatis/mapper/util/OGNL.java | 7 ++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java b/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java index fc29872f5..8ea911ef9 100644 --- a/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java +++ b/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java @@ -1,5 +1,7 @@ package tk.mybatis.mapper.annotation; +import scala.Int; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -14,6 +16,12 @@ int isDeletedValue() default 1; + // 优先级比isDeletedValue更高 表示以null作为删除记录的标识 + boolean isNullForDeletedValue() default false; + int notDeletedValue() default 0; + // 优先级比notDeletedValue更高 表示以null作为未删除记录的标识 + boolean isNullForNotDeletedValue() default false; + } diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java index 949a44042..83c7391b5 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java @@ -776,7 +776,12 @@ public static String logicDeleteColumnEqualsValue(Class entityClass, boolean public static String logicDeleteColumnEqualsValue(EntityColumn column, boolean isDeleted) { String result = ""; if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) { - result = column.getColumn() + " = " + getLogicDeletedValue(column, isDeleted); + Integer logicDeletedValue = getLogicDeletedValue(column, isDeleted); + if(logicDeletedValue==null){ + result = column.getColumn() + " is null "; + }else { + result = column.getColumn() + " = " + logicDeletedValue; + } } return result; } @@ -788,15 +793,15 @@ public static String logicDeleteColumnEqualsValue(EntityColumn column, boolean i * @param isDeleted true:逻辑删除的值,false:未逻辑删除的值 * @return */ - public static int getLogicDeletedValue(EntityColumn column, boolean isDeleted) { + public static Integer getLogicDeletedValue(EntityColumn column, boolean isDeleted) { if (!column.getEntityField().isAnnotationPresent(LogicDelete.class)) { throw new LogicDeleteException(column.getColumn() + " 没有 @LogicDelete 注解!"); } LogicDelete logicDelete = column.getEntityField().getAnnotation(LogicDelete.class); if (isDeleted) { - return logicDelete.isDeletedValue(); + return logicDelete.isNullForDeletedValue()?null: logicDelete.isDeletedValue(); } - return logicDelete.notDeletedValue(); + return logicDelete.isNullForNotDeletedValue()?null: logicDelete.notDeletedValue(); } /** diff --git a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java index a5e4a8959..34bbe0513 100644 --- a/core/src/main/java/tk/mybatis/mapper/util/OGNL.java +++ b/core/src/main/java/tk/mybatis/mapper/util/OGNL.java @@ -243,7 +243,12 @@ public static String andNotLogicDelete(Object parameter) { EntityColumn column = entry.getValue(); if (column.getEntityField().isAnnotationPresent(LogicDelete.class)) { // 未逻辑删除的条件 - result = column.getColumn() + " = " + SqlHelper.getLogicDeletedValue(column, false); + Integer logicDeletedValue = SqlHelper.getLogicDeletedValue(column, false); + if(logicDeletedValue==null){ + result = column.getColumn() + " is null "; + }else { + result = column.getColumn() + " = " + logicDeletedValue; + } // 如果Example中有条件,则拼接" and ", // 如果是空的oredCriteria,则where中只有逻辑删除注解的未删除条件 From 55dd584efc2c9c324b52f21c0b6bd6b66e769bcb Mon Sep 17 00:00:00 2001 From: wangyuhao12 Date: Fri, 3 Nov 2023 12:08:42 +0800 Subject: [PATCH 078/109] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=9C=AA=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java b/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java index 8ea911ef9..ecd482ecb 100644 --- a/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java +++ b/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java @@ -1,7 +1,5 @@ package tk.mybatis.mapper.annotation; -import scala.Int; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; From 5195826d3477ae60a0e659cd2f236a422fee7641 Mon Sep 17 00:00:00 2001 From: Saairam Venkatesh Date: Fri, 3 Nov 2023 19:30:54 -0500 Subject: [PATCH 079/109] Fixed flakiness caused by Class.getDeclaredFields --- .../mybatis/mapper/mapperhelper/FieldHelper.java | 1 + .../mapper/mapperhelper/ComplexEntityTest.java | 16 ++++++++-------- .../mapper/mapperhelper/SqlHelperTest.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java index a9fe51e33..c09051423 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java @@ -181,6 +181,7 @@ private List _getFields(Class entityClass, List fie return fieldList; } Field[] fields = entityClass.getDeclaredFields(); + Arrays.sort(fields, Comparator.comparing(Field::getName)); int index = 0; for (int i = 0; i < fields.length; i++) { Field field = fields[i]; diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java index 1ecd948f0..edfba3400 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java @@ -152,19 +152,19 @@ public void test() { sqlBuilder.append(SqlHelper.fromTable(entityClass, entityTable.getName())); sqlBuilder.append(SqlHelper.whereAllIfColumns(entityClass, config.isNotEmpty())); final String sql = sqlBuilder.toString(); - Assert.assertEquals("SELECT id,user_name,address,state FROM user " + + Assert.assertEquals("SELECT address,id,state,user_name FROM user " + "" + - " AND id = #{id}" + - " AND user_name = #{userName}" + " AND address = #{address, typeHandler=tk.mybatis.mapper.mapperhelper.ComplexEntityTest$AddressHandler}" + - " AND state = #{state}", sql); + " AND id = #{id}" + + " AND state = #{state}" + + " AND user_name = #{userName}", sql); final ResultMap resultMap = entityTable.getResultMap(configuration); final List resultMappings = resultMap.getResultMappings(); - final ResultMapping idMapping = resultMappings.get(0); - final ResultMapping userNameMapping = resultMappings.get(1); - final ResultMapping addressMapping = resultMappings.get(2); - final ResultMapping stateMapping = resultMappings.get(3); + final ResultMapping addressMapping = resultMappings.get(0); + final ResultMapping idMapping = resultMappings.get(1); + final ResultMapping stateMapping = resultMappings.get(2); + final ResultMapping userNameMapping = resultMappings.get(3); Assert.assertEquals("id", idMapping.getColumn()); Assert.assertEquals("id", idMapping.getProperty()); diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java index 78308e53a..1589e20de 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java @@ -35,7 +35,7 @@ public void testLogicDeleteSql() { Assert.assertEquals(" AND is_valid = 1", notLogicDeletedColumn); String updateSetColumns = SqlHelper.updateSetColumns(User.class, null, false, false); - Assert.assertEquals("username = #{username},is_valid = 1,", updateSetColumns); + Assert.assertEquals("is_valid = 1,username = #{username},", updateSetColumns); } } From a7d20907eb1bfa87b81ec8c8e20d9ad783c05a98 Mon Sep 17 00:00:00 2001 From: gonghao Date: Wed, 20 Dec 2023 17:31:34 +0800 Subject: [PATCH 080/109] =?UTF-8?q?WeekendSqlsUtils=E6=96=B0=E5=A2=9Ewhere?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/weekend/WeekendSqlsUtils.java | 5 +++++ .../mybatis/mapper/weekend/reflection/Reflections.java | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java index 62dd274f1..71f7a64b5 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java @@ -25,6 +25,8 @@ package tk.mybatis.mapper.weekend; +import tk.mybatis.mapper.weekend.reflection.Reflections; + /** * {@link WeekendSqls} 的工具类,提供一系列静态方法,减少泛型参数的指定,使代码更简洁、清晰 * @@ -276,4 +278,7 @@ public static WeekendSqls orNotLike(Fn fn, String value) { return WeekendSqls.custom().orNotLike(fn, value); } + public static String[] where(Fn... fn) { + return Reflections.fnToFieldNames(fn); + } } diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/reflection/Reflections.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/reflection/Reflections.java index 4df0864e0..236dcbadd 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/reflection/Reflections.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/reflection/Reflections.java @@ -30,6 +30,8 @@ import java.beans.Introspector; import java.lang.invoke.SerializedLambda; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; /** @@ -58,4 +60,12 @@ public static String fnToFieldName(Fn fn) { throw new ReflectionOperationException(e); } } + + public static String[] fnToFieldNames(Fn... fns) { + List list = new ArrayList<>(); + for (Fn fn : fns) { + list.add(fnToFieldName(fn)); + } + return list.toArray(new String[0]); + } } From 2d7a33d2a36608a85f17a1af6500a093ec0dbe54 Mon Sep 17 00:00:00 2001 From: gonghao Date: Thu, 4 Jan 2024 14:53:33 +0800 Subject: [PATCH 081/109] =?UTF-8?q?where=E6=96=B9=E6=B3=95=E6=9B=B4?= =?UTF-8?q?=E5=90=8D=E4=B8=BAselect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java index 71f7a64b5..5a036e344 100644 --- a/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java +++ b/weekend/src/main/java/tk/mybatis/mapper/weekend/WeekendSqlsUtils.java @@ -278,7 +278,7 @@ public static WeekendSqls orNotLike(Fn fn, String value) { return WeekendSqls.custom().orNotLike(fn, value); } - public static String[] where(Fn... fn) { + public static String[] select(Fn... fn) { return Reflections.fnToFieldNames(fn); } } From 32fd500bfcfc4b774b63efc29be1ef66b1346848 Mon Sep 17 00:00:00 2001 From: yuanhao18 Date: Thu, 22 Feb 2024 21:06:48 +0800 Subject: [PATCH 082/109] feat: support multi provider in one mapper feat: support multi provider in one mapper --- .../mapper/mapperhelper/MapperHelper.java | 59 ++++++++----------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java index 800aad6aa..221ea35f6 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java @@ -87,7 +87,6 @@ public MapperHelper(Properties properties) { this(); setProperties(properties); } - /** * 通过通用Mapper接口获取对应的MapperTemplate * @@ -95,56 +94,44 @@ public MapperHelper(Properties properties) { * @return * @throws Exception */ - private MapperTemplate fromMapperClass(Class mapperClass) { + private Collection fromMapperClasses(Class mapperClass) { + Map,MapperTemplate> templateMap = new ConcurrentHashMap, MapperTemplate>(); Method[] methods = mapperClass.getDeclaredMethods(); - Class templateClass = null; - Class tempClass = null; - Set methodSet = new HashSet(); for (Method method : methods) { + Class templateClass = null; if (method.isAnnotationPresent(SelectProvider.class)) { SelectProvider provider = method.getAnnotation(SelectProvider.class); - tempClass = provider.type(); - methodSet.add(method.getName()); + templateClass = provider.type(); } else if (method.isAnnotationPresent(InsertProvider.class)) { InsertProvider provider = method.getAnnotation(InsertProvider.class); - tempClass = provider.type(); - methodSet.add(method.getName()); + templateClass = provider.type(); } else if (method.isAnnotationPresent(DeleteProvider.class)) { DeleteProvider provider = method.getAnnotation(DeleteProvider.class); - tempClass = provider.type(); - methodSet.add(method.getName()); + templateClass = provider.type(); } else if (method.isAnnotationPresent(UpdateProvider.class)) { UpdateProvider provider = method.getAnnotation(UpdateProvider.class); - tempClass = provider.type(); - methodSet.add(method.getName()); + templateClass = provider.type(); } - if (templateClass == null) { - templateClass = tempClass; - } else if (templateClass != tempClass) { - log.error("一个通用Mapper中只允许存在一个MapperTemplate子类!"); - throw new MapperException("一个通用Mapper中只允许存在一个MapperTemplate子类!"); + if (templateClass == null || !MapperTemplate.class.isAssignableFrom(templateClass)) { + templateClass = EmptyProvider.class; } - } - if (templateClass == null || !MapperTemplate.class.isAssignableFrom(templateClass)) { - templateClass = EmptyProvider.class; - } - MapperTemplate mapperTemplate = null; - try { - mapperTemplate = (MapperTemplate) templateClass.getConstructor(Class.class, MapperHelper.class).newInstance(mapperClass, this); - } catch (Exception e) { - log.error("实例化MapperTemplate对象失败:" + e, e); - throw new MapperException("实例化MapperTemplate对象失败:" + e.getMessage()); - } - //注册方法 - for (String methodName : methodSet) { + MapperTemplate mapperTemplate; try { - mapperTemplate.addMethodMap(methodName, templateClass.getMethod(methodName, MappedStatement.class)); + mapperTemplate = templateMap.getOrDefault(templateClass,(MapperTemplate) templateClass.getConstructor(Class.class, MapperHelper.class).newInstance(mapperClass, this));; + templateMap.put(templateClass, mapperTemplate); + } catch (Exception e) { + log.error("实例化MapperTemplate对象失败:" + e, e); + throw new MapperException("实例化MapperTemplate对象失败:" + e.getMessage()); + } + //注册方法 + try { + mapperTemplate.addMethodMap(method.getName(), templateClass.getMethod(method.getName(), MappedStatement.class)); } catch (NoSuchMethodException e) { - log.error(templateClass.getName() + "中缺少" + methodName + "方法!", e); - throw new MapperException(templateClass.getName() + "中缺少" + methodName + "方法!"); + log.error(templateClass.getName() + "中缺少" + method.getName() + "方法!", e); + throw new MapperException(templateClass.getName() + "中缺少" + method.getName() + "方法!"); } } - return mapperTemplate; + return templateMap.values(); } /** @@ -155,7 +142,7 @@ private MapperTemplate fromMapperClass(Class mapperClass) { public void registerMapper(Class mapperClass) { if (!registerMapper.containsKey(mapperClass)) { registerClass.add(mapperClass); - registerMapper.put(mapperClass, fromMapperClass(mapperClass)); + fromMapperClasses(mapperClass).forEach(c -> registerMapper.put(mapperClass, c)); } //自动注册继承的接口 Class[] interfaces = mapperClass.getInterfaces(); From 30e8c35ed8166e4b4f176a96030339b391c27206 Mon Sep 17 00:00:00 2001 From: Hao Yuan Date: Wed, 28 Feb 2024 09:08:23 +0800 Subject: [PATCH 083/109] test --- .../helper/MultipleMapperProviderTest.java | 37 +++++++++++++++++++ .../mapper/mapper/CountryMultipleMapper.java | 11 ++++++ .../mapper/mapper/MultipleCommonMapper.java | 17 +++++++++ base/src/test/resources/mybatis-java.xml | 1 + 4 files changed, 66 insertions(+) create mode 100644 base/src/test/java/tk/mybatis/mapper/helper/MultipleMapperProviderTest.java create mode 100644 base/src/test/java/tk/mybatis/mapper/mapper/CountryMultipleMapper.java create mode 100644 base/src/test/java/tk/mybatis/mapper/mapper/MultipleCommonMapper.java diff --git a/base/src/test/java/tk/mybatis/mapper/helper/MultipleMapperProviderTest.java b/base/src/test/java/tk/mybatis/mapper/helper/MultipleMapperProviderTest.java new file mode 100644 index 000000000..2ba4cb669 --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/helper/MultipleMapperProviderTest.java @@ -0,0 +1,37 @@ +package tk.mybatis.mapper.helper; + +import org.apache.ibatis.annotations.InsertProvider; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.session.SqlSession; +import org.junit.Assert; +import org.junit.Test; +import tk.mybatis.mapper.annotation.RegisterMapper; +import tk.mybatis.mapper.mapper.CountryMultipleMapper; +import tk.mybatis.mapper.mapper.MybatisHelper; +import tk.mybatis.mapper.model.Country; +import tk.mybatis.mapper.provider.base.BaseInsertProvider; +import tk.mybatis.mapper.provider.base.BaseSelectProvider; + +import java.util.List; + +/** + * @author yuanhao + */ +public class MultipleMapperProviderTest { + @Test + public void test() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + CountryMultipleMapper mapper = sqlSession.getMapper(CountryMultipleMapper.class); + + Country country = new Country(); + country.setId(200); + country.setCountrycode("AB"); + mapper.insert(country); + List countryList = mapper.select(country); + Assert.assertEquals("AB", countryList.get(0).getCountrycode()); + } finally { + sqlSession.close(); + } + } +} diff --git a/base/src/test/java/tk/mybatis/mapper/mapper/CountryMultipleMapper.java b/base/src/test/java/tk/mybatis/mapper/mapper/CountryMultipleMapper.java new file mode 100644 index 000000000..b7cf67e57 --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/mapper/CountryMultipleMapper.java @@ -0,0 +1,11 @@ +package tk.mybatis.mapper.mapper; + +import tk.mybatis.mapper.common.Mapper; +import tk.mybatis.mapper.model.Country; + +//@RegisterMapper +public interface CountryMultipleMapper +// extends Mapper { + extends MultipleCommonMapper { + +} diff --git a/base/src/test/java/tk/mybatis/mapper/mapper/MultipleCommonMapper.java b/base/src/test/java/tk/mybatis/mapper/mapper/MultipleCommonMapper.java new file mode 100644 index 000000000..19c0b0f18 --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/mapper/MultipleCommonMapper.java @@ -0,0 +1,17 @@ +package tk.mybatis.mapper.mapper; + +import org.apache.ibatis.annotations.InsertProvider; +import org.apache.ibatis.annotations.SelectProvider; +import tk.mybatis.mapper.annotation.RegisterMapper; +import tk.mybatis.mapper.provider.base.BaseInsertProvider; +import tk.mybatis.mapper.provider.base.BaseSelectProvider; + +import java.util.List; + +@RegisterMapper +public interface MultipleCommonMapper { + @SelectProvider(type = BaseSelectProvider.class, method = "dynamicSQL") + List select(T record); + @InsertProvider(type = BaseInsertProvider.class, method = "dynamicSQL") + int insert(T record); +} diff --git a/base/src/test/resources/mybatis-java.xml b/base/src/test/resources/mybatis-java.xml index 8f028a361..1f00f834e 100644 --- a/base/src/test/resources/mybatis-java.xml +++ b/base/src/test/resources/mybatis-java.xml @@ -62,6 +62,7 @@ + From 56a9a530bd26f481c71628a4bec743b157b9f088 Mon Sep 17 00:00:00 2001 From: yuanhao18 Date: Thu, 29 Feb 2024 15:59:08 +0800 Subject: [PATCH 084/109] fix: multiple providers --- .../mapper/helper/MultipleMapperProviderTest.java | 1 - .../mybatis/mapper/mapper/CountryMultipleMapper.java | 5 ++--- .../tk/mybatis/mapper/mapperhelper/MapperHelper.java | 12 +++++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/base/src/test/java/tk/mybatis/mapper/helper/MultipleMapperProviderTest.java b/base/src/test/java/tk/mybatis/mapper/helper/MultipleMapperProviderTest.java index 2ba4cb669..f752947a7 100644 --- a/base/src/test/java/tk/mybatis/mapper/helper/MultipleMapperProviderTest.java +++ b/base/src/test/java/tk/mybatis/mapper/helper/MultipleMapperProviderTest.java @@ -23,7 +23,6 @@ public void test() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryMultipleMapper mapper = sqlSession.getMapper(CountryMultipleMapper.class); - Country country = new Country(); country.setId(200); country.setCountrycode("AB"); diff --git a/base/src/test/java/tk/mybatis/mapper/mapper/CountryMultipleMapper.java b/base/src/test/java/tk/mybatis/mapper/mapper/CountryMultipleMapper.java index b7cf67e57..fa9dc67a3 100644 --- a/base/src/test/java/tk/mybatis/mapper/mapper/CountryMultipleMapper.java +++ b/base/src/test/java/tk/mybatis/mapper/mapper/CountryMultipleMapper.java @@ -1,11 +1,10 @@ package tk.mybatis.mapper.mapper; import tk.mybatis.mapper.common.Mapper; +import tk.mybatis.mapper.common.base.insert.InsertMapper; +import tk.mybatis.mapper.common.base.select.SelectMapper; import tk.mybatis.mapper.model.Country; -//@RegisterMapper public interface CountryMultipleMapper -// extends Mapper { extends MultipleCommonMapper { - } diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java index 221ea35f6..6d700cbf7 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java @@ -65,7 +65,7 @@ public class MapperHelper { /** * 注册的通用Mapper接口 */ - private Map, MapperTemplate> registerMapper = new ConcurrentHashMap, MapperTemplate>(); + private Map, Collection> registerMapper = new ConcurrentHashMap, Collection>(); /** * 通用Mapper配置 @@ -142,7 +142,7 @@ private Collection fromMapperClasses(Class mapperClass) { public void registerMapper(Class mapperClass) { if (!registerMapper.containsKey(mapperClass)) { registerClass.add(mapperClass); - fromMapperClasses(mapperClass).forEach(c -> registerMapper.put(mapperClass, c)); + registerMapper.put(mapperClass,fromMapperClasses(mapperClass)); } //自动注册继承的接口 Class[] interfaces = mapperClass.getInterfaces(); @@ -196,9 +196,11 @@ public MapperTemplate isMapperMethod(String msId) { * @return */ public MapperTemplate getMapperTemplateByMsId(String msId) { - for (Map.Entry, MapperTemplate> entry : registerMapper.entrySet()) { - if (entry.getValue().supportMethod(msId)) { - return entry.getValue(); + for (Map.Entry, Collection> entry : registerMapper.entrySet()) { + for (MapperTemplate t : entry.getValue()) { + if (t.supportMethod(msId)) { + return t; + } } } return null; From 00f6fc97beacfcfc7d4d52ba793e411f8134ba1f Mon Sep 17 00:00:00 2001 From: "trifolium.wang" Date: Wed, 3 Apr 2024 11:39:12 +0800 Subject: [PATCH 085/109] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=AF=B9sol?= =?UTF-8?q?on=E7=9A=84=E6=8F=92=E4=BB=B6=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + solon-plugin/pom.xml | 87 ++++++++++++++ .../mybatis/solon/TkMapperAdapterFactory.java | 24 ++++ .../mybatis/solon/TkMapperMybatisAdapter.java | 112 ++++++++++++++++++ .../java/tk/mybatis/solon/XPluginImpl.java | 22 ++++ .../mybatis-tkmapper-solon-plugin.properties | 2 + .../tk/mybatis/solon/test/TkMapperTest.java | 15 +++ .../mybatis/solon/test/conf/TestConfig.java | 48 ++++++++ .../tk/mybatis/solon/test/entity/User.java | 108 +++++++++++++++++ .../mybatis/solon/test/mapper/UserMapper.java | 18 +++ .../test/service/TkMapperServiceTest.java | 85 +++++++++++++ solon-plugin/src/test/resources/app.yml | 21 ++++ .../src/test/resources/mapper/UserMapper.xml | 26 ++++ 13 files changed, 569 insertions(+) create mode 100644 solon-plugin/pom.xml create mode 100644 solon-plugin/src/main/java/tk/mybatis/solon/TkMapperAdapterFactory.java create mode 100644 solon-plugin/src/main/java/tk/mybatis/solon/TkMapperMybatisAdapter.java create mode 100644 solon-plugin/src/main/java/tk/mybatis/solon/XPluginImpl.java create mode 100644 solon-plugin/src/main/resources/META-INF/solon/mybatis-tkmapper-solon-plugin.properties create mode 100644 solon-plugin/src/test/java/tk/mybatis/solon/test/TkMapperTest.java create mode 100644 solon-plugin/src/test/java/tk/mybatis/solon/test/conf/TestConfig.java create mode 100644 solon-plugin/src/test/java/tk/mybatis/solon/test/entity/User.java create mode 100644 solon-plugin/src/test/java/tk/mybatis/solon/test/mapper/UserMapper.java create mode 100644 solon-plugin/src/test/java/tk/mybatis/solon/test/service/TkMapperServiceTest.java create mode 100644 solon-plugin/src/test/resources/app.yml create mode 100644 solon-plugin/src/test/resources/mapper/UserMapper.xml diff --git a/pom.xml b/pom.xml index 2f2fc2b34..974cb0737 100644 --- a/pom.xml +++ b/pom.xml @@ -141,6 +141,7 @@ weekend generator spring-boot-starter + solon-plugin diff --git a/solon-plugin/pom.xml b/solon-plugin/pom.xml new file mode 100644 index 000000000..832f263a8 --- /dev/null +++ b/solon-plugin/pom.xml @@ -0,0 +1,87 @@ + + + + + 4.0.0 + + tk.mybatis + mapper-modules + ${revision} + + mapper-solon-plugin + jar + + mapper-solon-plugin + Solon Support for Mapper + https://github.com/abel533/solon-plugin/ + + + 2.7.3 + + + + + + org.noear + mybatis-solon-plugin + ${solon.version} + + + + tk.mybatis + mapper-core + ${project.version} + + + + tk.mybatis + mapper-base + ${project.version} + + + + org.noear + solon-test-junit4 + ${solon.version} + test + + + + com.h2database + h2 + 1.4.200 + test + + + + com.zaxxer + HikariCP + 4.0.3 + test + + + + diff --git a/solon-plugin/src/main/java/tk/mybatis/solon/TkMapperAdapterFactory.java b/solon-plugin/src/main/java/tk/mybatis/solon/TkMapperAdapterFactory.java new file mode 100644 index 000000000..e36cd0bf3 --- /dev/null +++ b/solon-plugin/src/main/java/tk/mybatis/solon/TkMapperAdapterFactory.java @@ -0,0 +1,24 @@ +package tk.mybatis.solon; + +import org.apache.ibatis.solon.MybatisAdapter; +import org.apache.ibatis.solon.MybatisAdapterFactory; +import org.noear.solon.core.BeanWrap; +import org.noear.solon.core.Props; + +/** + * @title: tkMybatis Adapter Factory + * @author: trifolium.wang + * @date: 2024/4/1 + * @since 2.7.3 + */ +public class TkMapperAdapterFactory implements MybatisAdapterFactory { + @Override + public MybatisAdapter create(BeanWrap dsWrap) { + return new TkMapperMybatisAdapter(dsWrap); + } + + @Override + public MybatisAdapter create(BeanWrap dsWrap, Props dsProps) { + return new TkMapperMybatisAdapter(dsWrap, dsProps); + } +} diff --git a/solon-plugin/src/main/java/tk/mybatis/solon/TkMapperMybatisAdapter.java b/solon-plugin/src/main/java/tk/mybatis/solon/TkMapperMybatisAdapter.java new file mode 100644 index 000000000..fb92d69ff --- /dev/null +++ b/solon-plugin/src/main/java/tk/mybatis/solon/TkMapperMybatisAdapter.java @@ -0,0 +1,112 @@ +package tk.mybatis.solon; + +import org.apache.ibatis.mapping.Environment; +import org.apache.ibatis.session.Configuration; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.solon.integration.MybatisAdapterDefault; +import org.noear.solon.core.BeanWrap; +import org.noear.solon.core.Props; +import org.noear.solon.core.PropsConverter; +import org.noear.solon.core.VarHolder; +import tk.mybatis.mapper.entity.Config; +import tk.mybatis.mapper.mapperhelper.MapperHelper; + +/** + * @title: TkMybatis Adapter + * @author: trifolium.wang + * @date: 2024/4/1 + * @since 2.7.3 + */ +public class TkMapperMybatisAdapter extends MybatisAdapterDefault { + + protected Config tkConfig; + + protected MapperHelper mapperHelper; + + protected TkMapperMybatisAdapter(BeanWrap dsWrap) { + super(dsWrap); + + dsWrap.context().getBeanAsync(Config.class, bean -> { + tkConfig = bean; + }); + + dsWrap.context().getBeanAsync(MapperHelper.class, bean -> { + mapperHelper = bean; + }); + } + + protected TkMapperMybatisAdapter(BeanWrap dsWrap, Props dsProps) { + super(dsWrap, dsProps); + + dsWrap.context().getBeanAsync(Config.class, bean -> { + tkConfig = bean; + }); + + dsWrap.context().getBeanAsync(MapperHelper.class, bean -> { + mapperHelper = bean; + }); + } + + @Override + protected void initConfiguration(Environment environment) { + config = new tk.mybatis.mapper.session.Configuration(); + config.setEnvironment(environment); + + Props mybatisProps = dsProps.getProp("configuration"); + if (!mybatisProps.isEmpty()) { + PropsConverter.global().convert(mybatisProps, config, Configuration.class, null); + } + } + + @Override + public SqlSessionFactory getFactory() { + if (factory == null) { + builderMapperHelper(); + factory = factoryBuilder.build(config); + } + return factory; + } + + @Override + public void injectTo(VarHolder varH) { + super.injectTo(varH); + + //@Db("db1") Config tkConfig; + if (Config.class.isAssignableFrom(varH.getType())) { + varH.setValue(this.tkConfig); + } + + //@Db("db1") tk.mybatis.mapper.session.Configuration configuration; + if (tk.mybatis.mapper.session.Configuration.class.isAssignableFrom(varH.getType())) { + varH.setValue(getConfiguration()); + } + + //@Db("db1") MapperHelper mapperHelper; + if (MapperHelper.class.isAssignableFrom(varH.getType())) { + varH.setValue(this.mapperHelper); + } + } + + /** + * 通过使用 tk.mybatis.mapper.session.Configuration + * 替换 MyBatis 中的 org.apache.ibatis.session.Configuration. + * 重写原 Configuration 中的 addMappedStatement实现 + */ + private void builderMapperHelper() { + Props cfgProps = dsProps.getProp("tk.mapper"); + + if (tkConfig == null) { + tkConfig = new Config(); + } + + if (!cfgProps.isEmpty()) { + PropsConverter.global().convert(cfgProps, tkConfig, Config.class, null); + } + if (mapperHelper == null) { + mapperHelper = new MapperHelper(); + } + + mapperHelper.setConfig(tkConfig); + ((tk.mybatis.mapper.session.Configuration) config).setMapperHelper(mapperHelper); + } +} diff --git a/solon-plugin/src/main/java/tk/mybatis/solon/XPluginImpl.java b/solon-plugin/src/main/java/tk/mybatis/solon/XPluginImpl.java new file mode 100644 index 000000000..75ef5c2f7 --- /dev/null +++ b/solon-plugin/src/main/java/tk/mybatis/solon/XPluginImpl.java @@ -0,0 +1,22 @@ +package tk.mybatis.solon; + +import org.apache.ibatis.solon.integration.MybatisAdapterManager; +import org.noear.solon.core.AppContext; +import org.noear.solon.core.Plugin; + +/** + * @title: TkMybatis的Solon插件 + * @author: trifolium.wang + * @date: 2024/4/1 + * @since 2.7.3 + */ +public class XPluginImpl implements Plugin { + + + @Override + public void start(AppContext context) throws Throwable { + + MybatisAdapterManager.setAdapterFactory(new TkMapperAdapterFactory()); + } + +} diff --git a/solon-plugin/src/main/resources/META-INF/solon/mybatis-tkmapper-solon-plugin.properties b/solon-plugin/src/main/resources/META-INF/solon/mybatis-tkmapper-solon-plugin.properties new file mode 100644 index 000000000..14e843dbd --- /dev/null +++ b/solon-plugin/src/main/resources/META-INF/solon/mybatis-tkmapper-solon-plugin.properties @@ -0,0 +1,2 @@ +solon.plugin=tk.mybatis.solon.XPluginImpl +solon.plugin.priority=3 \ No newline at end of file diff --git a/solon-plugin/src/test/java/tk/mybatis/solon/test/TkMapperTest.java b/solon-plugin/src/test/java/tk/mybatis/solon/test/TkMapperTest.java new file mode 100644 index 000000000..f73d3962b --- /dev/null +++ b/solon-plugin/src/test/java/tk/mybatis/solon/test/TkMapperTest.java @@ -0,0 +1,15 @@ +package tk.mybatis.solon.test; + +import org.noear.solon.Solon; + +/** + * @title: TkMapperTest + * @author: trifolium.wang + * @date: 2024/4/2 + */ +public class TkMapperTest { + + public static void main(String[] args) { + Solon.start(TkMapperTest.class, args); + } +} diff --git a/solon-plugin/src/test/java/tk/mybatis/solon/test/conf/TestConfig.java b/solon-plugin/src/test/java/tk/mybatis/solon/test/conf/TestConfig.java new file mode 100644 index 000000000..5fa149a1c --- /dev/null +++ b/solon-plugin/src/test/java/tk/mybatis/solon/test/conf/TestConfig.java @@ -0,0 +1,48 @@ +package tk.mybatis.solon.test.conf; + +import com.zaxxer.hikari.HikariDataSource; +import org.noear.solon.annotation.Bean; +import org.noear.solon.annotation.Configuration; +import org.noear.solon.annotation.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.Statement; + +/** + * @title: TestConfig + * @author: trifolium.wang + * @date: 2024/4/2 + */ +@Configuration +public class TestConfig { + + Logger log = LoggerFactory.getLogger(TestConfig.class); + + @Bean(name = "db1", typed = true) + public DataSource db1(@Inject("${test.db1}") HikariDataSource ds) { + try { + Connection conn = ds.getConnection(); + Statement statement = conn.createStatement(); + statement.execute("CREATE TABLE user (" + + " `id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " `name` varchar(255) DEFAULT NULL," + + " `age` int DEFAULT NULL," + + " `create_time` datetime DEFAULT NULL," + + " `is_del` tinyint(1) DEFAULT NULL" + + ")"); + + statement.execute("INSERT INTO `user` (`id`, `name`, `age`, `create_time`, `is_del`) VALUES (1, '张三', 11, '2024-04-02 13:38:56', 0);\n" + + "INSERT INTO `user` (`id`, `name`, `age`, `create_time`, `is_del`) VALUES (2, '李四', 3, '2024-04-02 13:39:08', 0);\n" + + "INSERT INTO `user` (`id`, `name`, `age`, `create_time`, `is_del`) VALUES (3, '张麻子', 43, '2024-04-02 13:39:20', 0);"); + statement.close(); + conn.close(); + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new RuntimeException("Datasource initialization Failure!"); + } + return ds; + } +} diff --git a/solon-plugin/src/test/java/tk/mybatis/solon/test/entity/User.java b/solon-plugin/src/test/java/tk/mybatis/solon/test/entity/User.java new file mode 100644 index 000000000..900149620 --- /dev/null +++ b/solon-plugin/src/test/java/tk/mybatis/solon/test/entity/User.java @@ -0,0 +1,108 @@ +package tk.mybatis.solon.test.entity; + +import org.noear.snack.core.utils.DateUtil; +import tk.mybatis.mapper.annotation.LogicDelete; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; + +@Table(name = "`user`") +public class User { + @Id + @Column(name = "id") + @GeneratedValue(generator = "JDBC") + private Long id; + + @Column(name = "`name`") + private String name; + + @Column(name = "age") + private Integer age; + + @Column(name = "create_time") + private Date createTime; + + @LogicDelete + @Column(name = "is_del") + private Boolean isDel; + + /** + * @return id + */ + public Long getId() { + return id; + } + + /** + * @param id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * @return name + */ + public String getName() { + return name; + } + + /** + * @param name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return age + */ + public Integer getAge() { + return age; + } + + /** + * @param age + */ + public void setAge(Integer age) { + this.age = age; + } + + /** + * @return create_time + */ + public Date getCreateTime() { + return createTime; + } + + /** + * @param createTime + */ + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + /** + * @return is_del + */ + public Boolean getIsDel() { + return isDel; + } + + /** + * @param isDel + */ + public void setIsDel(Boolean isDel) { + this.isDel = isDel; + } + + @Override + public String toString() { + + return String.format("id:%d, name:%s, age:%d, createTime:%s", id, name, age, + createTime != null ? DateUtil.format(createTime, DateUtil.FORMAT_19_b) : null); + } +} \ No newline at end of file diff --git a/solon-plugin/src/test/java/tk/mybatis/solon/test/mapper/UserMapper.java b/solon-plugin/src/test/java/tk/mybatis/solon/test/mapper/UserMapper.java new file mode 100644 index 000000000..0dc60d2e6 --- /dev/null +++ b/solon-plugin/src/test/java/tk/mybatis/solon/test/mapper/UserMapper.java @@ -0,0 +1,18 @@ +package tk.mybatis.solon.test.mapper; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Select; +import tk.mybatis.mapper.common.Mapper; +import tk.mybatis.solon.test.entity.User; + +import java.util.List; + +public interface UserMapper extends Mapper { + + @ResultMap("tk.mybatis.solon.test.mapper.UserMapper.BaseResultMap") + @Select("SELECT * FROM user WHERE is_del = 0 AND age > #{age}") + List findByGTAge(@Param("age") Integer age); + + List findByName(@Param("name") String name); +} \ No newline at end of file diff --git a/solon-plugin/src/test/java/tk/mybatis/solon/test/service/TkMapperServiceTest.java b/solon-plugin/src/test/java/tk/mybatis/solon/test/service/TkMapperServiceTest.java new file mode 100644 index 000000000..a0e2a85ff --- /dev/null +++ b/solon-plugin/src/test/java/tk/mybatis/solon/test/service/TkMapperServiceTest.java @@ -0,0 +1,85 @@ +package tk.mybatis.solon.test.service; + +import org.apache.ibatis.solon.annotation.Db; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.noear.solon.test.SolonJUnit4ClassRunner; +import org.noear.solon.test.SolonTest; +import org.noear.solon.test.annotation.Rollback; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import tk.mybatis.mapper.entity.Example; +import tk.mybatis.solon.test.TkMapperTest; +import tk.mybatis.solon.test.entity.User; +import tk.mybatis.solon.test.mapper.UserMapper; + +import java.util.List; + +/** + * @title: TkMapperServiceTest + * @author: trifolium.wang + * @date: 2024/4/2 + */ +//@Ignore +@SolonTest(TkMapperTest.class) +@RunWith(SolonJUnit4ClassRunner.class) +public class TkMapperServiceTest { + + Logger log = LoggerFactory.getLogger(TkMapperServiceTest.class); + + @Db("db1") + private UserMapper userMapper; + + @Test + public void all() { + + userMapper.selectAll().forEach(u -> log.info(u.toString())); + } + + /** + * 根据主键查询 + */ + @Test + public void byId() { + + User user = userMapper.selectByPrimaryKey(1); + log.info(user == null ? null : user.toString()); + } + + /** + * 根据example查询 + */ + @Test + public void exampleQuery() { + Example example = new Example(User.class); + example.and().andLike("name", "%张%"); + userMapper.selectByExample(example).forEach(u -> log.info(u.toString())); + } + + /** + * mybatis 原生查询 + */ + @Test + public void rawMybatisQuery() { + + userMapper.findByGTAge(11).forEach(u -> log.info(u.toString())); + } + + /** + * mybatis 逻辑删除和添加,并测试事务 + */ + @Test + @Rollback + public void logicDelInsert() { + + List users = userMapper.findByName("张麻子"); + if (!users.isEmpty()) { + User user = users.get(0); + userMapper.deleteByPrimaryKey(user.getId()); + user.setId(null); + userMapper.insert(user); + } + } + +} diff --git a/solon-plugin/src/test/resources/app.yml b/solon-plugin/src/test/resources/app.yml new file mode 100644 index 000000000..a76e959f5 --- /dev/null +++ b/solon-plugin/src/test/resources/app.yml @@ -0,0 +1,21 @@ +# 配置数据源 +test: + db1: + jdbcUrl: jdbc:h2:mem:h2DB + driverClassName: org.h2.Driver + username: root + password: root + +mybatis: + db1: + typeAliases: + - "tk.mybatis.solon.test.entity.*" + mappers: + - "classpath:mapper/*.xml" + +# tk mapper的配置 + tk: + mapper: + style: camelhumpandlowercase + safe-update: true + safe-delete: true diff --git a/solon-plugin/src/test/resources/mapper/UserMapper.xml b/solon-plugin/src/test/resources/mapper/UserMapper.xml new file mode 100644 index 000000000..3a279814c --- /dev/null +++ b/solon-plugin/src/test/resources/mapper/UserMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + id, `name`, age, create_time, is_del + + + + \ No newline at end of file From 3813806576b16809a63dc8153c6d9fddd2afa553 Mon Sep 17 00:00:00 2001 From: liuzh Date: Sat, 6 Apr 2024 11:05:11 +0800 Subject: [PATCH 086/109] =?UTF-8?q?=E5=8F=91=E5=B8=834.3.0=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 974cb0737..03c61cbf5 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 4.3.0-SNAPSHOT + 4.3.0 8 8 UTF-8 From 9a34553ea9eeb0c5ef1696b8ba5103f903c4754e Mon Sep 17 00:00:00 2001 From: "trifolium.wang" Date: Thu, 18 Apr 2024 15:23:38 +0800 Subject: [PATCH 087/109] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=AF=B9?= =?UTF-8?q?=E5=8E=9F=E7=94=9FmyBatis=E6=9F=A5=E8=AF=A2=E7=9A=84JPA?= =?UTF-8?q?=E6=98=A0=E5=B0=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/mapper/rawresultmap/CreateDB.sql | 16 +++ .../mapper/rawresultmap/RawResultMapTest.java | 99 +++++++++++++++++++ .../tk/mybatis/mapper/rawresultmap/User.java | 94 ++++++++++++++++++ .../mapper/rawresultmap/UserMapper.java | 25 +++++ .../mapper/rawresultmap/UserMapper.xml | 32 ++++++ .../mybatis-config-rawresultmap.xml | 28 ++++++ .../mapper/mapperhelper/EntityHelper.java | 10 ++ .../mapper/mapperhelper/MapperHelper.java | 38 ++++++- .../mybatis/mapper/session/Configuration.java | 6 +- 9 files changed, 344 insertions(+), 4 deletions(-) create mode 100644 base/src/test/java/tk/mybatis/mapper/rawresultmap/CreateDB.sql create mode 100644 base/src/test/java/tk/mybatis/mapper/rawresultmap/RawResultMapTest.java create mode 100644 base/src/test/java/tk/mybatis/mapper/rawresultmap/User.java create mode 100644 base/src/test/java/tk/mybatis/mapper/rawresultmap/UserMapper.java create mode 100644 base/src/test/java/tk/mybatis/mapper/rawresultmap/UserMapper.xml create mode 100644 base/src/test/java/tk/mybatis/mapper/rawresultmap/mybatis-config-rawresultmap.xml diff --git a/base/src/test/java/tk/mybatis/mapper/rawresultmap/CreateDB.sql b/base/src/test/java/tk/mybatis/mapper/rawresultmap/CreateDB.sql new file mode 100644 index 000000000..659fe7856 --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/rawresultmap/CreateDB.sql @@ -0,0 +1,16 @@ +drop table user if exists; + +create table user +( + id integer NOT NULL PRIMARY KEY, + name varchar(32), + user_name varchar(32), + email varchar(32), + age__int__aa integer, + create_time datetime +); + +INSERT INTO user (id, name, user_name, email, age__int__aa, create_time) +VALUES (1, 'trifolium1', 'wang1', 'email1', 23, now()); +INSERT INTO user (id, name, user_name, email, age__int__aa, create_time) +VALUES (2, 'trifolium2', 'wang2', 'email2', 32, now()); \ No newline at end of file diff --git a/base/src/test/java/tk/mybatis/mapper/rawresultmap/RawResultMapTest.java b/base/src/test/java/tk/mybatis/mapper/rawresultmap/RawResultMapTest.java new file mode 100644 index 000000000..334a7e515 --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/rawresultmap/RawResultMapTest.java @@ -0,0 +1,99 @@ +package tk.mybatis.mapper.rawresultmap; + +import org.apache.ibatis.session.SqlSession; +import org.junit.Assert; +import org.junit.Test; +import tk.mybatis.mapper.base.BaseTest; +import tk.mybatis.mapper.code.Style; +import tk.mybatis.mapper.entity.Config; + +import java.io.IOException; +import java.io.Reader; +import java.net.URL; +import java.util.List; + +/** + * @author liuzh + */ +public class RawResultMapTest extends BaseTest { + + @Override + protected Config getConfig() { + Config config = super.getConfig(); + config.setStyle(Style.normal); + return config; + } + + @Override + protected Reader getConfigFileAsReader() throws IOException { + return toReader(RawResultMapTest.class.getResource("mybatis-config-rawresultmap.xml")); + } + + @Override + protected Reader getSqlFileAsReader() throws IOException { + URL url = RawResultMapTest.class.getResource("CreateDB.sql"); + return toReader(url); + } + + @Test + public void testSelect() { + SqlSession sqlSession = getSqlSession(); + try { + UserMapper mapper = sqlSession.getMapper(UserMapper.class); + + List users; + + System.out.println("------selectAll------"); + users = mapper.selectAll(); + users.forEach(u -> { + System.out.println(u); + Assert.assertNotNull(u.getUname()); + Assert.assertNotNull(u.getAge()); + Assert.assertNotNull(u.getCreateTime()); + Assert.assertNull(u.getEmail()); + }); + System.out.println("------------"); + + System.out.println("------selectRawAnnotation------"); + users = mapper.selectRawAnnotation(); + users.forEach(u -> { + System.out.println(u); + Assert.assertNotNull(u.getUname()); + Assert.assertNotNull(u.getAge()); + Assert.assertNotNull(u.getCreateTime()); + Assert.assertNotNull(u.getEmail()); + }); + System.out.println("------------"); + + System.out.println("------fetchRawResultMap------"); + users = mapper.fetchRawResultMap(); + users.forEach(u -> { + System.out.println(u); + Assert.assertNotNull(u.getUname()); + Assert.assertNotNull(u.getAge()); + Assert.assertNotNull(u.getCreateTime()); + Assert.assertNotNull(u.getEmail()); + }); + System.out.println("------------"); + + System.out.println("------fetchRawResultType------"); + users = mapper.fetchRawResultType(); + users.forEach(u -> { + System.out.println(u); + Assert.assertNotNull(u.getUname()); + Assert.assertNotNull(u.getAge()); + Assert.assertNotNull(u.getCreateTime()); + Assert.assertNotNull(u.getEmail()); + }); + System.out.println("------------"); + + System.out.println("------getMapUser------"); + System.out.println(mapper.getMapUser()); + System.out.println("------------"); + + System.out.println(mapper.selectCount2()); + } finally { + sqlSession.close(); + } + } +} diff --git a/base/src/test/java/tk/mybatis/mapper/rawresultmap/User.java b/base/src/test/java/tk/mybatis/mapper/rawresultmap/User.java new file mode 100644 index 000000000..536fb6aa8 --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/rawresultmap/User.java @@ -0,0 +1,94 @@ +package tk.mybatis.mapper.rawresultmap; + +import tk.mybatis.mapper.annotation.NameStyle; +import tk.mybatis.mapper.code.Style; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Transient; +import java.util.Date; + +/** + * @author liuzh + */ +@NameStyle(Style.camelhump) +@Table(name = "user") +public class User { + + @Id + private Integer id; + + private String name; + + @Column(name = "user_name") + private String uname; + + @Column(name = "age__int__aa") + private Integer age; + + private Date createTime; + + @Transient + private String email; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUname() { + return uname; + } + + public void setUname(String uname) { + this.uname = uname; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", name='" + name + '\'' + + ", uname='" + uname + '\'' + + ", age=" + age + + ", createTime=" + createTime + + ", email='" + email + '\'' + + '}'; + } +} diff --git a/base/src/test/java/tk/mybatis/mapper/rawresultmap/UserMapper.java b/base/src/test/java/tk/mybatis/mapper/rawresultmap/UserMapper.java new file mode 100644 index 000000000..80a6f759b --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/rawresultmap/UserMapper.java @@ -0,0 +1,25 @@ +package tk.mybatis.mapper.rawresultmap; + +import org.apache.ibatis.annotations.Select; +import tk.mybatis.mapper.common.BaseMapper; + +import java.util.List; +import java.util.Map; + +/** + * @author liuzh + */ +public interface UserMapper extends BaseMapper { + + + @Select("SELECT * FROM user") + List selectRawAnnotation(); + + List fetchRawResultType(); + + List fetchRawResultMap(); + + Map getMapUser(); + + Integer selectCount2(); +} diff --git a/base/src/test/java/tk/mybatis/mapper/rawresultmap/UserMapper.xml b/base/src/test/java/tk/mybatis/mapper/rawresultmap/UserMapper.xml new file mode 100644 index 000000000..d23931675 --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/rawresultmap/UserMapper.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/base/src/test/java/tk/mybatis/mapper/rawresultmap/mybatis-config-rawresultmap.xml b/base/src/test/java/tk/mybatis/mapper/rawresultmap/mybatis-config-rawresultmap.xml new file mode 100644 index 000000000..7900bd3f7 --- /dev/null +++ b/base/src/test/java/tk/mybatis/mapper/rawresultmap/mybatis-config-rawresultmap.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/EntityHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/EntityHelper.java index b345bbe76..85053774a 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/EntityHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/EntityHelper.java @@ -71,6 +71,16 @@ public static EntityTable getEntityTable(Class entityClass) { return entityTable; } + /** + * 获取表对象,如果没有则返回Null + * + * @param entityClass + * @return + */ + public static EntityTable getEntityTableOrNull(Class entityClass) { + return entityTableMap.get(entityClass); + } + /** * 获取默认的orderby语句 * diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java index 6d700cbf7..7ed167d4a 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java @@ -32,12 +32,18 @@ import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.ResultMap; +import org.apache.ibatis.mapping.SqlCommandType; +import org.apache.ibatis.reflection.MetaObject; +import org.apache.ibatis.scripting.defaults.RawSqlSource; import org.apache.ibatis.session.Configuration; import tk.mybatis.mapper.MapperException; import tk.mybatis.mapper.annotation.RegisterMapper; import tk.mybatis.mapper.entity.Config; +import tk.mybatis.mapper.entity.EntityTable; import tk.mybatis.mapper.mapperhelper.resolve.EntityResolve; import tk.mybatis.mapper.provider.EmptyProvider; +import tk.mybatis.mapper.util.MetaObjectUtil; import tk.mybatis.mapper.util.StringUtil; import java.lang.reflect.Method; @@ -87,6 +93,7 @@ public MapperHelper(Properties properties) { this(); setProperties(properties); } + /** * 通过通用Mapper接口获取对应的MapperTemplate * @@ -95,7 +102,7 @@ public MapperHelper(Properties properties) { * @throws Exception */ private Collection fromMapperClasses(Class mapperClass) { - Map,MapperTemplate> templateMap = new ConcurrentHashMap, MapperTemplate>(); + Map, MapperTemplate> templateMap = new ConcurrentHashMap, MapperTemplate>(); Method[] methods = mapperClass.getDeclaredMethods(); for (Method method : methods) { Class templateClass = null; @@ -117,7 +124,7 @@ private Collection fromMapperClasses(Class mapperClass) { } MapperTemplate mapperTemplate; try { - mapperTemplate = templateMap.getOrDefault(templateClass,(MapperTemplate) templateClass.getConstructor(Class.class, MapperHelper.class).newInstance(mapperClass, this));; + mapperTemplate = templateMap.getOrDefault(templateClass, (MapperTemplate) templateClass.getConstructor(Class.class, MapperHelper.class).newInstance(mapperClass, this)); templateMap.put(templateClass, mapperTemplate); } catch (Exception e) { log.error("实例化MapperTemplate对象失败:" + e, e); @@ -142,7 +149,7 @@ private Collection fromMapperClasses(Class mapperClass) { public void registerMapper(Class mapperClass) { if (!registerMapper.containsKey(mapperClass)) { registerClass.add(mapperClass); - registerMapper.put(mapperClass,fromMapperClasses(mapperClass)); + registerMapper.put(mapperClass, fromMapperClasses(mapperClass)); } //自动注册继承的接口 Class[] interfaces = mapperClass.getInterfaces(); @@ -291,9 +298,18 @@ public void processConfiguration(Configuration configuration, Class mapperInt */ public void processMappedStatement(MappedStatement ms) { MapperTemplate mapperTemplate = isMapperMethod(ms.getId()); + if (mapperTemplate != null && ms.getSqlSource() instanceof ProviderSqlSource) { setSqlSource(ms, mapperTemplate); } + + // 如果是原生mybatisSqlSource的查询,添加ResultMap + if (ms.getSqlSource() instanceof RawSqlSource + && ms.getSqlCommandType() == SqlCommandType.SELECT) { + if (ms.getResultMaps() != null && !ms.getResultMaps().isEmpty()) { + setRawSqlSourceMapper(ms); + } + } } /** @@ -380,4 +396,20 @@ public void setSqlSource(MappedStatement ms, MapperTemplate mapperTemplate) { } } + /** + * 设置原生Mybatis查询的实体映射, + *

+ * JPA的注解优先级将高于mybatis自动映射 + */ + public void setRawSqlSourceMapper(MappedStatement ms) { + + EntityTable entityTable = EntityHelper.getEntityTableOrNull(ms.getResultMaps().get(0).getType()); + if (entityTable != null) { + List resultMaps = new ArrayList<>(); + resultMaps.add(entityTable.getResultMap(ms.getConfiguration())); + MetaObject metaObject = MetaObjectUtil.forObject(ms); + metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps)); + } + } + } \ No newline at end of file diff --git a/core/src/main/java/tk/mybatis/mapper/session/Configuration.java b/core/src/main/java/tk/mybatis/mapper/session/Configuration.java index a95966290..5547dc1bb 100644 --- a/core/src/main/java/tk/mybatis/mapper/session/Configuration.java +++ b/core/src/main/java/tk/mybatis/mapper/session/Configuration.java @@ -1,6 +1,8 @@ package tk.mybatis.mapper.session; import org.apache.ibatis.mapping.MappedStatement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import tk.mybatis.mapper.entity.Config; import tk.mybatis.mapper.mapperhelper.MapperHelper; @@ -13,6 +15,8 @@ */ public class Configuration extends org.apache.ibatis.session.Configuration { + private final Logger log = LoggerFactory.getLogger(Configuration.class); + private MapperHelper mapperHelper; /** @@ -59,7 +63,7 @@ public void addMappedStatement(MappedStatement ms) { this.mapperHelper.processMappedStatement(ms); } catch (IllegalArgumentException e) { //这里的异常是导致 Spring 启动死循环的关键位置,为了避免后续会吞异常,这里直接输出 - e.printStackTrace(); + log.error(e.getMessage(), e); throw new RuntimeException(e); } } From c52a1e92f1290318733a45422be35839a73ca35f Mon Sep 17 00:00:00 2001 From: "trifolium.wang" Date: Thu, 18 Apr 2024 17:19:35 +0800 Subject: [PATCH 088/109] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E7=A9=BA=E7=9A=84?= =?UTF-8?q?ResultMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tk/mybatis/mapper/mapperhelper/MapperHelper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java index 7ed167d4a..6d12a2b9a 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java @@ -406,9 +406,12 @@ public void setRawSqlSourceMapper(MappedStatement ms) { EntityTable entityTable = EntityHelper.getEntityTableOrNull(ms.getResultMaps().get(0).getType()); if (entityTable != null) { List resultMaps = new ArrayList<>(); - resultMaps.add(entityTable.getResultMap(ms.getConfiguration())); - MetaObject metaObject = MetaObjectUtil.forObject(ms); - metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps)); + ResultMap resultMap = entityTable.getResultMap(ms.getConfiguration()); + if (resultMap != null) { + resultMaps.add(resultMap); + MetaObject metaObject = MetaObjectUtil.forObject(ms); + metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps)); + } } } From da833c78bb6ea9d39c12bc2dda17a672c8ab843c Mon Sep 17 00:00:00 2001 From: Liuzh Date: Thu, 18 Apr 2024 20:09:10 +0800 Subject: [PATCH 089/109] Update release.yml --- .github/workflows/release.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37ac4d42f..0e954b254 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,8 +2,6 @@ name: Publish package to the Maven Central Repository on: push: tags: [ "*" ] - branches: - - master jobs: publish: runs-on: ubuntu-latest @@ -26,4 +24,4 @@ jobs: env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} - run: mvn --batch-mode -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} -P release clean deploy \ No newline at end of file + run: mvn --batch-mode -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} -P release clean deploy From c167b6042cf00788634704f1ad6a92cf1955b4f9 Mon Sep 17 00:00:00 2001 From: gonghao Date: Wed, 10 Jul 2024 14:27:58 +0800 Subject: [PATCH 090/109] =?UTF-8?q?fix:=20generator=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=BC=98=E5=8C=96=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=A1=A8=E6=B3=A8=E9=87=8A=E5=8F=98=E9=87=8F=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E5=A4=9A=E4=BD=99=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generator/README.md | 2 ++ .../tk/mybatis/mapper/generator/TemplateFilePlugin.java | 5 ++++- .../tk/mybatis/mapper/generator/model/TableClass.java | 9 +++++++++ .../mapper/generator/model/TableColumnBuilder.java | 1 + generator/src/main/resources/generator/test-all.ftl | 1 + generator/src/main/resources/generator/test-one.ftl | 1 + 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/generator/README.md b/generator/README.md index 3dd4657a1..6f6117e17 100644 --- a/generator/README.md +++ b/generator/README.md @@ -254,6 +254,7 @@ ${key} - ${props[key]} 实体和表的信息: 表名:${tableClass.tableName} +表注释:${tableClass.remarks} 变量名:${tableClass.variableName} 小写名:${tableClass.lowerCaseName} 类名:${tableClass.shortClassName} @@ -411,6 +412,7 @@ fileName - ${tableClass.shortClassName}Test.txt 实体和表的信息: 表名:user_info +表注释:用户信息表 变量名:userInfo 小写名:userinfo 类名:UserInfo diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java index 6e0bfec64..83aaedddd 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/TemplateFilePlugin.java @@ -130,8 +130,11 @@ protected String read(InputStream inputStream) throws IOException { StringBuffer stringBuffer = new StringBuffer(); String line = reader.readLine(); while (line != null) { - stringBuffer.append(line).append("\n"); + stringBuffer.append(line); line = reader.readLine(); + if (line != null) { + stringBuffer.append("\n"); + } } return stringBuffer.toString(); } diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/model/TableClass.java b/generator/src/main/java/tk/mybatis/mapper/generator/model/TableClass.java index a51f74106..c391b4cd1 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/model/TableClass.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/model/TableClass.java @@ -46,6 +46,7 @@ public class TableClass implements Serializable { private String fullClassName; private String packageName; private FullyQualifiedJavaType type; + private String remarks; private List pkFields; private List baseFields; @@ -147,4 +148,12 @@ public String getVariableName() { public void setVariableName(String variableName) { this.variableName = variableName; } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } } diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/model/TableColumnBuilder.java b/generator/src/main/java/tk/mybatis/mapper/generator/model/TableColumnBuilder.java index 7c0ceca5f..e50acb3ee 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/model/TableColumnBuilder.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/model/TableColumnBuilder.java @@ -48,6 +48,7 @@ public class TableColumnBuilder { public static TableClass build(IntrospectedTable introspectedTable) { TableClass tableClass = new TableClass(); tableClass.setIntrospectedTable(introspectedTable); + tableClass.setRemarks(introspectedTable.getRemarks()); FullyQualifiedTable fullyQualifiedTable = introspectedTable.getFullyQualifiedTable(); tableClass.setTableName(fullyQualifiedTable.getIntrospectedTableName()); diff --git a/generator/src/main/resources/generator/test-all.ftl b/generator/src/main/resources/generator/test-all.ftl index 8fbafe9c8..52fd6c036 100644 --- a/generator/src/main/resources/generator/test-all.ftl +++ b/generator/src/main/resources/generator/test-all.ftl @@ -16,6 +16,7 @@ ${dateTime?string["yyyy-MM-dd HH:mm:ss"]} **************************************************************************************** 实体和表的信息: 表名:${tableClass.tableName} + 表注释:${tableClass.remarks} 变量名:${tableClass.variableName} 小写名:${tableClass.lowerCaseName} 类名:${tableClass.shortClassName} diff --git a/generator/src/main/resources/generator/test-one.ftl b/generator/src/main/resources/generator/test-one.ftl index a26505448..835399063 100644 --- a/generator/src/main/resources/generator/test-one.ftl +++ b/generator/src/main/resources/generator/test-one.ftl @@ -13,6 +13,7 @@ ${dateTime?string["yyyy-MM-dd HH:mm:ss"]} 实体和表的信息: 表名:${tableClass.tableName} +表注释:${tableClass.remarks} 变量名:${tableClass.variableName} 小写名:${tableClass.lowerCaseName} 类名:${tableClass.shortClassName} From 45febda05e98d77d892cc3bea4f414b0ed2ccd37 Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 19 Aug 2024 22:34:54 +0800 Subject: [PATCH 091/109] =?UTF-8?q?5.x=E5=88=86=E6=94=AF=EF=BC=8C=E5=9F=BA?= =?UTF-8?q?=E4=BA=8EJdk17=E5=92=8CSpring=20Boot=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- all/mapper/pom.xml | 4 +-- base/pom.xml | 10 +++---- .../java/tk/mybatis/mapper/base/Country.java | 2 +- .../tk/mybatis/mapper/base/genid/Country.java | 2 +- .../tk/mybatis/mapper/base/genid/User.java | 2 +- .../mapper/defaultenumtypehandler/User.java | 2 +- .../generatedvalue/UserAutoIncrement.java | 8 ++--- .../UserAutoIncrementIdentity.java | 2 +- .../mapper/generatedvalue/UserSqlAfter.java | 2 +- .../mapper/helper/FieldHelperTest.java | 2 +- .../tk/mybatis/mapper/helper/FieldTest.java | 4 +-- .../issues/_216_datetime/TimeModel.java | 4 +-- .../issues/_216_datetime/TimeModel2.java | 4 +-- .../issues/_216_datetime/TimeModel3.java | 4 +-- .../mapper/keysql/UserAutoIncrement.java | 6 ++-- .../keysql/UserAutoIncrementIdentity.java | 6 ++-- .../mybatis/mapper/keysql/UserSqlAfter.java | 6 ++-- .../mybatis/mapper/keysql/UserSqlBefore.java | 4 +-- .../mybatis/mapper/model/BaseLogicDelete.java | 8 ++--- .../java/tk/mybatis/mapper/model/Country.java | 4 +-- .../tk/mybatis/mapper/model/Country2.java | 6 ++-- .../tk/mybatis/mapper/model/CountryI.java | 6 ++-- .../tk/mybatis/mapper/model/CountryJDBC.java | 6 ++-- .../tk/mybatis/mapper/model/CountryT.java | 4 +-- .../mybatis/mapper/model/CountryVersion.java | 2 +- .../java/tk/mybatis/mapper/model/Entity.java | 4 +-- .../java/tk/mybatis/mapper/model/TbUser.java | 2 +- .../mapper/model/TbUserLogicDelete.java | 4 +-- .../tk/mybatis/mapper/model/UserInfo.java | 6 ++-- .../tk/mybatis/mapper/model/UserInfoAble.java | 2 +- .../tk/mybatis/mapper/model/UserInfoMap.java | 6 ++-- .../tk/mybatis/mapper/model/UserLogin.java | 6 ++-- .../tk/mybatis/mapper/model/UserLogin2.java | 2 +- .../mybatis/mapper/model/UserLogin2Key.java | 6 ++-- .../tk/mybatis/mapper/model/UserParent.java | 2 +- .../tk/mybatis/mapper/rawresultmap/User.java | 8 ++--- .../tk/mybatis/mapper/typehandler/User.java | 2 +- .../tk/mybatis/mapper/typehandler/User2.java | 6 ++-- .../tk/mybatis/mapper/version/UserInt.java | 4 +-- .../mybatis/mapper/version/UserTimestamp.java | 4 +-- core/pom.xml | 4 +-- .../mapper/annotation/LogicDelete.java | 8 +++-- .../java/tk/mybatis/mapper/code/ORDER.java | 15 ++++++++-- .../java/tk/mybatis/mapper/code/Style.java | 30 +++++++++++++++---- .../tk/mybatis/mapper/entity/EntityTable.java | 2 +- .../mapper/mapperhelper/FieldHelper.java | 2 +- .../resolve/DefaultEntityResolve.java | 2 +- .../mybatis/mapper/annotation/ColumnTest.java | 2 +- .../tk/mybatis/mapper/annotation/IdTest.java | 2 +- .../mybatis/mapper/annotation/TableTest.java | 2 +- .../mapperhelper/ComplexEntityTest.java | 4 +-- .../mapper/mapperhelper/SqlHelperTest.java | 2 +- extra/pom.xml | 5 ---- .../tk/mybatis/mapper/additional/Country.java | 2 +- .../mapper/additional/aggregation/User.java | 4 +-- .../mapper/additional/delete/Course.java | 4 +-- .../dialect/oracle/DemoCountry.java | 2 +- .../mapper/additional/insertlist/User.java | 2 +- .../mapper/additional/select/Book.java | 2 +- .../additional/update/force/CountryInt.java | 2 +- generator/pom.xml | 8 ++--- pom.xml | 28 ++++++++--------- solon-plugin/pom.xml | 4 +-- .../tk/mybatis/solon/test/entity/User.java | 8 ++--- .../tk/mybatis/sample/domain/Country.java | 2 +- .../tk/mybatis/sample/domain/Country.java | 2 +- spring-boot-starter/pom.xml | 10 ++----- spring/pom.xml | 4 +-- .../tk/mybatis/mapper/annotation/Country.java | 2 +- .../mybatis/mapper/configuration/Country.java | 2 +- .../java/tk/mybatis/mapper/xml/Country.java | 2 +- .../mapper/weekend/entity/Country.java | 4 +-- .../mybatis/mapper/weekend/entity/User.java | 2 +- 73 files changed, 185 insertions(+), 165 deletions(-) diff --git a/all/mapper/pom.xml b/all/mapper/pom.xml index c09413976..041e7375e 100644 --- a/all/mapper/pom.xml +++ b/all/mapper/pom.xml @@ -39,8 +39,8 @@ - javax.persistence - javax.persistence-api + jakarta.persistence + jakarta.persistence-api tk.mybatis diff --git a/base/pom.xml b/base/pom.xml index 3b63c4ef0..9fde3310a 100644 --- a/base/pom.xml +++ b/base/pom.xml @@ -40,8 +40,8 @@ - javax.persistence - javax.persistence-api + jakarta.persistence + jakarta.persistence-api @@ -58,9 +58,9 @@ - mysql - mysql-connector-java - 8.0.21 + com.mysql + mysql-connector-j + 8.0.33 test diff --git a/base/src/test/java/tk/mybatis/mapper/base/Country.java b/base/src/test/java/tk/mybatis/mapper/base/Country.java index d8c9a6050..c03435aef 100644 --- a/base/src/test/java/tk/mybatis/mapper/base/Country.java +++ b/base/src/test/java/tk/mybatis/mapper/base/Country.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.base; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/base/src/test/java/tk/mybatis/mapper/base/genid/Country.java b/base/src/test/java/tk/mybatis/mapper/base/genid/Country.java index 250b41995..59a0cab5e 100644 --- a/base/src/test/java/tk/mybatis/mapper/base/genid/Country.java +++ b/base/src/test/java/tk/mybatis/mapper/base/genid/Country.java @@ -26,7 +26,7 @@ import tk.mybatis.mapper.annotation.KeySql; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/base/src/test/java/tk/mybatis/mapper/base/genid/User.java b/base/src/test/java/tk/mybatis/mapper/base/genid/User.java index b5121484d..6bd88aef1 100644 --- a/base/src/test/java/tk/mybatis/mapper/base/genid/User.java +++ b/base/src/test/java/tk/mybatis/mapper/base/genid/User.java @@ -2,7 +2,7 @@ import tk.mybatis.mapper.annotation.KeySql; -import javax.persistence.Id; +import jakarta.persistence.Id; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/User.java b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/User.java index 2e57b441e..791696171 100644 --- a/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/User.java +++ b/base/src/test/java/tk/mybatis/mapper/defaultenumtypehandler/User.java @@ -1,6 +1,6 @@ package tk.mybatis.mapper.defaultenumtypehandler; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserAutoIncrement.java b/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserAutoIncrement.java index 216e2f0b4..0822c58bf 100644 --- a/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserAutoIncrement.java +++ b/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserAutoIncrement.java @@ -1,9 +1,9 @@ package tk.mybatis.mapper.generatedvalue; -import javax.persistence.Column; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserAutoIncrementIdentity.java b/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserAutoIncrementIdentity.java index 8a28544f4..9f9aa1264 100644 --- a/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserAutoIncrementIdentity.java +++ b/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserAutoIncrementIdentity.java @@ -1,6 +1,6 @@ package tk.mybatis.mapper.generatedvalue; -import javax.persistence.*; +import jakarta.persistence.*; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserSqlAfter.java b/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserSqlAfter.java index 979dde4da..caa604cf3 100644 --- a/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserSqlAfter.java +++ b/base/src/test/java/tk/mybatis/mapper/generatedvalue/UserSqlAfter.java @@ -1,6 +1,6 @@ package tk.mybatis.mapper.generatedvalue; -import javax.persistence.*; +import jakarta.persistence.*; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/helper/FieldHelperTest.java b/base/src/test/java/tk/mybatis/mapper/helper/FieldHelperTest.java index f07a83a67..1e2dc79f4 100644 --- a/base/src/test/java/tk/mybatis/mapper/helper/FieldHelperTest.java +++ b/base/src/test/java/tk/mybatis/mapper/helper/FieldHelperTest.java @@ -29,7 +29,7 @@ import tk.mybatis.mapper.mapperhelper.FieldHelper; import tk.mybatis.mapper.model.Country; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.beans.IntrospectionException; import java.util.List; diff --git a/base/src/test/java/tk/mybatis/mapper/helper/FieldTest.java b/base/src/test/java/tk/mybatis/mapper/helper/FieldTest.java index 19c51d7a0..5e3530bba 100644 --- a/base/src/test/java/tk/mybatis/mapper/helper/FieldTest.java +++ b/base/src/test/java/tk/mybatis/mapper/helper/FieldTest.java @@ -29,8 +29,8 @@ import tk.mybatis.mapper.mapperhelper.FieldHelper; import tk.mybatis.mapper.model.Country; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; diff --git a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel.java b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel.java index fad28a5ed..32bcad037 100644 --- a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel.java +++ b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel.java @@ -1,7 +1,7 @@ package tk.mybatis.mapper.issues._216_datetime; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.io.Serializable; import java.util.Date; diff --git a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel2.java b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel2.java index a45538f3c..9bafddff8 100644 --- a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel2.java +++ b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel2.java @@ -1,7 +1,7 @@ package tk.mybatis.mapper.issues._216_datetime; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.io.Serializable; import java.sql.Timestamp; import java.util.Date; diff --git a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel3.java b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel3.java index 424aec9f2..5a22b61d7 100644 --- a/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel3.java +++ b/base/src/test/java/tk/mybatis/mapper/issues/_216_datetime/TimeModel3.java @@ -3,8 +3,8 @@ import org.apache.ibatis.type.JdbcType; import tk.mybatis.mapper.annotation.ColumnType; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.io.Serializable; import java.util.Date; diff --git a/base/src/test/java/tk/mybatis/mapper/keysql/UserAutoIncrement.java b/base/src/test/java/tk/mybatis/mapper/keysql/UserAutoIncrement.java index 3293e452b..74425ba60 100644 --- a/base/src/test/java/tk/mybatis/mapper/keysql/UserAutoIncrement.java +++ b/base/src/test/java/tk/mybatis/mapper/keysql/UserAutoIncrement.java @@ -2,9 +2,9 @@ import tk.mybatis.mapper.annotation.KeySql; -import javax.persistence.Column; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/keysql/UserAutoIncrementIdentity.java b/base/src/test/java/tk/mybatis/mapper/keysql/UserAutoIncrementIdentity.java index 188aa40d3..9bced705a 100644 --- a/base/src/test/java/tk/mybatis/mapper/keysql/UserAutoIncrementIdentity.java +++ b/base/src/test/java/tk/mybatis/mapper/keysql/UserAutoIncrementIdentity.java @@ -3,9 +3,9 @@ import tk.mybatis.mapper.annotation.KeySql; import tk.mybatis.mapper.code.IdentityDialect; -import javax.persistence.Column; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/keysql/UserSqlAfter.java b/base/src/test/java/tk/mybatis/mapper/keysql/UserSqlAfter.java index 707236b7c..a615e5922 100644 --- a/base/src/test/java/tk/mybatis/mapper/keysql/UserSqlAfter.java +++ b/base/src/test/java/tk/mybatis/mapper/keysql/UserSqlAfter.java @@ -3,9 +3,9 @@ import tk.mybatis.mapper.annotation.KeySql; import tk.mybatis.mapper.code.ORDER; -import javax.persistence.Column; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/keysql/UserSqlBefore.java b/base/src/test/java/tk/mybatis/mapper/keysql/UserSqlBefore.java index d2644d545..fbb536c3a 100644 --- a/base/src/test/java/tk/mybatis/mapper/keysql/UserSqlBefore.java +++ b/base/src/test/java/tk/mybatis/mapper/keysql/UserSqlBefore.java @@ -3,8 +3,8 @@ import tk.mybatis.mapper.annotation.KeySql; import tk.mybatis.mapper.code.ORDER; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/model/BaseLogicDelete.java b/base/src/test/java/tk/mybatis/mapper/model/BaseLogicDelete.java index 15f2c5c7f..e9f8cf0e7 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/BaseLogicDelete.java +++ b/base/src/test/java/tk/mybatis/mapper/model/BaseLogicDelete.java @@ -2,10 +2,10 @@ import tk.mybatis.mapper.annotation.LogicDelete; -import javax.persistence.Column; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; public class BaseLogicDelete { diff --git a/base/src/test/java/tk/mybatis/mapper/model/Country.java b/base/src/test/java/tk/mybatis/mapper/model/Country.java index 089f6bc5c..8130118bf 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/Country.java +++ b/base/src/test/java/tk/mybatis/mapper/model/Country.java @@ -27,8 +27,8 @@ import tk.mybatis.mapper.annotation.Order; import tk.mybatis.mapper.entity.IDynamicTableName; -import javax.persistence.Column; -import javax.persistence.Transient; +import jakarta.persistence.Column; +import jakarta.persistence.Transient; import java.io.Serializable; import java.util.List; diff --git a/base/src/test/java/tk/mybatis/mapper/model/Country2.java b/base/src/test/java/tk/mybatis/mapper/model/Country2.java index a1e55efa1..54febb952 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/Country2.java +++ b/base/src/test/java/tk/mybatis/mapper/model/Country2.java @@ -24,9 +24,9 @@ package tk.mybatis.mapper.model; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; /** * Description: Country diff --git a/base/src/test/java/tk/mybatis/mapper/model/CountryI.java b/base/src/test/java/tk/mybatis/mapper/model/CountryI.java index e0e37a46b..0c5b0c59c 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/CountryI.java +++ b/base/src/test/java/tk/mybatis/mapper/model/CountryI.java @@ -27,9 +27,9 @@ import tk.mybatis.mapper.annotation.NameStyle; import tk.mybatis.mapper.code.Style; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; /** * Description: Country diff --git a/base/src/test/java/tk/mybatis/mapper/model/CountryJDBC.java b/base/src/test/java/tk/mybatis/mapper/model/CountryJDBC.java index 27e68fad5..c90065860 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/CountryJDBC.java +++ b/base/src/test/java/tk/mybatis/mapper/model/CountryJDBC.java @@ -24,9 +24,9 @@ package tk.mybatis.mapper.model; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * Description: Country diff --git a/base/src/test/java/tk/mybatis/mapper/model/CountryT.java b/base/src/test/java/tk/mybatis/mapper/model/CountryT.java index 1c76d7ed6..c4d4b18c9 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/CountryT.java +++ b/base/src/test/java/tk/mybatis/mapper/model/CountryT.java @@ -24,8 +24,8 @@ package tk.mybatis.mapper.model; -import javax.persistence.Id; -import javax.persistence.Transient; +import jakarta.persistence.Id; +import jakarta.persistence.Transient; /** * Description: Country diff --git a/base/src/test/java/tk/mybatis/mapper/model/CountryVersion.java b/base/src/test/java/tk/mybatis/mapper/model/CountryVersion.java index bd32873c6..41ab7da9b 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/CountryVersion.java +++ b/base/src/test/java/tk/mybatis/mapper/model/CountryVersion.java @@ -26,7 +26,7 @@ import tk.mybatis.mapper.annotation.Version; -import javax.persistence.Table; +import jakarta.persistence.Table; /** * Description: Country diff --git a/base/src/test/java/tk/mybatis/mapper/model/Entity.java b/base/src/test/java/tk/mybatis/mapper/model/Entity.java index 5136ee947..20ebde0e2 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/Entity.java +++ b/base/src/test/java/tk/mybatis/mapper/model/Entity.java @@ -26,8 +26,8 @@ import tk.mybatis.mapper.annotation.Order; -import javax.persistence.Id; -import javax.persistence.Transient; +import jakarta.persistence.Id; +import jakarta.persistence.Transient; import java.io.Serializable; /** diff --git a/base/src/test/java/tk/mybatis/mapper/model/TbUser.java b/base/src/test/java/tk/mybatis/mapper/model/TbUser.java index 6cc6e268c..b5eb2996e 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/TbUser.java +++ b/base/src/test/java/tk/mybatis/mapper/model/TbUser.java @@ -1,6 +1,6 @@ package tk.mybatis.mapper.model; -import javax.persistence.*; +import jakarta.persistence.*; @Table(name = "tb_user") public class TbUser { diff --git a/base/src/test/java/tk/mybatis/mapper/model/TbUserLogicDelete.java b/base/src/test/java/tk/mybatis/mapper/model/TbUserLogicDelete.java index e4a47d1e7..aecc63c6e 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/TbUserLogicDelete.java +++ b/base/src/test/java/tk/mybatis/mapper/model/TbUserLogicDelete.java @@ -1,7 +1,7 @@ package tk.mybatis.mapper.model; -import javax.persistence.Column; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Table; @Table(name = "tb_user") public class TbUserLogicDelete extends BaseLogicDelete { diff --git a/base/src/test/java/tk/mybatis/mapper/model/UserInfo.java b/base/src/test/java/tk/mybatis/mapper/model/UserInfo.java index d391f1ee6..7a317a73e 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/UserInfo.java +++ b/base/src/test/java/tk/mybatis/mapper/model/UserInfo.java @@ -24,9 +24,9 @@ package tk.mybatis.mapper.model; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/base/src/test/java/tk/mybatis/mapper/model/UserInfoAble.java b/base/src/test/java/tk/mybatis/mapper/model/UserInfoAble.java index 31dba0f3e..a1cdad193 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/UserInfoAble.java +++ b/base/src/test/java/tk/mybatis/mapper/model/UserInfoAble.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.model; -import javax.persistence.*; +import jakarta.persistence.*; import java.io.Serializable; /** diff --git a/base/src/test/java/tk/mybatis/mapper/model/UserInfoMap.java b/base/src/test/java/tk/mybatis/mapper/model/UserInfoMap.java index 851329204..e0f3a2ff0 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/UserInfoMap.java +++ b/base/src/test/java/tk/mybatis/mapper/model/UserInfoMap.java @@ -24,9 +24,9 @@ package tk.mybatis.mapper.model; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; import java.io.Serializable; import java.util.HashMap; diff --git a/base/src/test/java/tk/mybatis/mapper/model/UserLogin.java b/base/src/test/java/tk/mybatis/mapper/model/UserLogin.java index bde7eb6f1..9ca5cd2d7 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/UserLogin.java +++ b/base/src/test/java/tk/mybatis/mapper/model/UserLogin.java @@ -24,9 +24,9 @@ package tk.mybatis.mapper.model; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; import java.util.Date; /** diff --git a/base/src/test/java/tk/mybatis/mapper/model/UserLogin2.java b/base/src/test/java/tk/mybatis/mapper/model/UserLogin2.java index 747d3bf2b..fd572dd0f 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/UserLogin2.java +++ b/base/src/test/java/tk/mybatis/mapper/model/UserLogin2.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.model; -import javax.persistence.Table; +import jakarta.persistence.Table; import java.util.Date; /** diff --git a/base/src/test/java/tk/mybatis/mapper/model/UserLogin2Key.java b/base/src/test/java/tk/mybatis/mapper/model/UserLogin2Key.java index 353a77941..ab1541131 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/UserLogin2Key.java +++ b/base/src/test/java/tk/mybatis/mapper/model/UserLogin2Key.java @@ -24,9 +24,9 @@ package tk.mybatis.mapper.model; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; /** * Created by liuzh on 2014/11/21. diff --git a/base/src/test/java/tk/mybatis/mapper/model/UserParent.java b/base/src/test/java/tk/mybatis/mapper/model/UserParent.java index f52317aab..8ec21539d 100644 --- a/base/src/test/java/tk/mybatis/mapper/model/UserParent.java +++ b/base/src/test/java/tk/mybatis/mapper/model/UserParent.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.model; -import javax.persistence.Column; +import jakarta.persistence.Column; /** * @author liuzh_3nofxnp diff --git a/base/src/test/java/tk/mybatis/mapper/rawresultmap/User.java b/base/src/test/java/tk/mybatis/mapper/rawresultmap/User.java index 536fb6aa8..02e537b28 100644 --- a/base/src/test/java/tk/mybatis/mapper/rawresultmap/User.java +++ b/base/src/test/java/tk/mybatis/mapper/rawresultmap/User.java @@ -3,10 +3,10 @@ import tk.mybatis.mapper.annotation.NameStyle; import tk.mybatis.mapper.code.Style; -import javax.persistence.Column; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; +import jakarta.persistence.Column; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; import java.util.Date; /** diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/User.java b/base/src/test/java/tk/mybatis/mapper/typehandler/User.java index e42819271..503fad231 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/User.java +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/User.java @@ -2,7 +2,7 @@ import tk.mybatis.mapper.annotation.ColumnType; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/base/src/test/java/tk/mybatis/mapper/typehandler/User2.java b/base/src/test/java/tk/mybatis/mapper/typehandler/User2.java index fdb6287fd..6d9ca114e 100644 --- a/base/src/test/java/tk/mybatis/mapper/typehandler/User2.java +++ b/base/src/test/java/tk/mybatis/mapper/typehandler/User2.java @@ -1,8 +1,8 @@ package tk.mybatis.mapper.typehandler; -import javax.persistence.Column; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.io.Serializable; /** diff --git a/base/src/test/java/tk/mybatis/mapper/version/UserInt.java b/base/src/test/java/tk/mybatis/mapper/version/UserInt.java index 6ab7261bc..184865512 100644 --- a/base/src/test/java/tk/mybatis/mapper/version/UserInt.java +++ b/base/src/test/java/tk/mybatis/mapper/version/UserInt.java @@ -2,8 +2,8 @@ import tk.mybatis.mapper.annotation.Version; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * @author liuzh diff --git a/base/src/test/java/tk/mybatis/mapper/version/UserTimestamp.java b/base/src/test/java/tk/mybatis/mapper/version/UserTimestamp.java index d4992249b..30542347b 100644 --- a/base/src/test/java/tk/mybatis/mapper/version/UserTimestamp.java +++ b/base/src/test/java/tk/mybatis/mapper/version/UserTimestamp.java @@ -2,8 +2,8 @@ import tk.mybatis.mapper.annotation.Version; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.sql.Timestamp; /** diff --git a/core/pom.xml b/core/pom.xml index 603d18a6a..db365236a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -40,8 +40,8 @@ - javax.persistence - javax.persistence-api + jakarta.persistence + jakarta.persistence-api diff --git a/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java b/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java index ecd482ecb..f8520fd9e 100644 --- a/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java +++ b/core/src/main/java/tk/mybatis/mapper/annotation/LogicDelete.java @@ -14,12 +14,16 @@ int isDeletedValue() default 1; - // 优先级比isDeletedValue更高 表示以null作为删除记录的标识 + /** + * 优先级比isDeletedValue更高 表示以null作为删除记录的标识 + */ boolean isNullForDeletedValue() default false; int notDeletedValue() default 0; - // 优先级比notDeletedValue更高 表示以null作为未删除记录的标识 + /** + * 优先级比notDeletedValue更高 表示以null作为未删除记录的标识 + */ boolean isNullForNotDeletedValue() default false; } diff --git a/core/src/main/java/tk/mybatis/mapper/code/ORDER.java b/core/src/main/java/tk/mybatis/mapper/code/ORDER.java index a43ba0906..e6d7b1682 100644 --- a/core/src/main/java/tk/mybatis/mapper/code/ORDER.java +++ b/core/src/main/java/tk/mybatis/mapper/code/ORDER.java @@ -6,7 +6,16 @@ * @author liuzh */ public enum ORDER { - AFTER, //insert 后执行 SQL - BEFORE,//insert 前执行 SQL - DEFAULT//使用全局配置 + /** + * insert 后执行 SQL + */ + AFTER, + /** + * insert 前执行 SQL + */ + BEFORE, + /** + * 使用全局配置 + */ + DEFAULT } diff --git a/core/src/main/java/tk/mybatis/mapper/code/Style.java b/core/src/main/java/tk/mybatis/mapper/code/Style.java index 9aa6ad734..f81fff413 100644 --- a/core/src/main/java/tk/mybatis/mapper/code/Style.java +++ b/core/src/main/java/tk/mybatis/mapper/code/Style.java @@ -28,10 +28,28 @@ * 字段转换方式 */ public enum Style { - normal, //原值 - camelhump, //驼峰转下划线 - uppercase, //转换为大写 - lowercase, //转换为小写 - camelhumpAndUppercase, //驼峰转下划线大写形式 - camelhumpAndLowercase, //驼峰转下划线小写形式 + /** + * 原值 + */ + normal, + /** + * 驼峰转下划线 + */ + camelhump, + /** + * 转换为大写 + */ + uppercase, + /** + * 转换为小写 + */ + lowercase, + /** + * 驼峰转下划线大写形式 + */ + camelhumpAndUppercase, + /** + * 驼峰转下划线小写形式 + */ + camelhumpAndLowercase, } diff --git a/core/src/main/java/tk/mybatis/mapper/entity/EntityTable.java b/core/src/main/java/tk/mybatis/mapper/entity/EntityTable.java index 6be558ddf..d5a4c24ff 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/EntityTable.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/EntityTable.java @@ -33,7 +33,7 @@ import tk.mybatis.mapper.MapperException; import tk.mybatis.mapper.util.StringUtil; -import javax.persistence.Table; +import jakarta.persistence.Table; import java.lang.reflect.Constructor; import java.util.*; import java.util.regex.Matcher; diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java index c09051423..7f73e9239 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java @@ -27,7 +27,7 @@ import tk.mybatis.mapper.MapperException; import tk.mybatis.mapper.entity.EntityField; -import javax.persistence.Entity; +import jakarta.persistence.Entity; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java index 7097f6394..fca580b50 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/resolve/DefaultEntityResolve.java @@ -23,7 +23,7 @@ import tk.mybatis.mapper.util.SqlReservedWords; import tk.mybatis.mapper.util.StringUtil; -import javax.persistence.*; +import jakarta.persistence.*; import java.text.MessageFormat; import java.util.LinkedHashSet; import java.util.List; diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTest.java index e9bcf308e..7e055964e 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/ColumnTest.java @@ -13,7 +13,7 @@ import tk.mybatis.mapper.entity.EntityTable; import tk.mybatis.mapper.mapperhelper.EntityHelper; -import javax.persistence.Column; +import jakarta.persistence.Column; import java.util.Set; /** diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/IdTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/IdTest.java index c4cc9473a..89e5e7039 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/IdTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/IdTest.java @@ -13,7 +13,7 @@ import tk.mybatis.mapper.mapperhelper.EntityHelper; import tk.mybatis.mapper.mapperhelper.SqlHelper; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.util.Set; /** diff --git a/core/src/test/java/tk/mybatis/mapper/annotation/TableTest.java b/core/src/test/java/tk/mybatis/mapper/annotation/TableTest.java index 60c090655..1af61e3cf 100644 --- a/core/src/test/java/tk/mybatis/mapper/annotation/TableTest.java +++ b/core/src/test/java/tk/mybatis/mapper/annotation/TableTest.java @@ -8,7 +8,7 @@ import tk.mybatis.mapper.entity.EntityTable; import tk.mybatis.mapper.mapperhelper.EntityHelper; -import javax.persistence.Table; +import jakarta.persistence.Table; /** * @author liuzh diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java index edfba3400..3ae534ed1 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java @@ -15,8 +15,8 @@ import tk.mybatis.mapper.entity.Config; import tk.mybatis.mapper.entity.EntityTable; -import javax.persistence.Column; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.Id; import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java index 1589e20de..5795a8755 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java @@ -7,7 +7,7 @@ import tk.mybatis.mapper.code.Style; import tk.mybatis.mapper.entity.Config; -import javax.persistence.*; +import jakarta.persistence.*; public class SqlHelperTest { diff --git a/extra/pom.xml b/extra/pom.xml index f95bf743b..4be2443f9 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -36,11 +36,6 @@ mapper-extra Mybatis 通用 Mapper 扩展方法 - - 8 - 8 - - org.mybatis diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/Country.java b/extra/src/test/java/tk/mybatis/mapper/additional/Country.java index 7cc80c4c6..78b581ff8 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/Country.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/Country.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.additional; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/User.java b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/User.java index 35f0c52ea..be57d8382 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/User.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/aggregation/User.java @@ -24,8 +24,8 @@ package tk.mybatis.mapper.additional.aggregation; -import javax.persistence.Id; -import javax.persistence.Transient; +import jakarta.persistence.Id; +import jakarta.persistence.Transient; import java.io.Serializable; /** diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java b/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java index 57c3c237e..278714ef5 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/Course.java @@ -2,8 +2,8 @@ import tk.mybatis.mapper.annotation.LogicDelete; -import javax.persistence.Column; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.Id; import java.time.LocalDate; /** diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/DemoCountry.java b/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/DemoCountry.java index 93b05399e..8bc13fc34 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/DemoCountry.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/dialect/oracle/DemoCountry.java @@ -3,7 +3,7 @@ import tk.mybatis.mapper.additional.insertlist.UUIdGenId; import tk.mybatis.mapper.annotation.KeySql; -import javax.persistence.Id; +import jakarta.persistence.Id; /** * @description: diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/User.java b/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/User.java index 3f04c739c..84f7ff8d3 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/User.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/insertlist/User.java @@ -26,7 +26,7 @@ import tk.mybatis.mapper.annotation.KeySql; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java b/extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java index 05557600e..d883b367e 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java @@ -1,6 +1,6 @@ package tk.mybatis.mapper.additional.select; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.time.LocalDate; /** diff --git a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CountryInt.java b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CountryInt.java index 45b18293d..7a79554a2 100644 --- a/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CountryInt.java +++ b/extra/src/test/java/tk/mybatis/mapper/additional/update/force/CountryInt.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.additional.update.force; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/generator/pom.xml b/generator/pom.xml index 58872fbea..84394ab1c 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -37,8 +37,8 @@ Mybatis 通用 Mapper 代码生成器 - 2.3.28 - 1.4.1 + 2.3.33 + 1.4.2 @@ -73,8 +73,8 @@ test - javax.persistence - javax.persistence-api + jakarta.persistence + jakarta.persistence-api test diff --git a/pom.xml b/pom.xml index 03c61cbf5..9af44aa0e 100644 --- a/pom.xml +++ b/pom.xml @@ -35,20 +35,19 @@ https://mybatis.io - 4.3.0 - 8 - 8 + 5.0.0-SNAPSHOT + 17 + 17 UTF-8 UTF-8 - -Dfile.encoding=UTF-8 - 2.2 - 1.7.26 - 3.5.11 + 3.1.0 + 2.0.16 + 3.5.16 4.13.2 - 2.5.2 - 1.2.11 + 2.7.3 + 1.5.7 @@ -68,24 +67,21 @@ - javax.persistence - javax.persistence-api + jakarta.persistence + jakarta.persistence-api ${jpa.version} - org.mybatis mybatis ${mybatis.version} - provided org.slf4j slf4j-api ${slf4j.version} - provided @@ -111,6 +107,10 @@ + + org.slf4j + slf4j-api + junit diff --git a/solon-plugin/pom.xml b/solon-plugin/pom.xml index 832f263a8..1a0baf882 100644 --- a/solon-plugin/pom.xml +++ b/solon-plugin/pom.xml @@ -72,14 +72,14 @@ com.h2database h2 - 1.4.200 + 2.3.232 test com.zaxxer HikariCP - 4.0.3 + 5.1.0 test diff --git a/solon-plugin/src/test/java/tk/mybatis/solon/test/entity/User.java b/solon-plugin/src/test/java/tk/mybatis/solon/test/entity/User.java index 900149620..bb27cf852 100644 --- a/solon-plugin/src/test/java/tk/mybatis/solon/test/entity/User.java +++ b/solon-plugin/src/test/java/tk/mybatis/solon/test/entity/User.java @@ -3,10 +3,10 @@ import org.noear.snack.core.utils.DateUtil; import tk.mybatis.mapper.annotation.LogicDelete; -import javax.persistence.Column; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.util.Date; @Table(name = "`user`") diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/java/tk/mybatis/sample/domain/Country.java b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/java/tk/mybatis/sample/domain/Country.java index 3e7e12bf9..a1a072bec 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/java/tk/mybatis/sample/domain/Country.java +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/java/tk/mybatis/sample/domain/Country.java @@ -27,7 +27,7 @@ import org.apache.ibatis.type.JdbcType; import tk.mybatis.mapper.annotation.ColumnType; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/domain/Country.java b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/domain/Country.java index 3e7e12bf9..a1a072bec 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/domain/Country.java +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/domain/Country.java @@ -27,7 +27,7 @@ import org.apache.ibatis.type.JdbcType; import tk.mybatis.mapper.annotation.ColumnType; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; /** diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml index b10847a46..a53feb6d5 100644 --- a/spring-boot-starter/pom.xml +++ b/spring-boot-starter/pom.xml @@ -45,9 +45,8 @@ - 3.5.9 - 2.0.7 - 2.6.4 + 3.0.4 + 3.3.2 @@ -102,11 +101,6 @@ mapper-extra ${project.version} - - org.mybatis - mybatis - ${mybatis.version} - org.mybatis mybatis-spring diff --git a/spring/pom.xml b/spring/pom.xml index a5389039f..e3683dbb3 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -37,8 +37,8 @@ Mybatis 通用 Mapper 和 Spring 集成 - 4.3.30.RELEASE - 1.3.3 + 6.1.11 + 3.0.4 diff --git a/spring/src/test/java/tk/mybatis/mapper/annotation/Country.java b/spring/src/test/java/tk/mybatis/mapper/annotation/Country.java index 069b254d0..f8432ba52 100644 --- a/spring/src/test/java/tk/mybatis/mapper/annotation/Country.java +++ b/spring/src/test/java/tk/mybatis/mapper/annotation/Country.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.annotation; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; public class Country implements Serializable { diff --git a/spring/src/test/java/tk/mybatis/mapper/configuration/Country.java b/spring/src/test/java/tk/mybatis/mapper/configuration/Country.java index 28f2e1221..2d6b6891d 100644 --- a/spring/src/test/java/tk/mybatis/mapper/configuration/Country.java +++ b/spring/src/test/java/tk/mybatis/mapper/configuration/Country.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.configuration; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; public class Country implements Serializable { diff --git a/spring/src/test/java/tk/mybatis/mapper/xml/Country.java b/spring/src/test/java/tk/mybatis/mapper/xml/Country.java index 0baa38233..260b8180d 100644 --- a/spring/src/test/java/tk/mybatis/mapper/xml/Country.java +++ b/spring/src/test/java/tk/mybatis/mapper/xml/Country.java @@ -24,7 +24,7 @@ package tk.mybatis.mapper.xml; -import javax.persistence.Id; +import jakarta.persistence.Id; import java.io.Serializable; public class Country implements Serializable { diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/Country.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/Country.java index 62e7700c8..48dc363c2 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/Country.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/Country.java @@ -25,8 +25,8 @@ package tk.mybatis.mapper.weekend.entity; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.io.Serializable; @Table() diff --git a/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/User.java b/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/User.java index 8766af9d3..9258a5697 100644 --- a/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/User.java +++ b/weekend/src/test/java/tk/mybatis/mapper/weekend/entity/User.java @@ -25,7 +25,7 @@ package tk.mybatis.mapper.weekend.entity; -import javax.persistence.Table; +import jakarta.persistence.Table; /** * @author Frank From 76e46531dd4c548dac574e5b21733db62e2f3368 Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 19 Aug 2024 23:25:28 +0800 Subject: [PATCH 092/109] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E5=A4=84=E7=90=86=E7=BC=96=E8=AF=91=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- all/mapper/pom.xml | 2 +- all/pom.xml | 2 +- core/pom.xml | 4 ++++ generator/pom.xml | 4 ++-- pom.xml | 12 ++++++------ solon-plugin/pom.xml | 2 +- .../mapper-spring-boot-autoconfigure/pom.xml | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/all/mapper/pom.xml b/all/mapper/pom.xml index 041e7375e..f597de11f 100644 --- a/all/mapper/pom.xml +++ b/all/mapper/pom.xml @@ -79,7 +79,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.3.0 + 3.6.0 package diff --git a/all/pom.xml b/all/pom.xml index d360522f3..12b924a93 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -87,7 +87,7 @@ org.codehaus.mojo flatten-maven-plugin - 1.1.0 + 1.6.0 true bom diff --git a/core/pom.xml b/core/pom.xml index db365236a..3c98ecf76 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -38,6 +38,10 @@ https://mybatis.io + + org.slf4j + slf4j-api + jakarta.persistence diff --git a/generator/pom.xml b/generator/pom.xml index 84394ab1c..5cbf3ad77 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -57,13 +57,13 @@ org.projectlombok lombok - 1.16.22 + 1.18.34 provided io.swagger swagger-annotations - 1.5.20 + 1.6.14 provided diff --git a/pom.xml b/pom.xml index 9af44aa0e..b6ea3b8f6 100644 --- a/pom.xml +++ b/pom.xml @@ -157,7 +157,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.13.0 -parameters @@ -167,7 +167,7 @@ org.codehaus.mojo flatten-maven-plugin - 1.1.0 + 1.6.0 true resolveCiFriendliesOnly @@ -201,7 +201,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.1 package @@ -215,7 +215,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + 3.8.0 -Xdoclint:none @@ -234,7 +234,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.2.5 sign-artifacts @@ -254,7 +254,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.12 + 1.7.0 true ossrh diff --git a/solon-plugin/pom.xml b/solon-plugin/pom.xml index 1a0baf882..a1c96260f 100644 --- a/solon-plugin/pom.xml +++ b/solon-plugin/pom.xml @@ -72,7 +72,7 @@ com.h2database h2 - 2.3.232 + 1.4.200 test diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml index e3d165441..7b9be7921 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml @@ -74,8 +74,8 @@ true - javax.annotation - javax.annotation-api + jakarta.persistence + jakarta.persistence-api true From 5e7851d824c3c2c6d3bb7706081076bda15a93f3 Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 19 Aug 2024 23:45:23 +0800 Subject: [PATCH 093/109] =?UTF-8?q?=E9=80=82=E9=85=8DSpring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapperAutoConfiguration.java | 2 +- .../main/resources/META-INF/spring.factories | 3 - ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../src/main/resources/application.properties | 2 +- .../mybatis/sample/SampleXmlApplication.java | 2 +- .../src/main/resources/application.yml | 5 +- .../mybatis/spring/annotation/MapperScan.java | 149 ++-- .../annotation/MapperScannerRegistrar.java | 250 +++++-- .../spring/annotation/MapperScans.java | 41 ++ .../spring/mapper/ClassPathMapperScanner.java | 334 ++++++--- .../mapper/MapperScannerConfigurer.java | 655 ++++++++++++------ .../spring/mapper/SpringBootBindUtil.java | 108 +-- .../annotation/SpringAnnotationTest.java | 3 +- 13 files changed, 1016 insertions(+), 539 deletions(-) delete mode 100644 spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 spring/src/main/java/tk/mybatis/spring/annotation/MapperScans.java diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java index ad420d889..344bbdd5d 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java @@ -202,7 +202,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B logger.debug("Searching for mappers annotated with @Mapper"); - ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry); + ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry, environment); scanner.setMapperProperties(environment); try { if (this.resourceLoader != null) { diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 39e242f48..000000000 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -tk.mybatis.mapper.autoconfigure.MapperAutoConfiguration diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..48243cbf6 --- /dev/null +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +tk.mybatis.mapper.autoconfigure.MapperAutoConfiguration \ No newline at end of file diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties index a077c532c..dca3cf5cf 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties @@ -21,6 +21,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # -spring.datasource.schema=import.sql +spring.sql.init.schema-locations=classpath:import.sql logging.level.root=WARN logging.level.tk.mybatis.sample.mapper=TRACE \ No newline at end of file diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/SampleXmlApplication.java b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/SampleXmlApplication.java index 8473e4443..57fdf5de2 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/SampleXmlApplication.java +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/SampleXmlApplication.java @@ -48,7 +48,7 @@ public static void main(String[] args) { public void run(String... args) throws Exception { Country c = countryMapper.selectByPrimaryKey(1); System.out.println("Key : 1, Country Name: " + c.getCountryname()); - c.setId(null); + c.setId(1000L); c.setCountryname("新名字"); countryMapper.insert(c); System.out.println("New Key: " + c.getId()); diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml index 997c1e7b7..31048949b 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml @@ -22,8 +22,9 @@ # THE SOFTWARE. # spring: - datasource: - schema: import.sql + sql: + init: + schema-locations: classpath:import.sql mybatis: config-location: mybatis-config.xml base-packages: tk.mybatis.sample.mapper diff --git a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java index 0dab98301..f26f24b17 100644 --- a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java +++ b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScan.java @@ -1,34 +1,41 @@ -/** - * Copyright 2010-2016 the original author or authors. - *

+/* + * Copyright 2010-2023 the original author or authors. + * * 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 - *

+ * + * https://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 tk.mybatis.spring.annotation; +import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanNameGenerator; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Import; +import org.springframework.core.annotation.AliasFor; import tk.mybatis.spring.mapper.MapperFactoryBean; import tk.mybatis.spring.mapper.MapperScannerConfigurer; import java.lang.annotation.*; /** - * Use this annotation to register MyBatis mapper interfaces when using Java - * Config. It performs when same work as {@link MapperScannerConfigurer} via - * {@link tk.mybatis.spring.annotation.MapperScannerRegistrar}. + * Use this annotation to register MyBatis mapper interfaces when using Java Config. It performs when same work as + * {@link MapperScannerConfigurer} via {@link MapperScannerRegistrar}. + *

+ * Either {@link #basePackageClasses} or {@link #basePackages} (or its alias {@link #value}) may be specified to define + * specific packages to scan. Since 2.0.4, If specific packages are not defined, scanning will occur from the package of + * the class that declares this annotation. + *

+ * Configuration example: + *

* - *

Configuration example:

*
  * @Configuration
  * @MapperScan("org.mybatis.spring.sample.mapper")
@@ -36,9 +43,7 @@
  *
  *   @Bean
  *   public DataSource dataSource() {
- *     return new EmbeddedDatabaseBuilder()
- *              .addScript("schema.sql")
- *              .build();
+ *     return new EmbeddedDatabaseBuilder().addScript("schema.sql").build();
  *   }
  *
  *   @Bean
@@ -57,86 +62,139 @@
  *
  * @author Michael Lanyon
  * @author Eduardo Macarron
- *
- * @since 1.2.0
- * @see tk.mybatis.spring.annotation.MapperScannerRegistrar
+ * @author Qimiao Chen
+ * @see MapperScannerRegistrar
  * @see MapperFactoryBean
+ * @since 1.2.0
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.TYPE)
 @Documented
-@Import(tk.mybatis.spring.annotation.MapperScannerRegistrar.class)
+@Import(MapperScannerRegistrar.class)
+@Repeatable(MapperScans.class)
 public @interface MapperScan {
 
     /**
-     * Alias for the {@link #basePackages()} attribute. Allows for more concise
-     * annotation declarations e.g.:
-     * {@code @EnableMyBatisMapperScanner("org.my.pkg")} instead of {@code
-     * @EnableMyBatisMapperScanner(basePackages= "org.my.pkg"})}.
+     * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation declarations e.g.:
+     * {@code @MapperScan("org.my.pkg")} instead of {@code @MapperScan(basePackages = "org.my.pkg"})}.
+     *
+     * @return base package names
      */
+    @AliasFor("basePackages")
     String[] value() default {};
 
     /**
-     * Base packages to scan for MyBatis interfaces. Note that only interfaces
-     * with at least one method will be registered; concrete classes will be
-     * ignored.
+     * Base packages to scan for MyBatis interfaces. Note that only interfaces with at least one method will be
+     * registered; concrete classes will be ignored.
+     *
+     * @return base package names for scanning mapper interface
      */
+    @AliasFor("value")
     String[] basePackages() default {};
 
     /**
-     * Type-safe alternative to {@link #basePackages()} for specifying the packages
-     * to scan for annotated components. The package of each class specified will be scanned.
-     * 

Consider creating a special no-op marker class or interface in each package - * that serves no purpose other than being referenced by this attribute. + * Type-safe alternative to {@link #basePackages()} for specifying the packages to scan for annotated components. The + * package of each class specified will be scanned. + *

+ * Consider creating a special no-op marker class or interface in each package that serves no purpose other than being + * referenced by this attribute. + * + * @return classes that indicate base package for scanning mapper interface */ Class[] basePackageClasses() default {}; /** - * The {@link BeanNameGenerator} class to be used for naming detected components - * within the Spring container. + * The {@link BeanNameGenerator} class to be used for naming detected components within the Spring container. + * + * @return the class of {@link BeanNameGenerator} */ Class nameGenerator() default BeanNameGenerator.class; /** * This property specifies the annotation that the scanner will search for. *

- * The scanner will register all interfaces in the base package that also have - * the specified annotation. + * The scanner will register all interfaces in the base package that also have the specified annotation. *

* Note this can be combined with markerInterface. + * + * @return the annotation that the scanner will search for */ Class annotationClass() default Annotation.class; /** * This property specifies the parent that the scanner will search for. *

- * The scanner will register all interfaces in the base package that also have - * the specified interface class as a parent. + * The scanner will register all interfaces in the base package that also have the specified interface class as a + * parent. *

* Note this can be combined with annotationClass. + * + * @return the parent that the scanner will search for */ Class markerInterface() default Class.class; /** - * Specifies which {@code SqlSessionTemplate} to use in the case that there is - * more than one in the spring context. Usually this is only needed when you - * have more than one datasource. + * Specifies which {@code SqlSessionTemplate} to use in the case that there is more than one in the spring context. + * Usually this is only needed when you have more than one datasource. + * + * @return the bean name of {@code SqlSessionTemplate} */ String sqlSessionTemplateRef() default ""; /** - * Specifies which {@code SqlSessionFactory} to use in the case that there is - * more than one in the spring context. Usually this is only needed when you - * have more than one datasource. + * Specifies which {@code SqlSessionFactory} to use in the case that there is more than one in the spring context. + * Usually this is only needed when you have more than one datasource. + * + * @return the bean name of {@code SqlSessionFactory} */ String sqlSessionFactoryRef() default ""; /** * Specifies a custom MapperFactoryBean to return a mybatis proxy as spring bean. * + * @return the class of {@code MapperFactoryBean} */ Class factoryBean() default MapperFactoryBean.class; + /** + * Whether enable lazy initialization of mapper bean. + *

+ * Default is {@code false}. + *

+ * + * @return set {@code true} to enable lazy initialization + * @since 2.0.2 + */ + String lazyInitialization() default ""; + + /** + * Specifies the default scope of scanned mappers. + *

+ * Default is {@code ""} (equiv to singleton). + *

+ * + * @return the default scope + */ + String defaultScope() default AbstractBeanDefinition.SCOPE_DEFAULT; + + /** + * Specifies a flag that whether execute a property placeholder processing or not. + *

+ * The default is {@literal true}. This means that a property placeholder processing execute. + * + * @return a flag that whether execute a property placeholder processing or not + * @since 3.0.3 + */ + boolean processPropertyPlaceHolders() default true; + + /** + * Specifies which types are not eligible for mapper scanning. + * + * @return array of customized mapper excludeFilter + * @since 3.0.3 + */ + ComponentScan.Filter[] excludeFilters() default {}; + /** * 通用 Mapper 的配置,一行一个配置 * @@ -150,11 +208,4 @@ * @return */ String mapperHelperRef() default ""; - - /** - * Whether enable lazy initialization of mapper bean. - * Default is {@code false}. - * @return set {@code true} to enable lazy initialization - */ - String lazyInitialization() default ""; -} \ No newline at end of file +} diff --git a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java index a06bb6a55..6f6101a22 100644 --- a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java +++ b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScannerRegistrar.java @@ -1,106 +1,165 @@ -/** - * Copyright 2010-2016 the original author or authors. - *

+/* + * Copyright 2010-2024 the original author or authors. + * * 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 - *

+ * + * https://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 tk.mybatis.spring.annotation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.context.EnvironmentAware; import org.springframework.context.ResourceLoaderAware; +import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; import org.springframework.core.type.AnnotationMetadata; +import org.springframework.core.type.filter.AnnotationTypeFilter; +import org.springframework.core.type.filter.AssignableTypeFilter; +import org.springframework.core.type.filter.TypeFilter; +import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import tk.mybatis.spring.mapper.ClassPathMapperScanner; import tk.mybatis.spring.mapper.MapperFactoryBean; +import tk.mybatis.spring.mapper.MapperScannerConfigurer; import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; +/** + * A {@link ImportBeanDefinitionRegistrar} to allow annotation configuration of MyBatis mapper scanning. Using + * an @Enable annotation allows beans to be registered via @Component configuration, whereas implementing + * {@code BeanDefinitionRegistryPostProcessor} will work for XML configuration. + * + * @author Michael Lanyon + * @author Eduardo Macarron + * @author Putthiphong Boonphong + * + * @see MapperFactoryBean + * @see ClassPathMapperScanner + * + * @since 1.2.0 + */ public class MapperScannerRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware { - public static final Logger LOGGER = LoggerFactory.getLogger(MapperScannerRegistrar.class); - private ResourceLoader resourceLoader; + public static final Logger LOGGER = LoggerFactory.getLogger(MapperScannerRegistrar.class); + + // Note: Do not move resourceLoader via cleanup + private ResourceLoader resourceLoader; private Environment environment; @Override - public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + } + + @Override + public void setEnvironment(Environment environment) { + this.environment = environment; + } - AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(MapperScan.class.getName())); - ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry); - // this check is needed in Spring 3.1 - if (resourceLoader != null) { - scanner.setResourceLoader(resourceLoader); + @Override + public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { + var mapperScanAttrs = AnnotationAttributes + .fromMap(importingClassMetadata.getAnnotationAttributes(MapperScan.class.getName())); + if (mapperScanAttrs != null) { + registerBeanDefinitions(importingClassMetadata, mapperScanAttrs, registry, + generateBaseBeanName(importingClassMetadata, 0)); } + } + + void registerBeanDefinitions(AnnotationMetadata annoMeta, AnnotationAttributes annoAttrs, + BeanDefinitionRegistry registry, String beanName) { + + var builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class); + builder.addPropertyValue("processPropertyPlaceHolders", annoAttrs.getBoolean("processPropertyPlaceHolders")); Class annotationClass = annoAttrs.getClass("annotationClass"); if (!Annotation.class.equals(annotationClass)) { - scanner.setAnnotationClass(annotationClass); + builder.addPropertyValue("annotationClass", annotationClass); } Class markerInterface = annoAttrs.getClass("markerInterface"); if (!Class.class.equals(markerInterface)) { - scanner.setMarkerInterface(markerInterface); + builder.addPropertyValue("markerInterface", markerInterface); } Class generatorClass = annoAttrs.getClass("nameGenerator"); if (!BeanNameGenerator.class.equals(generatorClass)) { - scanner.setBeanNameGenerator(BeanUtils.instantiateClass(generatorClass)); + builder.addPropertyValue("nameGenerator", BeanUtils.instantiateClass(generatorClass)); } Class mapperFactoryBeanClass = annoAttrs.getClass("factoryBean"); if (!MapperFactoryBean.class.equals(mapperFactoryBeanClass)) { - scanner.setMapperFactoryBean(BeanUtils.instantiateClass(mapperFactoryBeanClass)); + builder.addPropertyValue("mapperFactoryBeanClass", mapperFactoryBeanClass); } - scanner.setSqlSessionTemplateBeanName(annoAttrs.getString("sqlSessionTemplateRef")); - scanner.setSqlSessionFactoryBeanName(annoAttrs.getString("sqlSessionFactoryRef")); + var sqlSessionTemplateRef = annoAttrs.getString("sqlSessionTemplateRef"); + if (StringUtils.hasText(sqlSessionTemplateRef)) { + builder.addPropertyValue("sqlSessionTemplateBeanName", annoAttrs.getString("sqlSessionTemplateRef")); + } - List basePackages = new ArrayList(); - for (String pkg : annoAttrs.getStringArray("value")) { - if (StringUtils.hasText(pkg)) { - basePackages.add(pkg); - } + var sqlSessionFactoryRef = annoAttrs.getString("sqlSessionFactoryRef"); + if (StringUtils.hasText(sqlSessionFactoryRef)) { + builder.addPropertyValue("sqlSessionFactoryBeanName", annoAttrs.getString("sqlSessionFactoryRef")); } - for (String pkg : annoAttrs.getStringArray("basePackages")) { - if (StringUtils.hasText(pkg)) { - basePackages.add(pkg); - } + + List basePackages = new ArrayList<>(Arrays.stream(annoAttrs.getStringArray("basePackages")) + .filter(StringUtils::hasText).collect(Collectors.toList())); + + basePackages.addAll(Arrays.stream(annoAttrs.getClassArray("basePackageClasses")).map(ClassUtils::getPackageName) + .collect(Collectors.toList())); + + if (basePackages.isEmpty()) { + basePackages.add(getDefaultBasePackage(annoMeta)); } - for (Class clazz : annoAttrs.getClassArray("basePackageClasses")) { - basePackages.add(ClassUtils.getPackageName(clazz)); + + var excludeFilterArray = annoAttrs.getAnnotationArray("excludeFilters"); + if (excludeFilterArray.length > 0) { + List typeFilters = new ArrayList<>(); + List> rawTypeFilters = new ArrayList<>(); + for (AnnotationAttributes excludeFilters : excludeFilterArray) { + if (excludeFilters.getStringArray("pattern").length > 0) { + // in oder to apply placeholder resolver + rawTypeFilters.addAll(parseFiltersHasPatterns(excludeFilters)); + } else { + typeFilters.addAll(typeFiltersFor(excludeFilters)); + } + } + builder.addPropertyValue("excludeFilters", typeFilters); + builder.addPropertyValue("rawExcludeFilters", rawTypeFilters); } + //优先级 mapperHelperRef > properties > springboot String mapperHelperRef = annoAttrs.getString("mapperHelperRef"); String[] properties = annoAttrs.getStringArray("properties"); if (StringUtils.hasText(mapperHelperRef)) { - scanner.setMapperHelperBeanName(mapperHelperRef); + builder.addPropertyValue("mapperHelperBeanName", mapperHelperRef); } else if (properties != null && properties.length > 0) { - scanner.setMapperProperties(properties); + builder.addPropertyValue("mapperProperties", properties); } else { try { - scanner.setMapperProperties(this.environment); + builder.addPropertyValue("mapperProperties", this.environment); } catch (Exception e) { LOGGER.warn("只有 Spring Boot 环境中可以通过 Environment(配置文件,环境变量,运行参数等方式) 配置通用 Mapper," + "其他环境请通过 @MapperScan 注解中的 mapperHelperRef 或 properties 参数进行配置!" + @@ -108,22 +167,119 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B } } - String lazyInitialization = annoAttrs.getString("lazyInitialization"); + var lazyInitialization = annoAttrs.getString("lazyInitialization"); if (StringUtils.hasText(lazyInitialization)) { - scanner.setLazyInitialization(Boolean.valueOf(lazyInitialization)); + builder.addPropertyValue("lazyInitialization", lazyInitialization); } - scanner.registerFilters(); - scanner.doScan(StringUtils.toStringArray(basePackages)); + var defaultScope = annoAttrs.getString("defaultScope"); + if (!AbstractBeanDefinition.SCOPE_DEFAULT.equals(defaultScope)) { + builder.addPropertyValue("defaultScope", defaultScope); + } + + builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(basePackages)); + + // for spring-native + builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); + + registry.registerBeanDefinition(beanName, builder.getBeanDefinition()); + } - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; + /** + * Parse excludeFilters which FilterType is REGEX or ASPECTJ + * + * @param filterAttributes + * AnnotationAttributes of excludeFilters + * + * @since 3.0.3 + */ + private List> parseFiltersHasPatterns(AnnotationAttributes filterAttributes) { + + List> rawTypeFilters = new ArrayList<>(); + FilterType filterType = filterAttributes.getEnum("type"); + var expressionArray = filterAttributes.getStringArray("pattern"); + for (String expression : expressionArray) { + switch (filterType) { + case REGEX: + case ASPECTJ: + Map typeFilter = new HashMap<>(16); + typeFilter.put("type", filterType.name().toLowerCase()); + typeFilter.put("expression", expression); + rawTypeFilters.add(typeFilter); + break; + default: + throw new IllegalArgumentException("Cannot specify the 'pattern' attribute if use the " + filterType + + " FilterType in exclude filter of @MapperScan"); + } + } + return rawTypeFilters; } - @Override - public void setResourceLoader(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; + /** + * Parse excludeFilters which FilterType is ANNOTATION ASSIGNABLE or CUSTOM + * + * @param filterAttributes + * AnnotationAttributes of excludeFilters + * + * @since 3.0.3 + */ + private List typeFiltersFor(AnnotationAttributes filterAttributes) { + + List typeFilters = new ArrayList<>(); + FilterType filterType = filterAttributes.getEnum("type"); + + for (Class filterClass : filterAttributes.getClassArray("value")) { + switch (filterType) { + case ANNOTATION: + Assert.isAssignable(Annotation.class, filterClass, + "Specified an unsupported type in 'ANNOTATION' exclude filter of @MapperScan"); + @SuppressWarnings("unchecked") + var annoClass = (Class) filterClass; + typeFilters.add(new AnnotationTypeFilter(annoClass)); + break; + case ASSIGNABLE_TYPE: + typeFilters.add(new AssignableTypeFilter(filterClass)); + break; + case CUSTOM: + Assert.isAssignable(TypeFilter.class, filterClass, + "An error occured when processing a @ComponentScan " + "CUSTOM type filter: "); + typeFilters.add(BeanUtils.instantiateClass(filterClass, TypeFilter.class)); + break; + default: + throw new IllegalArgumentException("Cannot specify the 'value' or 'classes' attribute if use the " + + filterType + " FilterType in exclude filter of @MapperScan"); + } + } + return typeFilters; } + + private static String generateBaseBeanName(AnnotationMetadata importingClassMetadata, int index) { + return importingClassMetadata.getClassName() + "#" + MapperScannerRegistrar.class.getSimpleName() + "#" + index; + } + + private static String getDefaultBasePackage(AnnotationMetadata importingClassMetadata) { + return ClassUtils.getPackageName(importingClassMetadata.getClassName()); + } + + /** + * A {@link MapperScannerRegistrar} for {@link MapperScans}. + * + * @since 2.0.0 + */ + static class RepeatingRegistrar extends MapperScannerRegistrar { + @Override + public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { + var mapperScansAttrs = AnnotationAttributes + .fromMap(importingClassMetadata.getAnnotationAttributes(MapperScans.class.getName())); + if (mapperScansAttrs != null) { + var annotations = mapperScansAttrs.getAnnotationArray("value"); + for (var i = 0; i < annotations.length; i++) { + registerBeanDefinitions(importingClassMetadata, annotations[i], registry, + generateBaseBeanName(importingClassMetadata, i)); + } + } + } + } + } diff --git a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScans.java b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScans.java new file mode 100644 index 000000000..b4b3bac80 --- /dev/null +++ b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScans.java @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2022 the original author or authors. + * + * 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 + * + * https://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 tk.mybatis.spring.annotation; + +import org.springframework.context.annotation.Import; + +import java.lang.annotation.*; + +/** + * The Container annotation that aggregates several {@link org.mybatis.spring.annotation.MapperScan} annotations. + *

+ * Can be used natively, declaring several nested {@link org.mybatis.spring.annotation.MapperScan} annotations. Can also be used in conjunction with + * Java 8's support for repeatable annotations, where {@link org.mybatis.spring.annotation.MapperScan} can simply be declared several times on the + * same method, implicitly generating this container annotation. + * + * @author Kazuki Shimizu + * + * @since 2.0.0 + * + * @see org.mybatis.spring.annotation.MapperScan + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Documented +@Import(MapperScannerRegistrar.RepeatingRegistrar.class) +public @interface MapperScans { + MapperScan[] value(); +} diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java b/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java index 11279ddb8..ff9e127d6 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/ClassPathMapperScanner.java @@ -1,12 +1,12 @@ -/** - * Copyright 2010-2016 the original author or authors. - *

+/* + * Copyright 2010-2024 the original author or authors. + * * 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 - *

+ * + * https://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. @@ -15,20 +15,25 @@ */ package tk.mybatis.spring.mapper; +import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionTemplate; -import org.mybatis.spring.mapper.MapperScannerConfigurer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.aop.scope.ScopedProxyFactoryBean; +import org.springframework.aop.scope.ScopedProxyUtils; +import org.springframework.aot.AotDetector; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; +import org.springframework.core.NativeDetector; import org.springframework.core.env.Environment; -import org.springframework.core.type.classreading.MetadataReader; -import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.core.type.filter.AssignableTypeFilter; import org.springframework.core.type.filter.TypeFilter; @@ -37,33 +42,37 @@ import tk.mybatis.mapper.entity.Config; import tk.mybatis.mapper.mapperhelper.MapperHelper; -import java.io.IOException; import java.lang.annotation.Annotation; -import java.util.Arrays; -import java.util.Properties; -import java.util.Set; +import java.util.*; /** - * A {@link ClassPathBeanDefinitionScanner} that registers Mappers by - * {@code basePackage}, {@code annotationClass}, or {@code markerInterface}. If - * an {@code annotationClass} and/or {@code markerInterface} is specified, only - * the specified types will be searched (searching for all interfaces will be - * disabled). + * A {@link ClassPathBeanDefinitionScanner} that registers Mappers by {@code basePackage}, {@code annotationClass}, or + * {@code markerInterface}. If an {@code annotationClass} and/or {@code markerInterface} is specified, only the + * specified types will be searched (searching for all interfaces will be disabled). *

- * This functionality was previously a private class of - * {@link MapperScannerConfigurer}, but was broken out in version 1.2.0. + * This functionality was previously a private class of {@link MapperScannerConfigurer}, but was broken out in version + * 1.2.0. * * @author Hunter Presnall * @author Eduardo Macarron + * * @see MapperFactoryBean + * * @since 1.2.0 */ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner { + private static final Logger LOGGER = LoggerFactory.getLogger(ClassPathMapperScanner.class); + + // Copy of FactoryBean#OBJECT_TYPE_ATTRIBUTE which was added in Spring 5.2 + static final String FACTORY_BEAN_OBJECT_TYPE = "factoryBeanObjectType"; + private boolean addToConfig = true; private boolean lazyInitialization; + private boolean printWarnLogIfNotFoundMappers = true; + private SqlSessionFactory sqlSessionFactory; private SqlSessionTemplate sqlSessionTemplate; @@ -80,19 +89,130 @@ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner { private String mapperHelperBeanName; - private MapperFactoryBean mapperFactoryBean = new MapperFactoryBean(); + private Class mapperFactoryBeanClass = MapperFactoryBean.class; + private String defaultScope; + private List excludeFilters; + + public ClassPathMapperScanner(BeanDefinitionRegistry registry, Environment environment) { + super(registry, false, environment); + setIncludeAnnotationConfig(!AotDetector.useGeneratedArtifacts()); + setPrintWarnLogIfNotFoundMappers(!NativeDetector.inNativeImage()); + } + + /** + * @deprecated Please use the {@link #ClassPathMapperScanner(BeanDefinitionRegistry, Environment)}. + */ + @Deprecated(since = "3.0.4", forRemoval = true) public ClassPathMapperScanner(BeanDefinitionRegistry registry) { super(registry, false); + setIncludeAnnotationConfig(!AotDetector.useGeneratedArtifacts()); + setPrintWarnLogIfNotFoundMappers(!NativeDetector.inNativeImage()); + } + + public void setAddToConfig(boolean addToConfig) { + this.addToConfig = addToConfig; + } + + public void setAnnotationClass(Class annotationClass) { + this.annotationClass = annotationClass; + } + + /** + * Set whether enable lazy initialization for mapper bean. + *

+ * Default is {@code false}. + *

+ * + * @param lazyInitialization + * Set the @{code true} to enable + * + * @since 2.0.2 + */ + public void setLazyInitialization(boolean lazyInitialization) { + this.lazyInitialization = lazyInitialization; + } + + /** + * Set whether print warning log if not found mappers that matches conditions. + *

+ * Default is {@code true}. But {@code false} when running in native image. + *

+ * + * @param printWarnLogIfNotFoundMappers + * Set the @{code true} to print + * + * @since 3.0.1 + */ + public void setPrintWarnLogIfNotFoundMappers(boolean printWarnLogIfNotFoundMappers) { + this.printWarnLogIfNotFoundMappers = printWarnLogIfNotFoundMappers; + } + + public void setMarkerInterface(Class markerInterface) { + this.markerInterface = markerInterface; + } + + public void setExcludeFilters(List excludeFilters) { + this.excludeFilters = excludeFilters; + } + + public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { + this.sqlSessionFactory = sqlSessionFactory; + } + + public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { + this.sqlSessionTemplate = sqlSessionTemplate; + } + + public void setSqlSessionTemplateBeanName(String sqlSessionTemplateBeanName) { + this.sqlSessionTemplateBeanName = sqlSessionTemplateBeanName; + } + + public void setSqlSessionFactoryBeanName(String sqlSessionFactoryBeanName) { + this.sqlSessionFactoryBeanName = sqlSessionFactoryBeanName; + } + + /** + * @deprecated Since 2.0.1, Please use the {@link #setMapperFactoryBeanClass(Class)}. + */ + @Deprecated + public void setMapperFactoryBean(MapperFactoryBean mapperFactoryBean) { + this.mapperFactoryBeanClass = mapperFactoryBean == null ? MapperFactoryBean.class : mapperFactoryBean.getClass(); + } + + /** + * Set the {@code MapperFactoryBean} class. + * + * @param mapperFactoryBeanClass + * the {@code MapperFactoryBean} class + * + * @since 2.0.1 + */ + public void setMapperFactoryBeanClass(Class mapperFactoryBeanClass) { + this.mapperFactoryBeanClass = mapperFactoryBeanClass == null ? MapperFactoryBean.class : mapperFactoryBeanClass; + } + + /** + * Set the default scope of scanned mappers. + *

+ * Default is {@code null} (equiv to singleton). + *

+ * + * @param defaultScope + * the scope + * + * @since 2.0.6 + */ + public void setDefaultScope(String defaultScope) { + this.defaultScope = defaultScope; } /** - * Configures parent scanner to search for the right interfaces. It can search - * for all interfaces or just for those that extends a markerInterface or/and - * those annotated with the annotationClass + * Configures parent scanner to search for the right interfaces. It can search for all interfaces or just for those + * that extends a markerInterface or/and those annotated with the annotationClass */ public void registerFilters() { - boolean acceptAllInterfaces = true; + var acceptAllInterfaces = true; // if specified, use the given annotation and / or marker interface if (this.annotationClass != null) { @@ -113,39 +233,40 @@ protected boolean matchClassName(String className) { if (acceptAllInterfaces) { // default include filter that accepts all classes - addIncludeFilter(new TypeFilter() { - @Override - public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { - return true; - } - }); + addIncludeFilter((metadataReader, metadataReaderFactory) -> true); } // exclude package-info.java - addExcludeFilter(new TypeFilter() { - @Override - public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { - String className = metadataReader.getClassMetadata().getClassName(); - if (className.endsWith("package-info")) { - return true; - } - return metadataReader.getAnnotationMetadata() - .hasAnnotation("tk.mybatis.mapper.annotation.RegisterMapper"); + addExcludeFilter((metadataReader, metadataReaderFactory) -> { + var className = metadataReader.getClassMetadata().getClassName(); + if (className.endsWith("package-info")) { + return true; } + return metadataReader.getAnnotationMetadata() + .hasAnnotation("tk.mybatis.mapper.annotation.RegisterMapper"); }); + + // exclude types declared by MapperScan.excludeFilters + if (excludeFilters != null && excludeFilters.size() > 0) { + for (TypeFilter excludeFilter : excludeFilters) { + addExcludeFilter(excludeFilter); + } + } } /** - * Calls the parent search that will search and register all the candidates. - * Then the registered objects are post processed to set them as - * MapperFactoryBeans + * Calls the parent search that will search and register all the candidates. Then the registered objects are post + * processed to set them as MapperFactoryBeans */ @Override public Set doScan(String... basePackages) { - Set beanDefinitions = super.doScan(basePackages); + var beanDefinitions = super.doScan(basePackages); if (beanDefinitions.isEmpty()) { - logger.warn("No MyBatis mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration."); + if (printWarnLogIfNotFoundMappers) { + LOGGER.warn("No MyBatis mapper was found in '" + Arrays.toString(basePackages) + + "' package. Please check your configuration."); + } } else { processBeanDefinitions(beanDefinitions); } @@ -154,19 +275,38 @@ public Set doScan(String... basePackages) { } private void processBeanDefinitions(Set beanDefinitions) { - GenericBeanDefinition definition; + AbstractBeanDefinition definition; + var registry = getRegistry(); for (BeanDefinitionHolder holder : beanDefinitions) { - definition = (GenericBeanDefinition) holder.getBeanDefinition(); - - if (logger.isDebugEnabled()) { - logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() - + "' and '" + definition.getBeanClassName() + "' mapperInterface"); + definition = (AbstractBeanDefinition) holder.getBeanDefinition(); + var scopedProxy = false; + if (ScopedProxyFactoryBean.class.getName().equals(definition.getBeanClassName())) { + definition = (AbstractBeanDefinition) Optional + .ofNullable(((RootBeanDefinition) definition).getDecoratedDefinition()) + .map(BeanDefinitionHolder::getBeanDefinition).orElseThrow(() -> new IllegalStateException( + "The target bean definition of scoped proxy bean not found. Root bean definition[" + holder + "]")); + scopedProxy = true; } + var beanClassName = definition.getBeanClassName(); + LOGGER.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + beanClassName + + "' mapperInterface"); // the mapper interface is the original class of the bean // but, the actual class of the bean is MapperFactoryBean - definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName()); // issue #59 - definition.setBeanClass(this.mapperFactoryBean.getClass()); + definition.getConstructorArgumentValues().addGenericArgumentValue(beanClassName); // issue #59 + try { + Class beanClass = Resources.classForName(beanClassName); + // Attribute for MockitoPostProcessor + // https://github.com/mybatis/spring-boot-starter/issues/475 + definition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, beanClass); + // for spring-native + definition.getPropertyValues().add("mapperInterface", beanClass); + } catch (ClassNotFoundException ignore) { + // ignore + } + + definition.setBeanClass(this.mapperFactoryBeanClass); + //设置通用 Mapper if (StringUtils.hasText(this.mapperHelperBeanName)) { definition.getPropertyValues().add("mapperHelper", new RuntimeBeanReference(this.mapperHelperBeanName)); @@ -180,9 +320,10 @@ private void processBeanDefinitions(Set beanDefinitions) { definition.getPropertyValues().add("addToConfig", this.addToConfig); - boolean explicitFactoryUsed = false; + var explicitFactoryUsed = false; if (StringUtils.hasText(this.sqlSessionFactoryBeanName)) { - definition.getPropertyValues().add("sqlSessionFactory", new RuntimeBeanReference(this.sqlSessionFactoryBeanName)); + definition.getPropertyValues().add("sqlSessionFactory", + new RuntimeBeanReference(this.sqlSessionFactoryBeanName)); explicitFactoryUsed = true; } else if (this.sqlSessionFactory != null) { definition.getPropertyValues().add("sqlSessionFactory", this.sqlSessionFactory); @@ -191,50 +332,58 @@ private void processBeanDefinitions(Set beanDefinitions) { if (StringUtils.hasText(this.sqlSessionTemplateBeanName)) { if (explicitFactoryUsed) { - logger.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored."); + LOGGER.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored."); } - definition.getPropertyValues().add("sqlSessionTemplate", new RuntimeBeanReference(this.sqlSessionTemplateBeanName)); + definition.getPropertyValues().add("sqlSessionTemplate", + new RuntimeBeanReference(this.sqlSessionTemplateBeanName)); explicitFactoryUsed = true; } else if (this.sqlSessionTemplate != null) { if (explicitFactoryUsed) { - logger.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored."); + LOGGER.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored."); } definition.getPropertyValues().add("sqlSessionTemplate", this.sqlSessionTemplate); explicitFactoryUsed = true; } if (!explicitFactoryUsed) { - if (logger.isDebugEnabled()) { - logger.debug("Enabling autowire by type for MapperFactoryBean with name '" + holder.getBeanName() + "'."); - } + LOGGER.debug("Enabling autowire by type for MapperFactoryBean with name '" + holder.getBeanName() + "'."); definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); } definition.setLazyInit(lazyInitialization); + + if (scopedProxy) { + continue; + } + + if (ConfigurableBeanFactory.SCOPE_SINGLETON.equals(definition.getScope()) && defaultScope != null) { + definition.setScope(defaultScope); + } + + if (!definition.isSingleton()) { + var proxyHolder = ScopedProxyUtils.createScopedProxy(holder, registry, true); + if (registry.containsBeanDefinition(proxyHolder.getBeanName())) { + registry.removeBeanDefinition(proxyHolder.getBeanName()); + } + registry.registerBeanDefinition(proxyHolder.getBeanName(), proxyHolder.getBeanDefinition()); + } + } } - /** - * {@inheritDoc} - */ @Override protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent(); } - /** - * {@inheritDoc} - */ @Override protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition) { if (super.checkCandidate(beanName, beanDefinition)) { return true; - } else { - logger.warn("Skipping MapperFactoryBean with name '" + beanName - + "' and '" + beanDefinition.getBeanClassName() + "' mapperInterface" - + ". Bean already defined with the same name!"); - return false; } + LOGGER.warn("Skipping MapperFactoryBean with name '" + beanName + "' and '" + + beanDefinition.getBeanClassName() + "' mapperInterface" + ". Bean already defined with the same name!"); + return false; } public MapperHelper getMapperHelper() { @@ -245,18 +394,6 @@ public void setMapperHelper(MapperHelper mapperHelper) { this.mapperHelper = mapperHelper; } - public void setAddToConfig(boolean addToConfig) { - this.addToConfig = addToConfig; - } - - public void setAnnotationClass(Class annotationClass) { - this.annotationClass = annotationClass; - } - - public void setLazyInitialization(boolean lazyInitialization) { - this.lazyInitialization = lazyInitialization; - } - /** * 配置通用 Mapper * @@ -269,16 +406,12 @@ public void setConfig(Config config) { mapperHelper.setConfig(config); } - public void setMapperFactoryBean(MapperFactoryBean mapperFactoryBean) { - this.mapperFactoryBean = mapperFactoryBean != null ? mapperFactoryBean : new MapperFactoryBean(); - } - public void setMapperHelperBeanName(String mapperHelperBeanName) { this.mapperHelperBeanName = mapperHelperBeanName; } /** - * 从环境变量中获取 mapper 配置信息 + * TODO 从环境变量中获取 mapper 配置信息 * * @param environment */ @@ -293,7 +426,7 @@ public void setMapperProperties(Environment environment) { } /** - * 从 properties 数组获取 mapper 配置信息 + * TODO 从 properties 数组获取 mapper 配置信息 * * @param properties */ @@ -319,23 +452,4 @@ public void setMapperProperties(String[] properties) { mapperHelper.setProperties(props); } - public void setMarkerInterface(Class markerInterface) { - this.markerInterface = markerInterface; - } - - public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { - this.sqlSessionFactory = sqlSessionFactory; - } - - public void setSqlSessionFactoryBeanName(String sqlSessionFactoryBeanName) { - this.sqlSessionFactoryBeanName = sqlSessionFactoryBeanName; - } - - public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { - this.sqlSessionTemplate = sqlSessionTemplate; - } - - public void setSqlSessionTemplateBeanName(String sqlSessionTemplateBeanName) { - this.sqlSessionTemplateBeanName = sqlSessionTemplateBeanName; - } } diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java b/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java index 70970e278..3c0b1d715 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/MapperScannerConfigurer.java @@ -1,12 +1,12 @@ -/** - * Copyright 2010-2016 the original author or authors. - *

+/* + * Copyright 2010-2024 the original author or authors. + * * 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 - *

+ * + * https://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. @@ -17,11 +17,10 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionTemplate; -import org.springframework.beans.PropertyValue; +import org.springframework.beans.BeanUtils; import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.PropertyResourceConfigurer; import org.springframework.beans.factory.config.TypedStringValue; @@ -33,69 +32,70 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.Environment; +import org.springframework.core.type.filter.*; +import org.springframework.lang.Nullable; +import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; +import tk.mybatis.mapper.MapperException; import tk.mybatis.mapper.common.Marker; +import tk.mybatis.mapper.entity.Config; import tk.mybatis.mapper.mapperhelper.MapperHelper; import java.lang.annotation.Annotation; -import java.util.Map; -import java.util.Properties; +import java.util.*; +import java.util.regex.Pattern; import static org.springframework.util.Assert.notNull; /** - * BeanDefinitionRegistryPostProcessor that searches recursively starting from a base package for - * interfaces and registers them as {@code MapperFactoryBean}. Note that only interfaces with at - * least one method will be registered; concrete classes will be ignored. + * BeanDefinitionRegistryPostProcessor that searches recursively starting from a base package for interfaces and + * registers them as {@code MapperFactoryBean}. Note that only interfaces with at least one method will be registered; + * concrete classes will be ignored. *

* This class was a {code BeanFactoryPostProcessor} until 1.0.1 version. It changed to - * {@code BeanDefinitionRegistryPostProcessor} in 1.0.2. See https://jira.springsource.org/browse/SPR-8269 - * for the details. + * {@code BeanDefinitionRegistryPostProcessor} in 1.0.2. See https://jira.springsource.org/browse/SPR-8269 for the + * details. *

- * The {@code basePackage} property can contain more than one package name, separated by either - * commas or semicolons. + * The {@code basePackage} property can contain more than one package name, separated by either commas or semicolons. *

- * This class supports filtering the mappers created by either specifying a marker interface or an - * annotation. The {@code annotationClass} property specifies an annotation to search for. The - * {@code markerInterface} property specifies a parent interface to search for. If both properties - * are specified, mappers are added for interfaces that match either criteria. By default, - * these two properties are null, so all interfaces in the given {@code basePackage} are added as - * mappers. + * This class supports filtering the mappers created by either specifying a marker interface or an annotation. The + * {@code annotationClass} property specifies an annotation to search for. The {@code markerInterface} property + * specifies a parent interface to search for. If both properties are specified, mappers are added for interfaces that + * match either criteria. By default, these two properties are null, so all interfaces in the given + * {@code basePackage} are added as mappers. *

- * This configurer enables autowire for all the beans that it creates so that they are - * automatically autowired with the proper {@code SqlSessionFactory} or {@code SqlSessionTemplate}. - * If there is more than one {@code SqlSessionFactory} in the application, however, autowiring - * cannot be used. In this case you must explicitly specify either an {@code SqlSessionFactory} or - * an {@code SqlSessionTemplate} to use via the bean name properties. Bean names are used - * rather than actual objects because Spring does not initialize property placeholders until after - * this class is processed. + * This configurer enables autowire for all the beans that it creates so that they are automatically autowired with the + * proper {@code SqlSessionFactory} or {@code SqlSessionTemplate}. If there is more than one {@code SqlSessionFactory} + * in the application, however, autowiring cannot be used. In this case you must explicitly specify either an + * {@code SqlSessionFactory} or an {@code SqlSessionTemplate} to use via the bean name properties. Bean names + * are used rather than actual objects because Spring does not initialize property placeholders until after this class + * is processed. *

- * Passing in an actual object which may require placeholders (i.e. DB user password) will fail. - * Using bean names defers actual object creation until later in the startup - * process, after all placeholder substituation is completed. However, note that this configurer - * does support property placeholders of its own properties. The basePackage - * and bean name properties all support ${property} style substitution. + * Passing in an actual object which may require placeholders (i.e. DB user password) will fail. Using bean names defers + * actual object creation until later in the startup process, after all placeholder substitution is completed. However, + * note that this configurer does support property placeholders of its own properties. The + * basePackage and bean name properties all support ${property} style substitution. *

* Configuration sample: - *

- *

+ * *

  * {@code
- * 
- * 
- * 
- * 
- * 
+ *   
+ *       
+ *       
+ *       
+ *   
  * }
  * 
* * @author Hunter Presnall * @author Eduardo Macarron - * @author liuzh - * @see tk.mybatis.spring.mapper.MapperFactoryBean + * + * @see MapperFactoryBean * @see ClassPathMapperScanner */ -public class MapperScannerConfigurer implements BeanDefinitionRegistryPostProcessor, InitializingBean, ApplicationContextAware, BeanNameAware { +public class MapperScannerConfigurer + implements BeanDefinitionRegistryPostProcessor, InitializingBean, ApplicationContextAware, BeanNameAware { private String basePackage; @@ -115,6 +115,12 @@ public class MapperScannerConfigurer implements BeanDefinitionRegistryPostProces private Class markerInterface; + private List excludeFilters; + + private List> rawExcludeFilters; + + private Class mapperFactoryBeanClass; + private ApplicationContext applicationContext; private String beanName; @@ -123,8 +129,12 @@ public class MapperScannerConfigurer implements BeanDefinitionRegistryPostProces private BeanNameGenerator nameGenerator; + private String defaultScope; + private MapperHelper mapperHelper = new MapperHelper(); + private String mapperHelperBeanName; + public MapperHelper getMapperHelper() { return mapperHelper; } @@ -135,132 +145,25 @@ public void setMapperHelper(MapperHelper mapperHelper) { /** - * {@inheritDoc} - */ - @Override - public void afterPropertiesSet() throws Exception { - notNull(this.basePackage, "Property 'basePackage' is required"); - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { - // left intentionally blank - } - - /** - * {@inheritDoc} - * - * @since 1.0.2 - */ - @Override - public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) { - if (this.processPropertyPlaceHolders) { - processPropertyPlaceHolders(); - } - ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry); - scanner.setAddToConfig(this.addToConfig); - scanner.setAnnotationClass(this.annotationClass); - scanner.setMarkerInterface(this.markerInterface); - scanner.setSqlSessionFactory(this.sqlSessionFactory); - scanner.setSqlSessionTemplate(this.sqlSessionTemplate); - scanner.setSqlSessionFactoryBeanName(this.sqlSessionFactoryBeanName); - scanner.setSqlSessionTemplateBeanName(this.sqlSessionTemplateBeanName); - scanner.setResourceLoader(this.applicationContext); - scanner.setBeanNameGenerator(this.nameGenerator); - if (StringUtils.hasText(lazyInitialization)) { - scanner.setLazyInitialization(Boolean.valueOf(lazyInitialization)); - } - scanner.registerFilters(); - //设置通用 Mapper - scanner.setMapperHelper(this.mapperHelper); - scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)); - } - - /* - * BeanDefinitionRegistries are called early in application startup, before - * BeanFactoryPostProcessors. This means that PropertyResourceConfigurers will not have been - * loaded and any property substitution of this class' properties will fail. To avoid this, find - * any PropertyResourceConfigurers defined in the context and run them on this class' bean - * definition. Then update the values. - */ - private void processPropertyPlaceHolders() { - Map prcs = applicationContext.getBeansOfType(PropertyResourceConfigurer.class); - - if (!prcs.isEmpty() && applicationContext instanceof ConfigurableApplicationContext) { - BeanDefinition mapperScannerBean = ((ConfigurableApplicationContext) applicationContext) - .getBeanFactory().getBeanDefinition(beanName); - - // PropertyResourceConfigurer does not expose any methods to explicitly perform - // property placeholder substitution. Instead, create a BeanFactory that just - // contains this mapper scanner and post process the factory. - DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); - factory.registerBeanDefinition(beanName, mapperScannerBean); - - for (PropertyResourceConfigurer prc : prcs.values()) { - prc.postProcessBeanFactory(factory); - } - - PropertyValues values = mapperScannerBean.getPropertyValues(); - - this.basePackage = updatePropertyValue("basePackage", values); - this.sqlSessionFactoryBeanName = updatePropertyValue("sqlSessionFactoryBeanName", values); - this.sqlSessionTemplateBeanName = updatePropertyValue("sqlSessionTemplateBeanName", values); - this.lazyInitialization = updatePropertyValue("lazyInitialization", values); - } - this.lazyInitialization = this.lazyInitialization == null ? null : getEnvironment().resolvePlaceholders(this.lazyInitialization); - } - - private Environment getEnvironment() { - return this.applicationContext.getEnvironment(); - } - - private String updatePropertyValue(String propertyName, PropertyValues values) { - PropertyValue property = values.getPropertyValue(propertyName); - - if (property == null) { - return null; - } - - Object value = property.getValue(); - - if (value == null) { - return null; - } else if (value instanceof String) { - return value.toString(); - } else if (value instanceof TypedStringValue) { - return ((TypedStringValue) value).getValue(); - } else { - return null; - } - } - - /** - * Gets beanNameGenerator to be used while running the scanner. - * - * @return the beanNameGenerator BeanNameGenerator that has been configured - * @since 1.2.0 - */ - public BeanNameGenerator getNameGenerator() { - return nameGenerator; - } - - /** - * Sets beanNameGenerator to be used while running the scanner. + * This property lets you set the base package for your mapper interface files. + *

+ * You can set more than one package by using a semicolon or comma as a separator. + *

+ * Mappers will be searched for recursively starting in the specified package(s). * - * @param nameGenerator the beanNameGenerator to set - * @since 1.2.0 + * @param basePackage + * base package name */ - public void setNameGenerator(BeanNameGenerator nameGenerator) { - this.nameGenerator = nameGenerator; + public void setBasePackage(String basePackage) { + this.basePackage = basePackage; } /** * Same as {@code MapperFactoryBean#setAddToConfig(boolean)}. * * @param addToConfig + * a flag that whether add mapper to MyBatis or not + * * @see MapperFactoryBean#setAddToConfig(boolean) */ public void setAddToConfig(boolean addToConfig) { @@ -269,8 +172,14 @@ public void setAddToConfig(boolean addToConfig) { /** * Set whether enable lazy initialization for mapper bean. + *

* Default is {@code false}. - * @param lazyInitialization Set the @{code true} to enable + *

+ * + * @param lazyInitialization + * Set the @{code true} to enable + * + * @since 2.0.2 */ public void setLazyInitialization(String lazyInitialization) { this.lazyInitialization = lazyInitialization; @@ -279,79 +188,112 @@ public void setLazyInitialization(String lazyInitialization) { /** * This property specifies the annotation that the scanner will search for. *

- * The scanner will register all interfaces in the base package that also have the - * specified annotation. + * The scanner will register all interfaces in the base package that also have the specified annotation. *

* Note this can be combined with markerInterface. * - * @param annotationClass annotation class + * @param annotationClass + * annotation class */ public void setAnnotationClass(Class annotationClass) { this.annotationClass = annotationClass; } /** - * {@inheritDoc} + * This property specifies the parent that the scanner will search for. + *

+ * The scanner will register all interfaces in the base package that also have the specified interface class as a + * parent. + *

+ * Note this can be combined with annotationClass. + * + * @param superClass + * parent class */ - @Override - public void setApplicationContext(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; + public void setMarkerInterface(Class superClass) { + this.markerInterface = superClass; + if (Marker.class.isAssignableFrom(superClass)) { + mapperHelper.registerMapper(superClass); + } } /** - * This property lets you set the base package for your mapper interface files. + * Specifies which types are not eligible for the mapper scanner. *

- * You can set more than one package by using a semicolon or comma as a separator. - *

- * Mappers will be searched for recursively starting in the specified package(s). + * The scanner will exclude types that define with excludeFilters. * - * @param basePackage base package name + * @since 3.0.3 + * + * @param excludeFilters + * list of TypeFilter */ - public void setBasePackage(String basePackage) { - this.basePackage = basePackage; + public void setExcludeFilters(List excludeFilters) { + this.excludeFilters = excludeFilters; } /** - * {@inheritDoc} + * In order to support process PropertyPlaceHolders. + *

+ * After parsed, it will be added to excludeFilters. + * + * @since 3.0.3 + * + * @param rawExcludeFilters + * list of rawExcludeFilter */ - @Override - public void setBeanName(String name) { - this.beanName = name; + public void setRawExcludeFilters(List> rawExcludeFilters) { + this.rawExcludeFilters = rawExcludeFilters; } /** - * This property specifies the parent that the scanner will search for. + * Specifies which {@code SqlSessionTemplate} to use in the case that there is more than one in the spring context. + * Usually this is only needed when you have more than one datasource. *

- * The scanner will register all interfaces in the base package that also have the - * specified interface class as a parent. + * + * @deprecated Use {@link #setSqlSessionTemplateBeanName(String)} instead + * + * @param sqlSessionTemplate + * a template of SqlSession + */ + @Deprecated + public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { + this.sqlSessionTemplate = sqlSessionTemplate; + } + + /** + * Specifies which {@code SqlSessionTemplate} to use in the case that there is more than one in the spring context. + * Usually this is only needed when you have more than one datasource. *

- * Note this can be combined with annotationClass. + * Note bean names are used, not bean references. This is because the scanner loads early during the start process and + * it is too early to build mybatis object instances. * - * @param superClass parent class + * @since 1.1.0 + * + * @param sqlSessionTemplateName + * Bean name of the {@code SqlSessionTemplate} */ - public void setMarkerInterface(Class superClass) { - this.markerInterface = superClass; - if (Marker.class.isAssignableFrom(superClass)) { - mapperHelper.registerMapper(superClass); - } + public void setSqlSessionTemplateBeanName(String sqlSessionTemplateName) { + this.sqlSessionTemplateBeanName = sqlSessionTemplateName; } /** - * @param processPropertyPlaceHolders - * @since 1.1.1 + * 属性注入 + * + * @param properties */ - public void setProcessPropertyPlaceHolders(boolean processPropertyPlaceHolders) { - this.processPropertyPlaceHolders = processPropertyPlaceHolders; + public void setProperties(Properties properties) { + mapperHelper.setProperties(properties); } /** - * Specifies which {@code SqlSessionFactory} to use in the case that there is - * more than one in the spring context. Usually this is only needed when you - * have more than one datasource. + * Specifies which {@code SqlSessionFactory} to use in the case that there is more than one in the spring context. + * Usually this is only needed when you have more than one datasource. *

* - * @param sqlSessionFactory * @deprecated Use {@link #setSqlSessionFactoryBeanName(String)} instead. + * + * @param sqlSessionFactory + * a factory of SqlSession */ @Deprecated public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { @@ -359,58 +301,315 @@ public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { } /** - * Specifies which {@code SqlSessionFactory} to use in the case that there is - * more than one in the spring context. Usually this is only needed when you - * have more than one datasource. + * Specifies which {@code SqlSessionFactory} to use in the case that there is more than one in the spring context. + * Usually this is only needed when you have more than one datasource. *

- * Note bean names are used, not bean references. This is because the scanner - * loads early during the start process and it is too early to build mybatis - * object instances. + * Note bean names are used, not bean references. This is because the scanner loads early during the start process and + * it is too early to build mybatis object instances. * - * @param sqlSessionFactoryName Bean name of the {@code SqlSessionFactory} * @since 1.1.0 + * + * @param sqlSessionFactoryName + * Bean name of the {@code SqlSessionFactory} */ public void setSqlSessionFactoryBeanName(String sqlSessionFactoryName) { this.sqlSessionFactoryBeanName = sqlSessionFactoryName; } /** - * Specifies which {@code SqlSessionTemplate} to use in the case that there is - * more than one in the spring context. Usually this is only needed when you - * have more than one datasource. + * Specifies a flag that whether execute a property placeholder processing or not. *

+ * The default is {@literal false}. This means that a property placeholder processing does not execute. * - * @param sqlSessionTemplate - * @deprecated Use {@link #setSqlSessionTemplateBeanName(String)} instead + * @since 1.1.1 + * + * @param processPropertyPlaceHolders + * a flag that whether execute a property placeholder processing or not */ - @Deprecated - public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { - this.sqlSessionTemplate = sqlSessionTemplate; + public void setProcessPropertyPlaceHolders(boolean processPropertyPlaceHolders) { + this.processPropertyPlaceHolders = processPropertyPlaceHolders; + } + + /** + * The class of the {@link MapperFactoryBean} to return a mybatis proxy as spring bean. + * + * @param mapperFactoryBeanClass + * The class of the MapperFactoryBean + * + * @since 2.0.1 + */ + public void setMapperFactoryBeanClass(Class mapperFactoryBeanClass) { + this.mapperFactoryBeanClass = mapperFactoryBeanClass; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Override + public void setBeanName(String name) { + this.beanName = name; + } + + /** + * Gets beanNameGenerator to be used while running the scanner. + * + * @return the beanNameGenerator BeanNameGenerator that has been configured + * + * @since 1.2.0 + */ + public BeanNameGenerator getNameGenerator() { + return nameGenerator; } /** - * Specifies which {@code SqlSessionTemplate} to use in the case that there is - * more than one in the spring context. Usually this is only needed when you - * have more than one datasource. + * Sets beanNameGenerator to be used while running the scanner. + * + * @param nameGenerator + * the beanNameGenerator to set + * + * @since 1.2.0 + */ + public void setNameGenerator(BeanNameGenerator nameGenerator) { + this.nameGenerator = nameGenerator; + } + + /** + * Sets the default scope of scanned mappers. *

- * Note bean names are used, not bean references. This is because the scanner - * loads early during the start process and it is too early to build mybatis - * object instances. + * Default is {@code null} (equiv to singleton). + *

* - * @param sqlSessionTemplateName Bean name of the {@code SqlSessionTemplate} - * @since 1.1.0 + * @param defaultScope + * the default scope + * + * @since 2.0.6 */ - public void setSqlSessionTemplateBeanName(String sqlSessionTemplateName) { - this.sqlSessionTemplateBeanName = sqlSessionTemplateName; + public void setDefaultScope(String defaultScope) { + this.defaultScope = defaultScope; + } + + @Override + public void afterPropertiesSet() throws Exception { + notNull(this.basePackage, "Property 'basePackage' is required"); + } + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { + // left intentionally blank + } + + @Override + public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) { + if (this.processPropertyPlaceHolders) { + processPropertyPlaceHolders(); + } + + var scanner = new ClassPathMapperScanner(registry, getEnvironment()); + scanner.setAddToConfig(this.addToConfig); + scanner.setAnnotationClass(this.annotationClass); + scanner.setMarkerInterface(this.markerInterface); + scanner.setExcludeFilters(this.excludeFilters = mergeExcludeFilters()); + scanner.setSqlSessionFactory(this.sqlSessionFactory); + scanner.setSqlSessionTemplate(this.sqlSessionTemplate); + scanner.setSqlSessionFactoryBeanName(this.sqlSessionFactoryBeanName); + scanner.setSqlSessionTemplateBeanName(this.sqlSessionTemplateBeanName); + scanner.setResourceLoader(this.applicationContext); + scanner.setBeanNameGenerator(this.nameGenerator); + scanner.setMapperFactoryBeanClass(this.mapperFactoryBeanClass); + if (StringUtils.hasText(lazyInitialization)) { + scanner.setLazyInitialization(Boolean.parseBoolean(lazyInitialization)); + } + if (StringUtils.hasText(defaultScope)) { + scanner.setDefaultScope(defaultScope); + } + if (StringUtils.hasText(mapperHelperBeanName)) { + scanner.setMapperHelperBeanName(mapperHelperBeanName); + } + scanner.registerFilters(); + //设置通用 Mapper + scanner.setMapperHelper(this.mapperHelper); + scanner.scan( + StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)); + } + + /* + * BeanDefinitionRegistries are called early in application startup, before BeanFactoryPostProcessors. This means that + * PropertyResourceConfigurers will not have been loaded and any property substitution of this class' properties will + * fail. To avoid this, find any PropertyResourceConfigurers defined in the context and run them on this class' bean + * definition. Then update the values. + */ + private void processPropertyPlaceHolders() { + Map prcs = applicationContext.getBeansOfType(PropertyResourceConfigurer.class, + false, false); + + if (!prcs.isEmpty() && applicationContext instanceof ConfigurableApplicationContext) { + var mapperScannerBean = ((ConfigurableApplicationContext) applicationContext).getBeanFactory() + .getBeanDefinition(beanName); + + // PropertyResourceConfigurer does not expose any methods to explicitly perform + // property placeholder substitution. Instead, create a BeanFactory that just + // contains this mapper scanner and post process the factory. + var factory = new DefaultListableBeanFactory(); + factory.registerBeanDefinition(beanName, mapperScannerBean); + + for (PropertyResourceConfigurer prc : prcs.values()) { + prc.postProcessBeanFactory(factory); + } + + PropertyValues values = mapperScannerBean.getPropertyValues(); + + this.basePackage = getPropertyValue("basePackage", values); + this.sqlSessionFactoryBeanName = getPropertyValue("sqlSessionFactoryBeanName", values); + this.sqlSessionTemplateBeanName = getPropertyValue("sqlSessionTemplateBeanName", values); + this.lazyInitialization = getPropertyValue("lazyInitialization", values); + this.defaultScope = getPropertyValue("defaultScope", values); + this.rawExcludeFilters = getPropertyValueForTypeFilter("rawExcludeFilters", values); + } + this.basePackage = Optional.ofNullable(this.basePackage).map(getEnvironment()::resolvePlaceholders).orElse(null); + this.sqlSessionFactoryBeanName = Optional.ofNullable(this.sqlSessionFactoryBeanName) + .map(getEnvironment()::resolvePlaceholders).orElse(null); + this.sqlSessionTemplateBeanName = Optional.ofNullable(this.sqlSessionTemplateBeanName) + .map(getEnvironment()::resolvePlaceholders).orElse(null); + this.lazyInitialization = Optional.ofNullable(this.lazyInitialization).map(getEnvironment()::resolvePlaceholders) + .orElse(null); + this.defaultScope = Optional.ofNullable(this.defaultScope).map(getEnvironment()::resolvePlaceholders).orElse(null); + } + + private Environment getEnvironment() { + return this.applicationContext.getEnvironment(); + } + + private String getPropertyValue(String propertyName, PropertyValues values) { + var property = values.getPropertyValue(propertyName); + + if (property == null) { + return null; + } + + var value = property.getValue(); + + if (value == null) { + return null; + } + if (value instanceof String) { + return value.toString(); + } + if (value instanceof TypedStringValue) { + return ((TypedStringValue) value).getValue(); + } + return null; + } + + @SuppressWarnings("unchecked") + private List> getPropertyValueForTypeFilter(String propertyName, PropertyValues values) { + var property = values.getPropertyValue(propertyName); + Object value; + if (property == null || (value = property.getValue()) == null || !(value instanceof List)) { + return null; + } + return (List>) value; + } + + private List mergeExcludeFilters() { + List typeFilters = new ArrayList<>(); + if (this.rawExcludeFilters == null || this.rawExcludeFilters.isEmpty()) { + return this.excludeFilters; + } + if (this.excludeFilters != null && !this.excludeFilters.isEmpty()) { + typeFilters.addAll(this.excludeFilters); + } + try { + for (Map typeFilter : this.rawExcludeFilters) { + typeFilters.add( + createTypeFilter(typeFilter.get("type"), typeFilter.get("expression"), this.getClass().getClassLoader())); + } + } catch (ClassNotFoundException exception) { + throw new RuntimeException("ClassNotFoundException occur when to load the Specified excludeFilter classes.", + exception); + } + return typeFilters; + } + + @SuppressWarnings("unchecked") + private TypeFilter createTypeFilter(String filterType, String expression, @Nullable ClassLoader classLoader) + throws ClassNotFoundException { + + if (this.processPropertyPlaceHolders) { + expression = this.getEnvironment().resolvePlaceholders(expression); + } + + switch (filterType) { + case "annotation": + Class filterAnno = ClassUtils.forName(expression, classLoader); + if (!Annotation.class.isAssignableFrom(filterAnno)) { + throw new IllegalArgumentException( + "Class is not assignable to [" + Annotation.class.getName() + "]: " + expression); + } + return new AnnotationTypeFilter((Class) filterAnno); + case "custom": + Class filterClass = ClassUtils.forName(expression, classLoader); + if (!TypeFilter.class.isAssignableFrom(filterClass)) { + throw new IllegalArgumentException( + "Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression); + } + return (TypeFilter) BeanUtils.instantiateClass(filterClass); + case "assignable": + return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader)); + case "regex": + return new RegexPatternTypeFilter(Pattern.compile(expression)); + case "aspectj": + return new AspectJTypeFilter(expression, classLoader); + default: + throw new IllegalArgumentException("Unsupported filter type: " + filterType); + } + } + + public void setMapperHelperBeanName(String mapperHelperBeanName) { + this.mapperHelperBeanName = mapperHelperBeanName; } /** - * 属性注入 + * 从环境变量中获取 mapper 配置信息 + * + * @param environment + */ + public void setMapperProperties(Environment environment) { + Config config = SpringBootBindUtil.bind(environment, Config.class, Config.PREFIX); + if (mapperHelper == null) { + mapperHelper = new MapperHelper(); + } + if (config != null) { + mapperHelper.setConfig(config); + } + } + + /** + * 从 properties 数组获取 mapper 配置信息 * * @param properties */ - public void setProperties(Properties properties) { - mapperHelper.setProperties(properties); + public void setMapperProperties(String[] properties) { + if (mapperHelper == null) { + mapperHelper = new MapperHelper(); + } + Properties props = new Properties(); + for (String property : properties) { + property = property.trim(); + int index = property.indexOf("="); + if (index < 0) { + throw new MapperException("通过 @MapperScan 注解的 properties 参数配置出错:" + property + " !\n" + + "请保证配置项按 properties 文件格式要求进行配置,例如:\n" + + "properties = {\n" + + "\t\"mappers=tk.mybatis.mapper.common.Mapper\",\n" + + "\t\"notEmpty=true\"\n" + + "}" + ); + } + props.put(property.substring(0, index).trim(), property.substring(index + 1).trim()); + } + mapperHelper.setProperties(props); } } diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/SpringBootBindUtil.java b/spring/src/main/java/tk/mybatis/spring/mapper/SpringBootBindUtil.java index de49c343b..34a4ae9d3 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/SpringBootBindUtil.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/SpringBootBindUtil.java @@ -24,14 +24,11 @@ package tk.mybatis.spring.mapper; -import org.springframework.beans.MutablePropertyValues; -import org.springframework.beans.PropertyValues; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; -import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.Map; /** * @author liuzh @@ -39,99 +36,20 @@ */ public abstract class SpringBootBindUtil { - public static final IBind BIND; + private static final Logger LOGGER = LoggerFactory.getLogger(SpringBootBindUtil.class); - static { - IBind bind; + public static T bind(Environment environment, Class targetClass, String prefix) { try { - //boot2 - Class.forName("org.springframework.boot.context.properties.bind.Binder"); - bind = new SpringBoot2Bind(); + Class binderClass = Class.forName("org.springframework.boot.context.properties.bind.Binder"); + Method getMethod = binderClass.getDeclaredMethod("get", Environment.class); + Method bindMethod = binderClass.getDeclaredMethod("bind", String.class, Class.class); + Object binder = getMethod.invoke(null, environment); + Object bindResult = bindMethod.invoke(binder, prefix, targetClass); + Method getMethodResult = bindResult.getClass().getDeclaredMethod("get"); + return (T) getMethodResult.invoke(bindResult); } catch (Exception e) { - //boot1 - bind = new SpringBoot1Bind(); - } - BIND = bind; - } - - public static T bind(Environment environment, Class targetClass, String prefix) { - return BIND.bind(environment, targetClass, prefix); - } - - public interface IBind { - T bind(Environment environment, Class targetClass, String prefix); - } - - /** - * 使用 Spring Boot 1.x 方式绑定 - */ - public static class SpringBoot1Bind implements IBind { - @Override - public T bind(Environment environment, Class targetClass, String prefix) { - /** - 为了方便以后直接依赖 Spring Boot 2.x 时不需要改动代码,这里也使用反射 - try { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment); - Map properties = resolver.getSubProperties(""); - T target = targetClass.newInstance(); - RelaxedDataBinder binder = new RelaxedDataBinder(target, prefix); - binder.bind(new MutablePropertyValues(properties)); - return target; - } catch (Exception e) { - throw new RuntimeException(e); - } - 下面是这段代码的反射实现 - */ - try { - //反射提取配置信息 - Class resolverClass = Class.forName("org.springframework.boot.bind.RelaxedPropertyResolver"); - Constructor resolverConstructor = resolverClass.getDeclaredConstructor(PropertyResolver.class); - Method getSubPropertiesMethod = resolverClass.getDeclaredMethod("getSubProperties", String.class); - Object resolver = resolverConstructor.newInstance(environment); - Map properties = (Map) getSubPropertiesMethod.invoke(resolver, ""); - //创建结果类 - T target = targetClass.newInstance(); - //反射使用 org.springframework.boot.bind.RelaxedDataBinder - Class binderClass = Class.forName("org.springframework.boot.bind.RelaxedDataBinder"); - Constructor binderConstructor = binderClass.getDeclaredConstructor(Object.class, String.class); - Method bindMethod = binderClass.getMethod("bind", PropertyValues.class); - //创建 binder 并绑定数据 - Object binder = binderConstructor.newInstance(target, prefix); - bindMethod.invoke(binder, new MutablePropertyValues(properties)); - return target; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - - /** - * 使用 Spring Boot 2.x 方式绑定 - */ - public static class SpringBoot2Bind implements IBind { - @Override - public T bind(Environment environment, Class targetClass, String prefix) { - /** - 由于不能同时依赖不同的两个版本,所以使用反射实现下面的代码 - Binder binder = Binder.get(environment); - return binder.bind(prefix, targetClass).get(); - 下面是这两行代码的完全反射版本 - */ - try { - Class bindClass = Class.forName("org.springframework.boot.context.properties.bind.Binder"); - Method getMethod = bindClass.getDeclaredMethod("get", Environment.class); - Method bindMethod = bindClass.getDeclaredMethod("bind", String.class, Class.class); - Object bind = getMethod.invoke(null, environment); - Object bindResult = bindMethod.invoke(bind, prefix, targetClass); - Method resultGetMethod = bindResult.getClass().getDeclaredMethod("get"); - Method isBoundMethod = bindResult.getClass().getDeclaredMethod("isBound"); - if ((Boolean) isBoundMethod.invoke(bindResult)) { - return (T) resultGetMethod.invoke(bindResult); - } - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } + LOGGER.warn("Bind " + targetClass + " error", e); + return null; } } diff --git a/spring/src/test/java/tk/mybatis/mapper/annotation/SpringAnnotationTest.java b/spring/src/test/java/tk/mybatis/mapper/annotation/SpringAnnotationTest.java index fe273f3e0..3169b5041 100644 --- a/spring/src/test/java/tk/mybatis/mapper/annotation/SpringAnnotationTest.java +++ b/spring/src/test/java/tk/mybatis/mapper/annotation/SpringAnnotationTest.java @@ -10,7 +10,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; -import tk.mybatis.mapper.MapperException; import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.entity.Config; import tk.mybatis.mapper.mapperhelper.MapperHelper; @@ -70,7 +69,7 @@ public void testMyBatisConfiguration() { Assert.assertEquals(183, countries.size()); } - @Test(expected = MapperException.class) + @Test(expected = Exception.class) public void testMyBatisConfigPropertiesError() { applicationContext.register(MyBatisConfigPropertiesError.class); startContext(); From 991b693ffbdbb6bfd0e9ac9e08ee2f74c9b03657 Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 19 Aug 2024 23:45:55 +0800 Subject: [PATCH 094/109] 5.0.0-rc1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b6ea3b8f6..41868225d 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 5.0.0-SNAPSHOT + 5.0.0-rc1 17 17 UTF-8 From bf0474fb977344f6c056f7165bc11bf55bcc43ac Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 19 Aug 2024 23:53:51 +0800 Subject: [PATCH 095/109] github action jdk17 --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0e954b254..e9281dc66 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: - name: Set up Maven Central Repository uses: actions/setup-java@v2 with: - java-version: '8' + java-version: '17' distribution: 'adopt' server-id: ossrh server-username: MAVEN_USERNAME diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 460dee580..60185440c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Maven Central Repository uses: actions/setup-java@v2 with: - java-version: '8' + java-version: '17' distribution: 'adopt' - name: Run the Maven verify phase run: mvn --batch-mode --update-snapshots -P dev test \ No newline at end of file From 50cfbab79b36283f9b91d900dfe568cdbe2d1ece Mon Sep 17 00:00:00 2001 From: liuzh Date: Tue, 20 Aug 2024 21:27:04 +0800 Subject: [PATCH 096/109] =?UTF-8?q?=E5=AE=8C=E5=96=84spring=20boot?= =?UTF-8?q?=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 39 +- .../mapper-spring-boot-autoconfigure/pom.xml | 16 + .../MapperAutoConfiguration.java | 251 ++++++--- ...pendsOnDatabaseInitializationDetector.java | 24 + ...ybatisLanguageDriverAutoConfiguration.java | 136 +++++ .../autoconfigure/MybatisProperties.java | 529 +++++++++++++++++- .../mapper/autoconfigure/SpringBootVFS.java | 80 ++- .../SqlSessionFactoryBeanCustomizer.java | 21 + ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../src/main/resources/application.properties | 6 +- .../src/main/resources/logback.xml | 10 + .../mybatis/sample/SampleXmlApplication.java | 2 + .../src/main/resources/application.yml | 2 + .../src/main/resources/logback.xml | 10 + .../spring/annotation/MapperScans.java | 8 +- 15 files changed, 982 insertions(+), 153 deletions(-) create mode 100644 spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisDependsOnDatabaseInitializationDetector.java create mode 100644 spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisLanguageDriverAutoConfiguration.java create mode 100644 spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SqlSessionFactoryBeanCustomizer.java create mode 100644 spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/logback.xml create mode 100644 spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/logback.xml diff --git a/pom.xml b/pom.xml index 41868225d..da994339a 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 5.0.0-rc1 + 5.0.0-SNAPSHOT 17 17 UTF-8 @@ -44,10 +44,14 @@ 3.1.0 2.0.16 3.5.16 + 1.2.4 + 2.1.2 + 1.0.4 + 4.13.2 2.7.3 - 1.5.7 + 1.5.6 @@ -78,10 +82,35 @@ mybatis ${mybatis.version} + + org.mybatis.scripting + mybatis-freemarker + ${mybatis-freemarker.version} + true + + + org.mybatis.scripting + mybatis-velocity + ${mybatis-velocity.version} + true + + + org.mybatis.scripting + mybatis-thymeleaf + ${mybatis-thymeleaf.version} + true + org.slf4j slf4j-api ${slf4j.version} + true + + + ch.qos.logback + logback-classic + ${logback.version} + true @@ -91,12 +120,6 @@ ${junit.version} test - - ch.qos.logback - logback-classic - ${logback.version} - test - org.hsqldb hsqldb diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml index 7b9be7921..97e10a6ad 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/pom.xml @@ -41,6 +41,22 @@ spring-boot-autoconfigure + + org.mybatis.scripting + mybatis-freemarker + true + + + org.mybatis.scripting + mybatis-velocity + true + + + org.mybatis.scripting + mybatis-thymeleaf + true + + tk.mybatis mapper-core diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java index 344bbdd5d..b6c587bda 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java @@ -1,35 +1,50 @@ -/** - * Copyright 2015-2018 the original author or authors. - *

- * 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. +/* + * Copyright 2015-2022 the original author or authors. + * + * 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 + * + * https://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 tk.mybatis.mapper.autoconfigure; +import java.beans.PropertyDescriptor; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.sql.DataSource; + import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.mapping.DatabaseIdProvider; import org.apache.ibatis.plugin.Interceptor; +import org.apache.ibatis.scripting.LanguageDriver; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.type.TypeHandler; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; +import org.springframework.beans.BeanWrapper; +import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.boot.autoconfigure.AutoConfigurationPackages; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -54,35 +69,26 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; -import tk.mybatis.spring.annotation.BaseProperties; -import tk.mybatis.spring.mapper.ClassPathMapperScanner; import tk.mybatis.spring.mapper.MapperFactoryBean; -import tk.mybatis.spring.mapper.SpringBootBindUtil; - -import javax.sql.DataSource; -import java.util.Arrays; -import java.util.List; +import tk.mybatis.spring.mapper.MapperScannerConfigurer; /** - * {@link EnableAutoConfiguration Auto-Configuration} for Mybatis. Contributes a - * {@link SqlSessionFactory} and a {@link SqlSessionTemplate}. - * - * If {@link org.mybatis.spring.annotation.MapperScan} is used, or a - * configuration file is specified as a property, those will be considered, - * otherwise this auto-configuration will attempt to register mappers based on - * the interface definitions in or under the root auto-configuration package. + * {@link EnableAutoConfiguration Auto-Configuration} for Mybatis. Contributes a {@link SqlSessionFactory} and a + * {@link SqlSessionTemplate}. If {@link tk.mybatis.spring.annotation.MapperScan} is used, or a configuration file is + * specified as a property, those will be considered, otherwise this auto-configuration will attempt to register mappers + * based on the interface definitions in or under the root auto-configuration package. * * @author Eddú Meléndez * @author Josh Long * @author Kazuki Shimizu * @author Eduardo Macarrón */ -@org.springframework.context.annotation.Configuration +@org.springframework.context.annotation.Configuration(proxyBeanMethods = false) @ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class}) @ConditionalOnSingleCandidate(DataSource.class) @EnableConfigurationProperties(MybatisProperties.class) -@AutoConfigureAfter(DataSourceAutoConfiguration.class) @AutoConfigureBefore(name = "org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration") +@AutoConfigureAfter({DataSourceAutoConfiguration.class, MybatisLanguageDriverAutoConfiguration.class}) public class MapperAutoConfiguration implements InitializingBean { private static final Logger logger = LoggerFactory.getLogger(MapperAutoConfiguration.class); @@ -91,22 +97,31 @@ public class MapperAutoConfiguration implements InitializingBean { private final Interceptor[] interceptors; + private final TypeHandler[] typeHandlers; + + private final LanguageDriver[] languageDrivers; + private final ResourceLoader resourceLoader; private final DatabaseIdProvider databaseIdProvider; private final List configurationCustomizers; - public MapperAutoConfiguration(MybatisProperties properties, - ObjectProvider interceptorsProvider, - ResourceLoader resourceLoader, - ObjectProvider databaseIdProvider, - ObjectProvider> configurationCustomizersProvider) { + private final List sqlSessionFactoryBeanCustomizers; + + public MapperAutoConfiguration(MybatisProperties properties, ObjectProvider interceptorsProvider, + ObjectProvider typeHandlersProvider, ObjectProvider languageDriversProvider, + ResourceLoader resourceLoader, ObjectProvider databaseIdProvider, + ObjectProvider> configurationCustomizersProvider, + ObjectProvider> sqlSessionFactoryBeanCustomizers) { this.properties = properties; this.interceptors = interceptorsProvider.getIfAvailable(); + this.typeHandlers = typeHandlersProvider.getIfAvailable(); + this.languageDrivers = languageDriversProvider.getIfAvailable(); this.resourceLoader = resourceLoader; this.databaseIdProvider = databaseIdProvider.getIfAvailable(); this.configurationCustomizers = configurationCustomizersProvider.getIfAvailable(); + this.sqlSessionFactoryBeanCustomizers = sqlSessionFactoryBeanCustomizers.getIfAvailable(); } @Override @@ -117,8 +132,8 @@ public void afterPropertiesSet() { private void checkConfigFileExists() { if (this.properties.isCheckConfigLocation() && StringUtils.hasText(this.properties.getConfigLocation())) { Resource resource = this.resourceLoader.getResource(this.properties.getConfigLocation()); - Assert.state(resource.exists(), "Cannot find config location: " + resource - + " (please add config file or check your Mybatis configuration)"); + Assert.state(resource.exists(), + "Cannot find config location: " + resource + " (please add config file or check your Mybatis configuration)"); } } @@ -127,7 +142,9 @@ private void checkConfigFileExists() { public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); factory.setDataSource(dataSource); - factory.setVfs(SpringBootVFS.class); + if (properties.getConfiguration() == null || properties.getConfiguration().getVfsImpl() == null) { + factory.setVfs(SpringBootVFS.class); + } if (StringUtils.hasText(this.properties.getConfigLocation())) { factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation())); } @@ -150,18 +167,41 @@ public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Excepti if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) { factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage()); } - if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) { - factory.setMapperLocations(this.properties.resolveMapperLocations()); + if (!ObjectUtils.isEmpty(this.typeHandlers)) { + factory.setTypeHandlers(this.typeHandlers); } - + Resource[] mapperLocations = this.properties.resolveMapperLocations(); + if (!ObjectUtils.isEmpty(mapperLocations)) { + factory.setMapperLocations(mapperLocations); + } + Set factoryPropertyNames = Stream + .of(new BeanWrapperImpl(SqlSessionFactoryBean.class).getPropertyDescriptors()).map(PropertyDescriptor::getName) + .collect(Collectors.toSet()); + Class defaultLanguageDriver = this.properties.getDefaultScriptingLanguageDriver(); + if (factoryPropertyNames.contains("scriptingLanguageDrivers") && !ObjectUtils.isEmpty(this.languageDrivers)) { + // Need to mybatis-spring 2.0.2+ + factory.setScriptingLanguageDrivers(this.languageDrivers); + if (defaultLanguageDriver == null && this.languageDrivers.length == 1) { + defaultLanguageDriver = this.languageDrivers[0].getClass(); + } + } + if (factoryPropertyNames.contains("defaultScriptingLanguageDriver")) { + // Need to mybatis-spring 2.0.2+ + factory.setDefaultScriptingLanguageDriver(defaultLanguageDriver); + } + applySqlSessionFactoryBeanCustomizers(factory); return factory.getObject(); } private void applyConfiguration(SqlSessionFactoryBean factory) { - Configuration configuration = this.properties.getConfiguration(); - if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) { + MybatisProperties.CoreConfiguration coreConfiguration = this.properties.getConfiguration(); + Configuration configuration = null; + if (coreConfiguration != null || !StringUtils.hasText(this.properties.getConfigLocation())) { configuration = new Configuration(); } + if (configuration != null && coreConfiguration != null) { + coreConfiguration.applyTo(configuration); + } if (configuration != null && !CollectionUtils.isEmpty(this.configurationCustomizers)) { for (ConfigurationCustomizer customizer : this.configurationCustomizers) { customizer.customize(configuration); @@ -170,6 +210,14 @@ private void applyConfiguration(SqlSessionFactoryBean factory) { factory.setConfiguration(configuration); } + private void applySqlSessionFactoryBeanCustomizers(SqlSessionFactoryBean factory) { + if (!CollectionUtils.isEmpty(this.sqlSessionFactoryBeanCustomizers)) { + for (SqlSessionFactoryBeanCustomizer customizer : this.sqlSessionFactoryBeanCustomizers) { + customizer.customize(factory); + } + } + } + @Bean @ConditionalOnMissingBean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { @@ -182,91 +230,107 @@ public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory } /** - * This will just scan the same base package as Spring Boot does. If you want - * more power, you can explicitly use - * {@link org.mybatis.spring.annotation.MapperScan} but this will get typed - * mappers working correctly, out-of-the-box, similar to using Spring Data JPA - * repositories. + * This will just scan the same base package as Spring Boot does. If you want more power, you can explicitly use + * {@link tk.mybatis.spring.annotation.MapperScan} but this will get typed mappers working correctly, out-of-the-box, + * similar to using Spring Data JPA repositories. */ public static class AutoConfiguredMapperScannerRegistrar - implements BeanFactoryAware, ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware { + implements BeanFactoryAware, ResourceLoaderAware, EnvironmentAware, ImportBeanDefinitionRegistrar { private BeanFactory beanFactory; - private ResourceLoader resourceLoader; - private Environment environment; @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { + if (!AutoConfigurationPackages.has(this.beanFactory)) { + logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled."); + return; + } + logger.debug("Searching for mappers annotated with @Mapper"); - ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry, environment); - scanner.setMapperProperties(environment); - try { - if (this.resourceLoader != null) { - scanner.setResourceLoader(this.resourceLoader); - } - List packages = AutoConfigurationPackages.get(this.beanFactory); - if (logger.isDebugEnabled()) { - for (String pkg : packages) { - logger.debug("Using auto-configuration base package '{}'", pkg); - } - } - BaseProperties properties = SpringBootBindUtil.bind(environment, BaseProperties.class, BaseProperties.MYBATIS_PREFIX); - if (properties != null && properties.getBasePackages() != null && properties.getBasePackages().length > 0) { - packages.addAll(Arrays.asList(properties.getBasePackages())); - } else { - //设置了包名的情况下,不需要指定该注解 - scanner.setAnnotationClass(Mapper.class); - } + List packages = AutoConfigurationPackages.get(this.beanFactory); + if (logger.isDebugEnabled()) { + packages.forEach(pkg -> logger.debug("Using auto-configuration base package '{}'", pkg)); + } - String lazyInitialization = environment.getProperty("mybatis.lazy-initialization"); - if (StringUtils.hasText(lazyInitialization)) { - scanner.setLazyInitialization(Boolean.valueOf(lazyInitialization)); - } + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class); + builder.addPropertyValue("processPropertyPlaceHolders", true); + builder.addPropertyValue("annotationClass", Mapper.class); + builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(packages)); + builder.addPropertyValue("mapperProperties", this.environment); + BeanWrapper beanWrapper = new BeanWrapperImpl(MapperScannerConfigurer.class); + Set propertyNames = Stream.of(beanWrapper.getPropertyDescriptors()).map(PropertyDescriptor::getName) + .collect(Collectors.toSet()); + if (propertyNames.contains("lazyInitialization")) { + // Need to mybatis-spring 2.0.2+ + builder.addPropertyValue("lazyInitialization", "${mybatis.lazy-initialization:false}"); + } + if (propertyNames.contains("defaultScope")) { + // Need to mybatis-spring 2.0.6+ + builder.addPropertyValue("defaultScope", "${mybatis.mapper-default-scope:}"); + } - scanner.registerFilters(); - scanner.doScan(StringUtils.toStringArray(packages)); - } catch (IllegalStateException ex) { - logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex); + // for spring-native + boolean injectSqlSession = environment.getProperty("mybatis.inject-sql-session-on-mapper-scan", Boolean.class, + Boolean.TRUE); + if (injectSqlSession && this.beanFactory instanceof ListableBeanFactory) { + ListableBeanFactory listableBeanFactory = (ListableBeanFactory) this.beanFactory; + Optional sqlSessionTemplateBeanName = Optional + .ofNullable(getBeanNameForType(SqlSessionTemplate.class, listableBeanFactory)); + Optional sqlSessionFactoryBeanName = Optional + .ofNullable(getBeanNameForType(SqlSessionFactory.class, listableBeanFactory)); + if (sqlSessionTemplateBeanName.isPresent() || !sqlSessionFactoryBeanName.isPresent()) { + builder.addPropertyValue("sqlSessionTemplateBeanName", + sqlSessionTemplateBeanName.orElse("sqlSessionTemplate")); + } else { + builder.addPropertyValue("sqlSessionFactoryBeanName", sqlSessionFactoryBeanName.get()); + } } + builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); + + registry.registerBeanDefinition(MapperScannerConfigurer.class.getName(), builder.getBeanDefinition()); } @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; } + @Override + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + } + @Override public void setEnvironment(Environment environment) { this.environment = environment; } - @Override - public void setResourceLoader(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; + private String getBeanNameForType(Class type, ListableBeanFactory factory) { + String[] beanNames = factory.getBeanNamesForType(type); + return beanNames.length > 0 ? beanNames[0] : null; } + } /** - * {@link org.mybatis.spring.annotation.MapperScan} ultimately ends up - * creating instances of {@link MapperFactoryBean}. If - * {@link org.mybatis.spring.annotation.MapperScan} is used then this - * auto-configuration is not needed. If it is _not_ used, however, then this - * will bring in a bean registrar and automatically register components based - * on the same component-scanning path as Spring Boot itself. + * If mapper registering configuration or mapper scanning configuration not present, this configuration allow to scan + * mappers based on the same component-scanning path as Spring Boot itself. */ - @org.springframework.context.annotation.Configuration - @Import({AutoConfiguredMapperScannerRegistrar.class}) - @ConditionalOnMissingBean(MapperFactoryBean.class) + @org.springframework.context.annotation.Configuration(proxyBeanMethods = false) + @Import(AutoConfiguredMapperScannerRegistrar.class) + @ConditionalOnMissingBean({MapperFactoryBean.class, MapperScannerConfigurer.class}) public static class MapperScannerRegistrarNotFoundConfiguration implements InitializingBean { @Override public void afterPropertiesSet() { - logger.debug("No {} found.", MapperFactoryBean.class.getName()); + logger.debug( + "Not found configuration for registering mapper bean using @MapperScan, MapperFactoryBean and MapperScannerConfigurer."); } + } /** @@ -282,4 +346,5 @@ public MapperCacheDisabler mapperCacheDisabler() { } } + } diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisDependsOnDatabaseInitializationDetector.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisDependsOnDatabaseInitializationDetector.java new file mode 100644 index 000000000..26fa98b6d --- /dev/null +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisDependsOnDatabaseInitializationDetector.java @@ -0,0 +1,24 @@ +package tk.mybatis.mapper.autoconfigure; + +import java.util.Collections; +import java.util.Set; + +import org.mybatis.spring.SqlSessionTemplate; +import org.springframework.boot.sql.init.dependency.AbstractBeansOfTypeDependsOnDatabaseInitializationDetector; +import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector; + +/** + * {@link DependsOnDatabaseInitializationDetector} for Mybatis. + * + * @author Eddú Meléndez + * @since 2.3.0 + */ +class MybatisDependsOnDatabaseInitializationDetector + extends AbstractBeansOfTypeDependsOnDatabaseInitializationDetector { + + @Override + protected Set> getDependsOnDatabaseInitializationBeanTypes() { + return Collections.singleton(SqlSessionTemplate.class); + } + +} diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisLanguageDriverAutoConfiguration.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisLanguageDriverAutoConfiguration.java new file mode 100644 index 000000000..85c2a245c --- /dev/null +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisLanguageDriverAutoConfiguration.java @@ -0,0 +1,136 @@ +package tk.mybatis.mapper.autoconfigure; + +import org.apache.ibatis.scripting.LanguageDriver; +import org.mybatis.scripting.freemarker.FreeMarkerLanguageDriver; +import org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig; +import org.mybatis.scripting.thymeleaf.ThymeleafLanguageDriver; +import org.mybatis.scripting.thymeleaf.ThymeleafLanguageDriverConfig; +import org.mybatis.scripting.velocity.VelocityLanguageDriver; +import org.mybatis.scripting.velocity.VelocityLanguageDriverConfig; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * {@link EnableAutoConfiguration Auto-Configuration} for MyBatis's scripting language drivers. + * + * @author Kazuki Shimizu + * @since 2.1.0 + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass(LanguageDriver.class) +public class MybatisLanguageDriverAutoConfiguration { + + private static final String CONFIGURATION_PROPERTY_PREFIX = "mybatis.scripting-language-driver"; + + /** + * Configuration class for mybatis-freemarker 1.1.x or under. + */ + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(FreeMarkerLanguageDriver.class) + @ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig") + public static class LegacyFreeMarkerConfiguration { + @Bean + @ConditionalOnMissingBean + FreeMarkerLanguageDriver freeMarkerLanguageDriver() { + return new FreeMarkerLanguageDriver(); + } + } + + /** + * Configuration class for mybatis-freemarker 1.2.x or above. + */ + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass({FreeMarkerLanguageDriver.class, FreeMarkerLanguageDriverConfig.class}) + public static class FreeMarkerConfiguration { + @Bean + @ConditionalOnMissingBean + FreeMarkerLanguageDriver freeMarkerLanguageDriver(FreeMarkerLanguageDriverConfig config) { + return new FreeMarkerLanguageDriver(config); + } + + @Bean + @ConditionalOnMissingBean + @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".freemarker") + public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() { + return FreeMarkerLanguageDriverConfig.newInstance(); + } + } + + /** + * Configuration class for mybatis-velocity 2.0 or under. + */ + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(org.mybatis.scripting.velocity.Driver.class) + @ConditionalOnMissingClass("org.mybatis.scripting.velocity.VelocityLanguageDriverConfig") + @SuppressWarnings("deprecation") + public static class LegacyVelocityConfiguration { + @Bean + @ConditionalOnMissingBean + org.mybatis.scripting.velocity.Driver velocityLanguageDriver() { + return new org.mybatis.scripting.velocity.Driver(); + } + } + + /** + * Configuration class for mybatis-velocity 2.1.x or above. + */ + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass({VelocityLanguageDriver.class, VelocityLanguageDriverConfig.class}) + public static class VelocityConfiguration { + @Bean + @ConditionalOnMissingBean + VelocityLanguageDriver velocityLanguageDriver(VelocityLanguageDriverConfig config) { + return new VelocityLanguageDriver(config); + } + + @Bean + @ConditionalOnMissingBean + @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".velocity") + public VelocityLanguageDriverConfig velocityLanguageDriverConfig() { + return VelocityLanguageDriverConfig.newInstance(); + } + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(ThymeleafLanguageDriver.class) + public static class ThymeleafConfiguration { + @Bean + @ConditionalOnMissingBean + ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) { + return new ThymeleafLanguageDriver(config); + } + + @Bean + @ConditionalOnMissingBean + @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf") + public ThymeleafLanguageDriverConfig thymeleafLanguageDriverConfig() { + return ThymeleafLanguageDriverConfig.newInstance(); + } + + // This class provides to avoid the https://github.com/spring-projects/spring-boot/issues/21626 as workaround. + @SuppressWarnings("unused") + private static class MetadataThymeleafLanguageDriverConfig extends ThymeleafLanguageDriverConfig { + + @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.dialect") + @Override + public DialectConfig getDialect() { + return super.getDialect(); + } + + @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.template-file") + @Override + public TemplateFileConfig getTemplateFile() { + return super.getTemplateFile(); + } + + } + + } + +} + diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisProperties.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisProperties.java index 33130ffa6..fd6af07fa 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisProperties.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MybatisProperties.java @@ -15,20 +15,29 @@ */ package tk.mybatis.mapper.autoconfigure; +import org.apache.ibatis.io.VFS; +import org.apache.ibatis.logging.Log; +import org.apache.ibatis.mapping.ResultSetType; +import org.apache.ibatis.scripting.LanguageDriver; +import org.apache.ibatis.session.AutoMappingBehavior; +import org.apache.ibatis.session.AutoMappingUnknownColumnBehavior; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.LocalCacheScope; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.TypeHandler; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.NestedConfigurationProperty; +import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import tk.mybatis.spring.annotation.BaseProperties; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.Optional; import java.util.Properties; +import java.util.Set; +import java.util.stream.Stream; /** * Configuration properties for MyBatis. @@ -57,8 +66,8 @@ public class MybatisProperties extends BaseProperties { private String typeAliasesPackage; /** - * The super class for filtering type alias. - * If this not specifies, the MyBatis deal as type alias all classes that searched from typeAliasesPackage. + * The super class for filtering type alias. If this not specifies, the MyBatis deal as type alias all classes that + * searched from typeAliasesPackage. */ private Class typeAliasesSuperType; @@ -77,17 +86,21 @@ public class MybatisProperties extends BaseProperties { */ private ExecutorType executorType; + /** + * The default scripting language driver class. (Available when use together with mybatis-spring 2.0.2+) + */ + private Class defaultScriptingLanguageDriver; + /** * Externalized properties for MyBatis configuration. */ private Properties configurationProperties; /** - * A Configuration object for customize default settings. If {@link #configLocation} - * is specified, this property is not used. + * A Configuration object for customize default settings. If {@link #configLocation} is specified, this property is + * not used. */ - @NestedConfigurationProperty - private Configuration configuration; + private CoreConfiguration configuration; /** * @since 1.1.0 @@ -103,16 +116,6 @@ public void setConfigLocation(String configLocation) { this.configLocation = configLocation; } - @Deprecated - public String getConfig() { - return this.configLocation; - } - - @Deprecated - public void setConfig(String config) { - this.configLocation = config; - } - public String[] getMapperLocations() { return this.mapperLocations; } @@ -167,6 +170,20 @@ public void setExecutorType(ExecutorType executorType) { this.executorType = executorType; } + /** + * @since 2.1.0 + */ + public Class getDefaultScriptingLanguageDriver() { + return defaultScriptingLanguageDriver; + } + + /** + * @since 2.1.0 + */ + public void setDefaultScriptingLanguageDriver(Class defaultScriptingLanguageDriver) { + this.defaultScriptingLanguageDriver = defaultScriptingLanguageDriver; + } + /** * @since 1.2.0 */ @@ -181,22 +198,17 @@ public void setConfigurationProperties(Properties configurationProperties) { this.configurationProperties = configurationProperties; } - public Configuration getConfiguration() { + public CoreConfiguration getConfiguration() { return configuration; } - public void setConfiguration(Configuration configuration) { + public void setConfiguration(CoreConfiguration configuration) { this.configuration = configuration; } public Resource[] resolveMapperLocations() { - List resources = new ArrayList(); - if (this.mapperLocations != null) { - for (String mapperLocation : this.mapperLocations) { - resources.addAll(Arrays.asList(getResources(mapperLocation))); - } - } - return resources.toArray(new Resource[resources.size()]); + return Stream.of(Optional.ofNullable(this.mapperLocations).orElse(new String[0])) + .flatMap(location -> Stream.of(getResources(location))).toArray(Resource[]::new); } private Resource[] getResources(String location) { @@ -207,4 +219,463 @@ private Resource[] getResources(String location) { } } + /** + * The configuration properties for mybatis core module. + * + * @since 3.0.0 + */ + public static class CoreConfiguration { + + /** + * Specifies the TypeHandler used by default for Enum. + */ + Class defaultEnumTypeHandler; + /** + * Allows using RowBounds on nested statements. If allow, set the false. Default is false. + */ + private Boolean safeRowBoundsEnabled; + /** + * Allows using ResultHandler on nested statements. If allow, set the false. Default is true. + */ + private Boolean safeResultHandlerEnabled; + /** + * Enables automatic mapping from classic database column names A_COLUMN to camel case classic Java property names + * aColumn. Default is false. + */ + private Boolean mapUnderscoreToCamelCase; + /** + * When enabled, any method call will load all the lazy properties of the object. Otherwise, each property is loaded + * on demand (see also lazyLoadTriggerMethods). Default is false. + */ + private Boolean aggressiveLazyLoading; + /** + * Allows or disallows multiple ResultSets to be returned from a single statement (compatible driver required). + * Default is true. + */ + private Boolean multipleResultSetsEnabled; + /** + * Allows JDBC support for generated keys. A compatible driver is required. This setting forces generated keys to be + * used if set to true, as some drivers deny compatibility but still work (e.g. Derby). Default is false. + */ + private Boolean useGeneratedKeys; + /** + * Uses the column label instead of the column name. Different drivers behave differently in this respect. Refer to + * the driver documentation, or test out both modes to determine how your driver behaves. Default is true. + */ + private Boolean useColumnLabel; + /** + * Globally enables or disables any caches configured in any mapper under this configuration. Default is true. + */ + private Boolean cacheEnabled; + /** + * Specifies if setters or map's put method will be called when a retrieved value is null. It is useful when you + * rely on Map.keySet() or null value initialization. Note primitives such as (int,boolean,etc.) will not be set to + * null. Default is false. + */ + private Boolean callSettersOnNulls; + /** + * Allow referencing statement parameters by their actual names declared in the method signature. To use this + * feature, your project must be compiled in Java 8 with -parameters option. Default is true. + */ + private Boolean useActualParamName; + /** + * MyBatis, by default, returns null when all the columns of a returned row are NULL. When this setting is enabled, + * MyBatis returns an empty instance instead. Note that it is also applied to nested results (i.e. collectioin and + * association). Default is false. + */ + private Boolean returnInstanceForEmptyRow; + /** + * Removes extra whitespace characters from the SQL. Note that this also affects literal strings in SQL. Default is + * false. + */ + private Boolean shrinkWhitespacesInSql; + /** + * Specifies the default value of 'nullable' attribute on 'foreach' tag. Default is false. + */ + private Boolean nullableOnForEach; + /** + * When applying constructor auto-mapping, argument name is used to search the column to map instead of relying on + * the column order. Default is false. + */ + private Boolean argNameBasedConstructorAutoMapping; + /** + * Globally enables or disables lazy loading. When enabled, all relations will be lazily loaded. This value can be + * superseded for a specific relation by using the fetchType attribute on it. Default is False. + */ + private Boolean lazyLoadingEnabled; + /** + * Sets the number of seconds the driver will wait for a response from the database. + */ + private Integer defaultStatementTimeout; + /** + * Sets the driver a hint as to control fetching size for return results. This parameter value can be override by a + * query setting. + */ + private Integer defaultFetchSize; + /** + * MyBatis uses local cache to prevent circular references and speed up repeated nested queries. By default + * (SESSION) all queries executed during a session are cached. If localCacheScope=STATEMENT local session will be + * used just for statement execution, no data will be shared between two different calls to the same SqlSession. + * Default is SESSION. + */ + private LocalCacheScope localCacheScope; + /** + * Specifies the JDBC type for null values when no specific JDBC type was provided for the parameter. Some drivers + * require specifying the column JDBC type but others work with generic values like NULL, VARCHAR or OTHER. Default + * is OTHER. + */ + private JdbcType jdbcTypeForNull; + /** + * Specifies a scroll strategy when omit it per statement settings. + */ + private ResultSetType defaultResultSetType; + /** + * Configures the default executor. SIMPLE executor does nothing special. REUSE executor reuses prepared statements. + * BATCH executor reuses statements and batches updates. Default is SIMPLE. + */ + private ExecutorType defaultExecutorType; + /** + * Specifies if and how MyBatis should automatically map columns to fields/properties. NONE disables auto-mapping. + * PARTIAL will only auto-map results with no nested result mappings defined inside. FULL will auto-map result + * mappings of any complexity (containing nested or otherwise). Default is PARTIAL. + */ + private AutoMappingBehavior autoMappingBehavior; + /** + * Specify the behavior when detects an unknown column (or unknown property type) of automatic mapping target. + * Default is NONE. + */ + private AutoMappingUnknownColumnBehavior autoMappingUnknownColumnBehavior; + /** + * Specifies the prefix string that MyBatis will add to the logger names. + */ + private String logPrefix; + /** + * Specifies which Object's methods trigger a lazy load. Default is [equals,clone,hashCode,toString]. + */ + private Set lazyLoadTriggerMethods; + /** + * Specifies which logging implementation MyBatis should use. If this setting is not present logging implementation + * will be autodiscovered. + */ + private Class logImpl; + /** + * Specifies VFS implementations. + */ + private Class vfsImpl; + /** + * Specifies an sql provider class that holds provider method. This class apply to the type(or value) attribute on + * sql provider annotation(e.g. @SelectProvider), when these attribute was omitted. + */ + private Class defaultSqlProviderType; + /** + * Specifies the class that provides an instance of Configuration. The returned Configuration instance is used to + * load lazy properties of deserialized objects. This class must have a method with a signature static Configuration + * getConfiguration(). + */ + private Class configurationFactory; + + /** + * Specify any configuration variables. + */ + private Properties variables; + + /** + * Specifies the database identify value for switching query to use. + */ + private String databaseId; + + public Boolean getSafeRowBoundsEnabled() { + return safeRowBoundsEnabled; + } + + public void setSafeRowBoundsEnabled(Boolean safeRowBoundsEnabled) { + this.safeRowBoundsEnabled = safeRowBoundsEnabled; + } + + public Boolean getSafeResultHandlerEnabled() { + return safeResultHandlerEnabled; + } + + public void setSafeResultHandlerEnabled(Boolean safeResultHandlerEnabled) { + this.safeResultHandlerEnabled = safeResultHandlerEnabled; + } + + public Boolean getMapUnderscoreToCamelCase() { + return mapUnderscoreToCamelCase; + } + + public void setMapUnderscoreToCamelCase(Boolean mapUnderscoreToCamelCase) { + this.mapUnderscoreToCamelCase = mapUnderscoreToCamelCase; + } + + public Boolean getAggressiveLazyLoading() { + return aggressiveLazyLoading; + } + + public void setAggressiveLazyLoading(Boolean aggressiveLazyLoading) { + this.aggressiveLazyLoading = aggressiveLazyLoading; + } + + public Boolean getMultipleResultSetsEnabled() { + return multipleResultSetsEnabled; + } + + public void setMultipleResultSetsEnabled(Boolean multipleResultSetsEnabled) { + this.multipleResultSetsEnabled = multipleResultSetsEnabled; + } + + public Boolean getUseGeneratedKeys() { + return useGeneratedKeys; + } + + public void setUseGeneratedKeys(Boolean useGeneratedKeys) { + this.useGeneratedKeys = useGeneratedKeys; + } + + public Boolean getUseColumnLabel() { + return useColumnLabel; + } + + public void setUseColumnLabel(Boolean useColumnLabel) { + this.useColumnLabel = useColumnLabel; + } + + public Boolean getCacheEnabled() { + return cacheEnabled; + } + + public void setCacheEnabled(Boolean cacheEnabled) { + this.cacheEnabled = cacheEnabled; + } + + public Boolean getCallSettersOnNulls() { + return callSettersOnNulls; + } + + public void setCallSettersOnNulls(Boolean callSettersOnNulls) { + this.callSettersOnNulls = callSettersOnNulls; + } + + public Boolean getUseActualParamName() { + return useActualParamName; + } + + public void setUseActualParamName(Boolean useActualParamName) { + this.useActualParamName = useActualParamName; + } + + public Boolean getReturnInstanceForEmptyRow() { + return returnInstanceForEmptyRow; + } + + public void setReturnInstanceForEmptyRow(Boolean returnInstanceForEmptyRow) { + this.returnInstanceForEmptyRow = returnInstanceForEmptyRow; + } + + public Boolean getShrinkWhitespacesInSql() { + return shrinkWhitespacesInSql; + } + + public void setShrinkWhitespacesInSql(Boolean shrinkWhitespacesInSql) { + this.shrinkWhitespacesInSql = shrinkWhitespacesInSql; + } + + public Boolean getNullableOnForEach() { + return nullableOnForEach; + } + + public void setNullableOnForEach(Boolean nullableOnForEach) { + this.nullableOnForEach = nullableOnForEach; + } + + public Boolean getArgNameBasedConstructorAutoMapping() { + return argNameBasedConstructorAutoMapping; + } + + public void setArgNameBasedConstructorAutoMapping(Boolean argNameBasedConstructorAutoMapping) { + this.argNameBasedConstructorAutoMapping = argNameBasedConstructorAutoMapping; + } + + public String getLogPrefix() { + return logPrefix; + } + + public void setLogPrefix(String logPrefix) { + this.logPrefix = logPrefix; + } + + public Class getLogImpl() { + return logImpl; + } + + public void setLogImpl(Class logImpl) { + this.logImpl = logImpl; + } + + public Class getVfsImpl() { + return vfsImpl; + } + + public void setVfsImpl(Class vfsImpl) { + this.vfsImpl = vfsImpl; + } + + public Class getDefaultSqlProviderType() { + return defaultSqlProviderType; + } + + public void setDefaultSqlProviderType(Class defaultSqlProviderType) { + this.defaultSqlProviderType = defaultSqlProviderType; + } + + public LocalCacheScope getLocalCacheScope() { + return localCacheScope; + } + + public void setLocalCacheScope(LocalCacheScope localCacheScope) { + this.localCacheScope = localCacheScope; + } + + public JdbcType getJdbcTypeForNull() { + return jdbcTypeForNull; + } + + public void setJdbcTypeForNull(JdbcType jdbcTypeForNull) { + this.jdbcTypeForNull = jdbcTypeForNull; + } + + public Set getLazyLoadTriggerMethods() { + return lazyLoadTriggerMethods; + } + + public void setLazyLoadTriggerMethods(Set lazyLoadTriggerMethods) { + this.lazyLoadTriggerMethods = lazyLoadTriggerMethods; + } + + public Integer getDefaultStatementTimeout() { + return defaultStatementTimeout; + } + + public void setDefaultStatementTimeout(Integer defaultStatementTimeout) { + this.defaultStatementTimeout = defaultStatementTimeout; + } + + public Integer getDefaultFetchSize() { + return defaultFetchSize; + } + + public void setDefaultFetchSize(Integer defaultFetchSize) { + this.defaultFetchSize = defaultFetchSize; + } + + public ResultSetType getDefaultResultSetType() { + return defaultResultSetType; + } + + public void setDefaultResultSetType(ResultSetType defaultResultSetType) { + this.defaultResultSetType = defaultResultSetType; + } + + public ExecutorType getDefaultExecutorType() { + return defaultExecutorType; + } + + public void setDefaultExecutorType(ExecutorType defaultExecutorType) { + this.defaultExecutorType = defaultExecutorType; + } + + public AutoMappingBehavior getAutoMappingBehavior() { + return autoMappingBehavior; + } + + public void setAutoMappingBehavior(AutoMappingBehavior autoMappingBehavior) { + this.autoMappingBehavior = autoMappingBehavior; + } + + public AutoMappingUnknownColumnBehavior getAutoMappingUnknownColumnBehavior() { + return autoMappingUnknownColumnBehavior; + } + + public void setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior autoMappingUnknownColumnBehavior) { + this.autoMappingUnknownColumnBehavior = autoMappingUnknownColumnBehavior; + } + + public Properties getVariables() { + return variables; + } + + public void setVariables(Properties variables) { + this.variables = variables; + } + + public Boolean getLazyLoadingEnabled() { + return lazyLoadingEnabled; + } + + public void setLazyLoadingEnabled(Boolean lazyLoadingEnabled) { + this.lazyLoadingEnabled = lazyLoadingEnabled; + } + + public Class getConfigurationFactory() { + return configurationFactory; + } + + public void setConfigurationFactory(Class configurationFactory) { + this.configurationFactory = configurationFactory; + } + + public Class getDefaultEnumTypeHandler() { + return defaultEnumTypeHandler; + } + + public void setDefaultEnumTypeHandler(Class defaultEnumTypeHandler) { + this.defaultEnumTypeHandler = defaultEnumTypeHandler; + } + + public String getDatabaseId() { + return databaseId; + } + + public void setDatabaseId(String databaseId) { + this.databaseId = databaseId; + } + + public void applyTo(Configuration target) { + PropertyMapper mapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + mapper.from(getSafeRowBoundsEnabled()).to(target::setSafeRowBoundsEnabled); + mapper.from(getSafeResultHandlerEnabled()).to(target::setSafeResultHandlerEnabled); + mapper.from(getMapUnderscoreToCamelCase()).to(target::setMapUnderscoreToCamelCase); + mapper.from(getAggressiveLazyLoading()).to(target::setAggressiveLazyLoading); + mapper.from(getMultipleResultSetsEnabled()).to(target::setMultipleResultSetsEnabled); + mapper.from(getUseGeneratedKeys()).to(target::setUseGeneratedKeys); + mapper.from(getUseColumnLabel()).to(target::setUseColumnLabel); + mapper.from(getCacheEnabled()).to(target::setCacheEnabled); + mapper.from(getCallSettersOnNulls()).to(target::setCallSettersOnNulls); + mapper.from(getUseActualParamName()).to(target::setUseActualParamName); + mapper.from(getReturnInstanceForEmptyRow()).to(target::setReturnInstanceForEmptyRow); + mapper.from(getShrinkWhitespacesInSql()).to(target::setShrinkWhitespacesInSql); + mapper.from(getNullableOnForEach()).to(target::setNullableOnForEach); + mapper.from(getArgNameBasedConstructorAutoMapping()).to(target::setArgNameBasedConstructorAutoMapping); + mapper.from(getLazyLoadingEnabled()).to(target::setLazyLoadingEnabled); + mapper.from(getLogPrefix()).to(target::setLogPrefix); + mapper.from(getLazyLoadTriggerMethods()).to(target::setLazyLoadTriggerMethods); + mapper.from(getDefaultStatementTimeout()).to(target::setDefaultStatementTimeout); + mapper.from(getDefaultFetchSize()).to(target::setDefaultFetchSize); + mapper.from(getLocalCacheScope()).to(target::setLocalCacheScope); + mapper.from(getJdbcTypeForNull()).to(target::setJdbcTypeForNull); + mapper.from(getDefaultResultSetType()).to(target::setDefaultResultSetType); + mapper.from(getDefaultExecutorType()).to(target::setDefaultExecutorType); + mapper.from(getAutoMappingBehavior()).to(target::setAutoMappingBehavior); + mapper.from(getAutoMappingUnknownColumnBehavior()).to(target::setAutoMappingUnknownColumnBehavior); + mapper.from(getVariables()).to(target::setVariables); + mapper.from(getLogImpl()).to(target::setLogImpl); + mapper.from(getVfsImpl()).to(target::setVfsImpl); + mapper.from(getDefaultSqlProviderType()).to(target::setDefaultSqlProviderType); + mapper.from(getConfigurationFactory()).to(target::setConfigurationFactory); + mapper.from(getDefaultEnumTypeHandler()).to(target::setDefaultEnumTypeHandler); + mapper.from(getDatabaseId()).to(target::setDatabaseId); + } + + } + } diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SpringBootVFS.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SpringBootVFS.java index 66d0b77b0..e68354615 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SpringBootVFS.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SpringBootVFS.java @@ -15,16 +15,22 @@ */ package tk.mybatis.mapper.autoconfigure; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.URL; +import java.net.URLDecoder; +import java.nio.charset.Charset; +import java.text.Normalizer; +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import org.apache.ibatis.io.VFS; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; - -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; +import org.springframework.util.ClassUtils; /** * @author Hans Westerbeek @@ -33,10 +39,17 @@ */ public class SpringBootVFS extends VFS { + private static Charset urlDecodingCharset; + private static Supplier classLoaderSupplier; private final ResourcePatternResolver resourceResolver; + static { + setUrlDecodingCharset(Charset.defaultCharset()); + setClassLoaderSupplier(ClassUtils::getDefaultClassLoader); + } + public SpringBootVFS() { - this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader()); + this.resourceResolver = new PathMatchingResourcePatternResolver(classLoaderSupplier.get()); } @Override @@ -44,20 +57,51 @@ public boolean isValid() { return true; } - @Override - protected List list(URL url, String path) throws IOException { - Resource[] resources = resourceResolver.getResources("classpath*:" + path + "/**/*.class"); - List resourcePaths = new ArrayList(); - for (Resource resource : resources) { - resourcePaths.add(preserveSubpackageName(resource.getURI(), path)); + /** + * Set the charset for decoding an encoded URL string. + *

+ * Default is system default charset. + *

+ * + * @param charset the charset for decoding an encoded URL string + * @since 2.3.0 + */ + public static void setUrlDecodingCharset(Charset charset) { + urlDecodingCharset = charset; + } + + /** + * Set the supplier for providing {@link ClassLoader} to used. + *

+ * Default is a returned instance from {@link ClassUtils#getDefaultClassLoader()}. + *

+ * + * @param supplier the supplier for providing {@link ClassLoader} to used + * @since 3.0.2 + */ + public static void setClassLoaderSupplier(Supplier supplier) { + classLoaderSupplier = supplier; + } + + private static String preserveSubpackageName(final String baseUrlString, final Resource resource, + final String rootPath) { + try { + return rootPath + (rootPath.endsWith("/") ? "" : "/") + + Normalizer + .normalize(URLDecoder.decode(resource.getURL().toString(), urlDecodingCharset), Normalizer.Form.NFC) + .substring(baseUrlString.length()); + } catch (IOException e) { + throw new UncheckedIOException(e); } - return resourcePaths; } - private static String preserveSubpackageName(final URI uri, final String rootPath) { - final String uriStr = uri.toString(); - final int start = uriStr.indexOf(rootPath); - return uriStr.substring(start); + @Override + protected List list(URL url, String path) throws IOException { + String urlString = URLDecoder.decode(url.toString(), urlDecodingCharset); + String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/"); + Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class"); + return Stream.of(resources).map(resource -> preserveSubpackageName(baseUrlString, resource, path)) + .collect(Collectors.toList()); } } diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SqlSessionFactoryBeanCustomizer.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SqlSessionFactoryBeanCustomizer.java new file mode 100644 index 000000000..2a3111460 --- /dev/null +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/SqlSessionFactoryBeanCustomizer.java @@ -0,0 +1,21 @@ +package tk.mybatis.mapper.autoconfigure; + +import org.mybatis.spring.SqlSessionFactoryBean; + +/** + * Callback interface that can be customized a {@link SqlSessionFactoryBean} object generated on auto-configuration. + * + * @author Kazuki Shimizu + * @since 2.2.2 + */ +@FunctionalInterface +public interface SqlSessionFactoryBeanCustomizer { + + /** + * Customize the given a {@link SqlSessionFactoryBean} object. + * + * @param factoryBean the factory bean object to customize + */ + void customize(SqlSessionFactoryBean factoryBean); + +} diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 48243cbf6..e62a7c18c 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1,2 @@ +tk.mybatis.mapper.autoconfigure.MybatisLanguageDriverAutoConfiguration tk.mybatis.mapper.autoconfigure.MapperAutoConfiguration \ No newline at end of file diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties index dca3cf5cf..5613106ea 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties @@ -23,4 +23,8 @@ # spring.sql.init.schema-locations=classpath:import.sql logging.level.root=WARN -logging.level.tk.mybatis.sample.mapper=TRACE \ No newline at end of file +logging.level.tk.mybatis.sample.mapper=TRACE +mapper.useSimpleType=false +mapper.enable-method-annotation=true +mapper.style=uppercase +mybatis.configuration.logImpl=org.apache.ibatis.logging.slf4j.Slf4jImpl \ No newline at end of file diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/logback.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/logback.xml new file mode 100644 index 000000000..cbc7d3ef0 --- /dev/null +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/logback.xml @@ -0,0 +1,10 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + \ No newline at end of file diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/SampleXmlApplication.java b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/SampleXmlApplication.java index 57fdf5de2..1592b777b 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/SampleXmlApplication.java +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/java/tk/mybatis/sample/SampleXmlApplication.java @@ -24,12 +24,14 @@ package tk.mybatis.sample; +import org.apache.ibatis.annotations.Mapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import tk.mybatis.sample.domain.Country; import tk.mybatis.sample.mapper.CountryMapper; +import tk.mybatis.spring.annotation.MapperScan; import java.util.List; diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml index 31048949b..aac52a11e 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml @@ -28,6 +28,8 @@ spring: mybatis: config-location: mybatis-config.xml base-packages: tk.mybatis.sample.mapper + mapper-locations: + - classpath: /tk/mybatis/sample/mapper logging: level: diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/logback.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/logback.xml new file mode 100644 index 000000000..cbc7d3ef0 --- /dev/null +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/logback.xml @@ -0,0 +1,10 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + \ No newline at end of file diff --git a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScans.java b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScans.java index b4b3bac80..1528e3b9d 100644 --- a/spring/src/main/java/tk/mybatis/spring/annotation/MapperScans.java +++ b/spring/src/main/java/tk/mybatis/spring/annotation/MapperScans.java @@ -20,17 +20,17 @@ import java.lang.annotation.*; /** - * The Container annotation that aggregates several {@link org.mybatis.spring.annotation.MapperScan} annotations. + * The Container annotation that aggregates several {@link tk.mybatis.spring.annotation.MapperScan} annotations. *

- * Can be used natively, declaring several nested {@link org.mybatis.spring.annotation.MapperScan} annotations. Can also be used in conjunction with - * Java 8's support for repeatable annotations, where {@link org.mybatis.spring.annotation.MapperScan} can simply be declared several times on the + * Can be used natively, declaring several nested {@link tk.mybatis.spring.annotation.MapperScan} annotations. Can also be used in conjunction with + * Java 8's support for repeatable annotations, where {@link tk.mybatis.spring.annotation.MapperScan} can simply be declared several times on the * same method, implicitly generating this container annotation. * * @author Kazuki Shimizu * * @since 2.0.0 * - * @see org.mybatis.spring.annotation.MapperScan + * @see tk.mybatis.spring.annotation.MapperScan */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) From 0b50897e48e988358024d2bd8910d264acbd5cc4 Mon Sep 17 00:00:00 2001 From: liuzh Date: Tue, 20 Aug 2024 22:16:33 +0800 Subject: [PATCH 097/109] =?UTF-8?q?=E5=AE=8C=E5=96=84=20mybatis.basePackag?= =?UTF-8?q?es=20=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=8C=87=E5=AE=9A=E8=AF=A5?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=97=B6=E4=B8=8D=E6=8C=87=E5=AE=9A=20@Mappe?= =?UTF-8?q?r=20=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapperAutoConfiguration.java | 27 ++++++++++++++----- .../src/main/resources/application.yml | 4 +-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java index b6c587bda..f1e504b26 100644 --- a/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java +++ b/spring-boot-starter/mapper-spring-boot-autoconfigure/src/main/java/tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.java @@ -16,6 +16,7 @@ package tk.mybatis.mapper.autoconfigure; import java.beans.PropertyDescriptor; +import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.Set; @@ -69,8 +70,10 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; +import tk.mybatis.spring.annotation.BaseProperties; import tk.mybatis.spring.mapper.MapperFactoryBean; import tk.mybatis.spring.mapper.MapperScannerConfigurer; +import tk.mybatis.spring.mapper.SpringBootBindUtil; /** * {@link EnableAutoConfiguration Auto-Configuration} for Mybatis. Contributes a {@link SqlSessionFactory} and a @@ -249,17 +252,27 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B return; } - logger.debug("Searching for mappers annotated with @Mapper"); + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class); - List packages = AutoConfigurationPackages.get(this.beanFactory); - if (logger.isDebugEnabled()) { - packages.forEach(pkg -> logger.debug("Using auto-configuration base package '{}'", pkg)); + BaseProperties properties = SpringBootBindUtil.bind(environment, BaseProperties.class, BaseProperties.MYBATIS_PREFIX); + if (properties != null && properties.getBasePackages() != null && properties.getBasePackages().length > 0) { + List basePackages = Arrays.asList(properties.getBasePackages()); + if (logger.isDebugEnabled()) { + basePackages.forEach(pkg -> logger.debug("Using mybatis.basePackages configuration package '{}'", pkg)); + } + builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(basePackages)); + } else { + //设置了包名的情况下,不需要指定该注解 + logger.debug("Searching for mappers annotated with @Mapper"); + builder.addPropertyValue("annotationClass", Mapper.class); + List packages = AutoConfigurationPackages.get(this.beanFactory); + if (logger.isDebugEnabled()) { + packages.forEach(pkg -> logger.debug("Using auto-configuration base package '{}'", pkg)); + } + builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(packages)); } - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class); builder.addPropertyValue("processPropertyPlaceHolders", true); - builder.addPropertyValue("annotationClass", Mapper.class); - builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(packages)); builder.addPropertyValue("mapperProperties", this.environment); BeanWrapper beanWrapper = new BeanWrapperImpl(MapperScannerConfigurer.class); Set propertyNames = Stream.of(beanWrapper.getPropertyDescriptors()).map(PropertyDescriptor::getName) diff --git a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml index aac52a11e..7b689c046 100644 --- a/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml +++ b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml @@ -28,12 +28,10 @@ spring: mybatis: config-location: mybatis-config.xml base-packages: tk.mybatis.sample.mapper - mapper-locations: - - classpath: /tk/mybatis/sample/mapper logging: level: - root: WARN + root: DEBUG tk.mybatis.sample.mapper: TRACE mapper: not-empty: true From cf801a4609da4b544a9b3ff7b90b5ba289918574 Mon Sep 17 00:00:00 2001 From: liuzh Date: Tue, 20 Aug 2024 22:18:59 +0800 Subject: [PATCH 098/109] 5.0.0-rc2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index da994339a..159da1017 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 5.0.0-SNAPSHOT + 5.0.0-rc2 17 17 UTF-8 From 63e67fac1bb294859ffea4ee06b7668c1fbb0136 Mon Sep 17 00:00:00 2001 From: liuzh Date: Wed, 21 Aug 2024 11:45:03 +0800 Subject: [PATCH 099/109] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f72d51a64..c24df150f 100644 --- a/README.md +++ b/README.md @@ -8,24 +8,43 @@ 支持单表操作,不支持通用的多表联合查询。 -**通用 Mapper 支持 Mybatis-3.2.4 及以上版本。** +## 通用 Mapper 5 来了🎉🎉🎉 -## [下一代 通用 Mapper5?](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) +基于 JDK 17 + Jakarta JPA 注解 + Spring Boot 3 -通用 Mapper 每次大的版本,基本上都是底层上的大变化,在使用通用 Mapper 的过程中,有很多人遇到过配置的问题,因为底层实现的方式,所以无法避免配置,而且随着功能的增加,配置也增加了不少。 +配置完全兼容,需要使用新版本的 JPA 注解,同步更新(copy) mybatis-spring 3.0.4 和 mybatis-spring-boot-starter 3.0.4。 -为了从根本上简化通用方法的实现,从2018年就开始思考如何让实现和MyBatis的兼容性更好,让实现变的更简单,为了从 MyBatis 根本解决问题,给官方提过好几个 PR,在 2019年3月份给 MyBatis 提交的 -[pr#1391](https://github.com/mybatis/mybatis-3/pull/1391) 合并后(对应 3.5.1 版本,最低要求版本),终于能以更简单的方式来实现通用 Mapper 了。 +此次更新主要是依赖的更新,没有增加新的功能,只是为了更好的兼容 JDK 17 和 Jakarta JPA 注解。 + +```xml + + tk.mybatis + mapper + 5.0.0-rc2 + +``` -由于此次变动太大,因此不打算对 **通用Mapper4** 进行任何改动,从头实现了一个新的项目,名字仍然没有新意的使用了 `mybatis-mapper`,推荐在新项目中使用: +如果你要在新项目中使用,可以看看新版本的 mybatis-mapper,完全作为 mybatis 扩展存在, +不修改 mybatis, mybatis-spring, mybatis-spring-boot-starter 任何代码,不需要额外配置,可以快速上手。 -- [GitHub - https://github.com/mybatis-mapper/mapper](https://github.com/mybatis-mapper/mapper) -- [Gitee - https://gitee.com/mybatis-mapper/mapper](https://gitee.com/mybatis-mapper/mapper) -- [文档: https://mapper.mybatis.io](https://mapper.mybatis.io/) -- [开发过程 - https://mapper.mybatis.io/releases/1.0.0.html](https://mapper.mybatis.io/releases/1.0.0.html) -- [快速上手 - https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) +- mybatis-mapper: https://github.com/mybatis-mapper/mapper +- mybatis-mapper 文档: https://mapper.mybatis.io +- [mybatis-mapper 快速入门](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) -另外,通用 Mapper 中的大量 PR 都是增加的新方法和代码生成器相关的注解,这些和核心无关,因此 mybaits-mapper 会提供独立的项目接收所有新增的通用方法, 和代码生成器相关的 lombok +> 通用 Mapper 每次大的版本,基本上都是底层上的大变化,在使用通用 Mapper 的过程中,有很多人遇到过配置的问题,因为底层实现的方式,所以无法避免配置,而且随着功能的增加,配置也增加了不少。 +> +> 为了从根本上简化通用方法的实现,从2018年就开始思考如何让实现和MyBatis的兼容性更好,让实现变的更简单,为了从 MyBatis 根本解决问题,给官方提过好几个 PR,在 2019年3月份给 MyBatis 提交的 +[pr#1391](https://github.com/mybatis/mybatis-3/pull/1391) 合并后(对应 3.5.1 版本,最低要求版本),终于能以更简单的方式来实现通用 Mapper 了。 +> +> 由于此次变动太大,因此不打算对 **通用Mapper4** 进行任何改动,从头实现了一个新的项目,名字仍然没有新意的使用了 `mybatis-mapper`,推荐在新项目中使用: +> +> - [GitHub - https://github.com/mybatis-mapper/mapper](https://github.com/mybatis-mapper/mapper) +> - [Gitee - https://gitee.com/mybatis-mapper/mapper](https://gitee.com/mybatis-mapper/mapper) +> - [文档: https://mapper.mybatis.io](https://mapper.mybatis.io/) +> - [开发过程 - https://mapper.mybatis.io/releases/1.0.0.html](https://mapper.mybatis.io/releases/1.0.0.html) +> - [快速上手 - https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) +> +> 另外,通用 Mapper 中的大量 PR 都是增加的新方法和代码生成器相关的注解,这些和核心无关,因此 mybaits-mapper 会提供独立的项目接收所有新增的通用方法, 和代码生成器相关的 lombok 注解完全不需要了,使用新版本中提供的代码生成器可以更方便的进行定制。 ## [**快速入门 - MyBatis 为什么需要通用 Mapper ?**](https://blog.csdn.net/isea533/article/details/83045335) @@ -52,13 +71,13 @@ ## 作者信息 -MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) +MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) -作者博客:http://blog.csdn.net/isea533 +作者博客:http://blog.csdn.net/isea533 ,http://blog.mybatis.io -作者邮箱: abel533@gmail.com +作者邮箱:abel533@gmail.com -推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper) +推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper) ## 《MyBatis 从入门到精通》 @@ -75,10 +94,6 @@ MyBatis 工具网站:[https://mybatis.io](https://mybatis.io) - [京东](https://item.jd.com/12103309.html) -- [当当](http://product.dangdang.com/25098208.html) - -- [亚马逊](https://www.amazon.cn/MyBatis从入门到精通-刘增辉/dp/B072RC11DM/ref=sr_1_18?ie=UTF8&qid=1498007125&sr=8-18&keywords=mybatis) - ### 相关介绍 - CSDN博客:http://blog.csdn.net/isea533/article/details/73555400 From 837f2a3cc1f234377ede62879d2e9a212dca2571 Mon Sep 17 00:00:00 2001 From: liuzh Date: Wed, 21 Aug 2024 11:49:09 +0800 Subject: [PATCH 100/109] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index c24df150f..6d5e4188e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MyBatis 通用 Mapper4 +# MyBatis 通用 Mapper5 来了🎉🎉🎉 [![Maven central](https://maven-badges.herokuapp.com/maven-central/tk.mybatis/mapper/badge.svg)](https://maven-badges.herokuapp.com/maven-central/tk.mybatis/mapper) @@ -8,9 +8,7 @@ 支持单表操作,不支持通用的多表联合查询。 -## 通用 Mapper 5 来了🎉🎉🎉 - -基于 JDK 17 + Jakarta JPA 注解 + Spring Boot 3 +## 基于 JDK 17 + Jakarta JPA 注解 + Spring Boot 3 配置完全兼容,需要使用新版本的 JPA 注解,同步更新(copy) mybatis-spring 3.0.4 和 mybatis-spring-boot-starter 3.0.4。 @@ -31,22 +29,6 @@ - mybatis-mapper 文档: https://mapper.mybatis.io - [mybatis-mapper 快速入门](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) -> 通用 Mapper 每次大的版本,基本上都是底层上的大变化,在使用通用 Mapper 的过程中,有很多人遇到过配置的问题,因为底层实现的方式,所以无法避免配置,而且随着功能的增加,配置也增加了不少。 -> -> 为了从根本上简化通用方法的实现,从2018年就开始思考如何让实现和MyBatis的兼容性更好,让实现变的更简单,为了从 MyBatis 根本解决问题,给官方提过好几个 PR,在 2019年3月份给 MyBatis 提交的 -[pr#1391](https://github.com/mybatis/mybatis-3/pull/1391) 合并后(对应 3.5.1 版本,最低要求版本),终于能以更简单的方式来实现通用 Mapper 了。 -> -> 由于此次变动太大,因此不打算对 **通用Mapper4** 进行任何改动,从头实现了一个新的项目,名字仍然没有新意的使用了 `mybatis-mapper`,推荐在新项目中使用: -> -> - [GitHub - https://github.com/mybatis-mapper/mapper](https://github.com/mybatis-mapper/mapper) -> - [Gitee - https://gitee.com/mybatis-mapper/mapper](https://gitee.com/mybatis-mapper/mapper) -> - [文档: https://mapper.mybatis.io](https://mapper.mybatis.io/) -> - [开发过程 - https://mapper.mybatis.io/releases/1.0.0.html](https://mapper.mybatis.io/releases/1.0.0.html) -> - [快速上手 - https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D](https://mapper.mybatis.io/docs/1.getting-started.html#%E4%BB%8B%E7%BB%8D) -> -> 另外,通用 Mapper 中的大量 PR 都是增加的新方法和代码生成器相关的注解,这些和核心无关,因此 mybaits-mapper 会提供独立的项目接收所有新增的通用方法, 和代码生成器相关的 lombok -注解完全不需要了,使用新版本中提供的代码生成器可以更方便的进行定制。 - ## [**快速入门 - MyBatis 为什么需要通用 Mapper ?**](https://blog.csdn.net/isea533/article/details/83045335) 简介: 在早期项目文档中有过类似主题的内容,但是最近我自己看文档的时候发现一个问题,文档虽然很详细,但是并不适合初次接触的人。为了方便第一次听说,第一次尝试的开发人员了解通用 Mapper,补充此文档。 From e37847a6efa7842b0ab7515e551b91ab1b71adb0 Mon Sep 17 00:00:00 2001 From: liuzh Date: Thu, 22 Aug 2024 18:22:53 +0800 Subject: [PATCH 101/109] =?UTF-8?q?=E5=AE=8C=E5=96=84Binder=E7=BB=91?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/spring/mapper/SpringBootBindUtil.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spring/src/main/java/tk/mybatis/spring/mapper/SpringBootBindUtil.java b/spring/src/main/java/tk/mybatis/spring/mapper/SpringBootBindUtil.java index 34a4ae9d3..4a0b4e3c8 100644 --- a/spring/src/main/java/tk/mybatis/spring/mapper/SpringBootBindUtil.java +++ b/spring/src/main/java/tk/mybatis/spring/mapper/SpringBootBindUtil.java @@ -45,8 +45,17 @@ public static T bind(Environment environment, Class targetClass, String p Method bindMethod = binderClass.getDeclaredMethod("bind", String.class, Class.class); Object binder = getMethod.invoke(null, environment); Object bindResult = bindMethod.invoke(binder, prefix, targetClass); - Method getMethodResult = bindResult.getClass().getDeclaredMethod("get"); - return (T) getMethodResult.invoke(bindResult); + + // Check if the value is bound + Method isBoundMethod = bindResult.getClass().getDeclaredMethod("isBound"); + boolean isBound = (boolean) isBoundMethod.invoke(bindResult); + + if (isBound) { + Method getMethodResult = bindResult.getClass().getDeclaredMethod("get"); + return (T) getMethodResult.invoke(bindResult); + } else { + return null; + } } catch (Exception e) { LOGGER.warn("Bind " + targetClass + " error", e); return null; From 0c52b2fae6958241d363d255086a3f37d60088b5 Mon Sep 17 00:00:00 2001 From: liuzh Date: Thu, 22 Aug 2024 18:23:31 +0800 Subject: [PATCH 102/109] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8import=20jakarta.persistence.*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java | 2 +- generator/src/main/resources/generator/test-all.ftl | 2 +- generator/src/main/resources/generator/test-one.ftl | 2 +- generator/src/test/resources/generatorConfig.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java index 527299623..657761d75 100644 --- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java +++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperPlugin.java @@ -127,7 +127,7 @@ public boolean clientGenerated(Interface interfaze, IntrospectedTable introspect */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //引入JPA注解 - topLevelClass.addImportedType("javax.persistence.*"); + topLevelClass.addImportedType("jakarta.persistence.*"); //lombok扩展开始 //如果需要Data,引入包,代码增加注解 if (this.needsData) { diff --git a/generator/src/main/resources/generator/test-all.ftl b/generator/src/main/resources/generator/test-all.ftl index 52fd6c036..4ffd7a8bd 100644 --- a/generator/src/main/resources/generator/test-all.ftl +++ b/generator/src/main/resources/generator/test-all.ftl @@ -16,7 +16,7 @@ ${dateTime?string["yyyy-MM-dd HH:mm:ss"]} **************************************************************************************** 实体和表的信息: 表名:${tableClass.tableName} - 表注释:${tableClass.remarks} + 表注释:${tableClass.remarks!""} 变量名:${tableClass.variableName} 小写名:${tableClass.lowerCaseName} 类名:${tableClass.shortClassName} diff --git a/generator/src/main/resources/generator/test-one.ftl b/generator/src/main/resources/generator/test-one.ftl index 835399063..d8ba742d4 100644 --- a/generator/src/main/resources/generator/test-one.ftl +++ b/generator/src/main/resources/generator/test-one.ftl @@ -13,7 +13,7 @@ ${dateTime?string["yyyy-MM-dd HH:mm:ss"]} 实体和表的信息: 表名:${tableClass.tableName} -表注释:${tableClass.remarks} +表注释:${tableClass.remarks!""} 变量名:${tableClass.variableName} 小写名:${tableClass.lowerCaseName} 类名:${tableClass.shortClassName} diff --git a/generator/src/test/resources/generatorConfig.xml b/generator/src/test/resources/generatorConfig.xml index f5988c5aa..e04cc270f 100644 --- a/generator/src/test/resources/generatorConfig.xml +++ b/generator/src/test/resources/generatorConfig.xml @@ -44,7 +44,7 @@ - + From 5c4d2ce7a2c1478c33de69669ab45be1c8441fa3 Mon Sep 17 00:00:00 2001 From: liuzh Date: Thu, 22 Aug 2024 18:23:50 +0800 Subject: [PATCH 103/109] 5.0.0-rc3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 159da1017..84ae1550a 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 5.0.0-rc2 + 5.0.0-rc3 17 17 UTF-8 From 6d67f05d3a8315bd84b69d134e7801021c5cc49a Mon Sep 17 00:00:00 2001 From: liuzh Date: Thu, 22 Aug 2024 18:25:33 +0800 Subject: [PATCH 104/109] 5.0.0-rc3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d5e4188e..02010fb23 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ tk.mybatis mapper - 5.0.0-rc2 + 5.0.0-rc3 ``` From 1936590a55910475f85e246e1e453231e60227c1 Mon Sep 17 00:00:00 2001 From: liuzh Date: Sun, 25 Aug 2024 15:50:12 +0800 Subject: [PATCH 105/109] =?UTF-8?q?=E5=8F=91=E5=B8=83=205.0.0=20=E6=AD=A3?= =?UTF-8?q?=E5=BC=8F=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- pom.xml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02010fb23..3a19c23d3 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,12 @@ tk.mybatis mapper - 5.0.0-rc3 + 5.0.0 ``` +## 推荐新版本 mybatis-mapper + 如果你要在新项目中使用,可以看看新版本的 mybatis-mapper,完全作为 mybatis 扩展存在, 不修改 mybatis, mybatis-spring, mybatis-spring-boot-starter 任何代码,不需要额外配置,可以快速上手。 diff --git a/pom.xml b/pom.xml index 84ae1550a..399acbce9 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 5.0.0-rc3 + 5.0.0 17 17 UTF-8 From 8e3e5a83bbc54a2dd83100f02dca0ef18a8a2bdf Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 4 Nov 2024 12:35:52 +0800 Subject: [PATCH 106/109] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0ena?= =?UTF-8?q?bleBaseResultMapFlag=20=E6=98=AF=E5=90=A6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=A4=84=E7=90=86=20Mapper=20=E6=8E=A5=E5=8F=A3=E4=B8=AD?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E6=89=8B=E5=86=99=E6=8C=87=E5=AE=9A=20result?= =?UTF-8?q?Type=20=E7=9A=84=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=BA=20resultMap=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/rawresultmap/RawResultMapTest.java | 10 +++++--- .../java/tk/mybatis/mapper/entity/Config.java | 12 ++++++++++ .../mapper/mapperhelper/MapperHelper.java | 24 +++++++++++-------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/base/src/test/java/tk/mybatis/mapper/rawresultmap/RawResultMapTest.java b/base/src/test/java/tk/mybatis/mapper/rawresultmap/RawResultMapTest.java index 334a7e515..18ed9b6f8 100644 --- a/base/src/test/java/tk/mybatis/mapper/rawresultmap/RawResultMapTest.java +++ b/base/src/test/java/tk/mybatis/mapper/rawresultmap/RawResultMapTest.java @@ -11,6 +11,7 @@ import java.io.Reader; import java.net.URL; import java.util.List; +import java.util.Map; /** * @author liuzh @@ -21,6 +22,7 @@ public class RawResultMapTest extends BaseTest { protected Config getConfig() { Config config = super.getConfig(); config.setStyle(Style.normal); + config.setEnableBaseResultMapFlag(true); return config; } @@ -70,7 +72,7 @@ public void testSelect() { users.forEach(u -> { System.out.println(u); Assert.assertNotNull(u.getUname()); - Assert.assertNotNull(u.getAge()); + Assert.assertNull(u.getAge()); Assert.assertNotNull(u.getCreateTime()); Assert.assertNotNull(u.getEmail()); }); @@ -88,10 +90,12 @@ public void testSelect() { System.out.println("------------"); System.out.println("------getMapUser------"); - System.out.println(mapper.getMapUser()); + Map mapUser = mapper.getMapUser(); + System.out.println(mapUser); System.out.println("------------"); - System.out.println(mapper.selectCount2()); + Integer x = mapper.selectCount2(); + System.out.println(x); } finally { sqlSession.close(); } diff --git a/core/src/main/java/tk/mybatis/mapper/entity/Config.java b/core/src/main/java/tk/mybatis/mapper/entity/Config.java index dbf11dbf1..9d90ea834 100644 --- a/core/src/main/java/tk/mybatis/mapper/entity/Config.java +++ b/core/src/main/java/tk/mybatis/mapper/entity/Config.java @@ -90,6 +90,10 @@ public class Config { * 是否设置 javaType */ private boolean useJavaType; + /** + * 是否自动处理 Mapper 接口中其他手写指定 resultType 的返回结果类型为 resultMap + */ + private boolean enableBaseResultMapFlag; public String getCatalog() { return catalog; @@ -316,6 +320,14 @@ public void setUseJavaType(boolean useJavaType) { this.useJavaType = useJavaType; } + public boolean isEnableBaseResultMapFlag() { + return enableBaseResultMapFlag; + } + + public void setEnableBaseResultMapFlag(boolean enableBaseResultMapFlag) { + this.enableBaseResultMapFlag = enableBaseResultMapFlag; + } + /** * 配置属性 * diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java index 6d12a2b9a..15c562879 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperHelper.java @@ -304,7 +304,8 @@ public void processMappedStatement(MappedStatement ms) { } // 如果是原生mybatisSqlSource的查询,添加ResultMap - if (ms.getSqlSource() instanceof RawSqlSource + if (config.isEnableBaseResultMapFlag() + && ms.getSqlSource() instanceof RawSqlSource && ms.getSqlCommandType() == SqlCommandType.SELECT) { if (ms.getResultMaps() != null && !ms.getResultMaps().isEmpty()) { setRawSqlSourceMapper(ms); @@ -402,15 +403,18 @@ public void setSqlSource(MappedStatement ms, MapperTemplate mapperTemplate) { * JPA的注解优先级将高于mybatis自动映射 */ public void setRawSqlSourceMapper(MappedStatement ms) { - - EntityTable entityTable = EntityHelper.getEntityTableOrNull(ms.getResultMaps().get(0).getType()); - if (entityTable != null) { - List resultMaps = new ArrayList<>(); - ResultMap resultMap = entityTable.getResultMap(ms.getConfiguration()); - if (resultMap != null) { - resultMaps.add(resultMap); - MetaObject metaObject = MetaObjectUtil.forObject(ms); - metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps)); + ResultMap rm = ms.getResultMaps().get(0); + //不处理已经配置映射的查询 + if (rm.getResultMappings().isEmpty()) { + EntityTable entityTable = EntityHelper.getEntityTableOrNull(rm.getType()); + if (entityTable != null) { + List resultMaps = new ArrayList<>(); + ResultMap resultMap = entityTable.getResultMap(ms.getConfiguration()); + if (resultMap != null) { + resultMaps.add(resultMap); + MetaObject metaObject = MetaObjectUtil.forObject(ms); + metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps)); + } } } } From 8c4728fa66a9e81163e77b9c56a0753ee245e2d9 Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 4 Nov 2024 12:36:14 +0800 Subject: [PATCH 107/109] =?UTF-8?q?=E5=8F=91=E5=B8=83=205.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 399acbce9..63a69da54 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ https://mybatis.io - 5.0.0 + 5.0.1 17 17 UTF-8 From 88b8243dbe2f01fcc0738457e663d335046bd030 Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 4 Nov 2024 12:45:23 +0800 Subject: [PATCH 108/109] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/tk/mybatis/mapper/test/able/TestBasicAble.java | 1 - 1 file changed, 1 deletion(-) diff --git a/base/src/test/java/tk/mybatis/mapper/test/able/TestBasicAble.java b/base/src/test/java/tk/mybatis/mapper/test/able/TestBasicAble.java index ce403d981..d5c9e1e66 100644 --- a/base/src/test/java/tk/mybatis/mapper/test/able/TestBasicAble.java +++ b/base/src/test/java/tk/mybatis/mapper/test/able/TestBasicAble.java @@ -55,7 +55,6 @@ public void testInsert() { Assert.assertEquals(1, mapper.insert(userInfo)); Assert.assertNotNull(userInfo.getId()); - Assert.assertEquals(6, (int) userInfo.getId()); userInfo = mapper.selectByPrimaryKey(userInfo.getId()); //email没有插入 From 7990b9c48bbcebf590f09fc245daba0c396f7b57 Mon Sep 17 00:00:00 2001 From: liuzh Date: Mon, 4 Nov 2024 12:46:29 +0800 Subject: [PATCH 109/109] =?UTF-8?q?=E5=AE=8C=E6=88=90CI=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 60185440c..7fe9255b2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,4 +15,4 @@ jobs: java-version: '17' distribution: 'adopt' - name: Run the Maven verify phase - run: mvn --batch-mode --update-snapshots -P dev test \ No newline at end of file + run: mvn --batch-mode --update-snapshots test \ No newline at end of file