因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..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
@@ -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,10 +56,10 @@ 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("");
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 a2bbbfc72..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
@@ -54,8 +54,8 @@ public IdListProvider(Class> 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);
}
}
@@ -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();
}
@@ -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("");
}
@@ -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..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,12 +59,14 @@ 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) {
sql.append("");
@@ -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/select/SelectByPropertyMapper.java b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java
new file mode 100644
index 000000000..4fa9a49f2
--- /dev/null
+++ b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectByPropertyMapper.java
@@ -0,0 +1,80 @@
+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..2586614fb
--- /dev/null
+++ b/extra/src/main/java/tk/mybatis/mapper/additional/select/SelectPropertyProvider.java
@@ -0,0 +1,259 @@
+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/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 extends T> 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 extends T> recordList);
+}
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..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,19 +122,19 @@ 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(")
- .append("@").append(versionClass).append("@class, ")
- .append(column.getProperty()).append(")},");
+ .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(")
+ .append("@").append(versionClass).append("@class, ")
+ .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/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..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
@@ -37,8 +37,8 @@
import java.util.Set;
/**
- * @Description: 通用Mapper接口,更新,强制,实现
* @author qrqhuangcy
+ * @Description: 通用Mapper接口, 更新, 强制,实现
* @date 2018-06-26
*/
public class UpdateByPrimaryKeySelectiveForceProvider extends MapperTemplate {
@@ -80,24 +80,31 @@ 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(")
- .append("@").append(versionClass).append("@class, ")
- .append(column.getProperty()).append(")},");
+ .append(" = ${@tk.mybatis.mapper.version.VersionUtil@nextVersion(")
+ .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()) {
+ //set id = id,
+ sql.append(column.getColumn()).append(" = ").append(column.getColumn()).append(",");
}
}
sql.append("");
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 extends T> 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..27b308744
--- /dev/null
+++ b/extra/src/main/java/tk/mybatis/mapper/additional/upsert/UpsertMapper.java
@@ -0,0 +1,14 @@
+package tk.mybatis.mapper.additional.upsert;
+
+import org.apache.ibatis.annotations.UpdateProvider;
+import tk.mybatis.mapper.annotation.RegisterMapper;
+
+@RegisterMapper
+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();
+ }
+}
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/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/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..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;
/**
@@ -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
new file mode 100644
index 000000000..278714ef5
--- /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 jakarta.persistence.Column;
+import jakarta.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..8bfcc83ea
--- /dev/null
+++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/CreateDB.sql
@@ -0,0 +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
+);
+
+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
new file mode 100644
index 000000000..f7ebe1f26
--- /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("JavaStarter2", beforeDelete.getName());
+
+ int deletedCount = mapper.deleteByProperty(Course::getName, "JavaStarter2");
+ 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..4d4f1a7f9
--- /dev/null
+++ b/extra/src/test/java/tk/mybatis/mapper/additional/delete/mybatis-config.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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/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/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..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;
/**
@@ -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/Book.java b/extra/src/test/java/tk/mybatis/mapper/additional/select/Book.java
new file mode 100644
index 000000000..d883b367e
--- /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 jakarta.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..4edd8de8d
--- /dev/null
+++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/CreateDB.sql
@@ -0,0 +1,18 @@
+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, '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
new file mode 100644
index 000000000..8ad3eb780
--- /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, "JavaStarter1");
+ Assert.assertNotNull(book);
+ Assert.assertEquals("JavaStarter1", 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..8dc2a4791
--- /dev/null
+++ b/extra/src/test/java/tk/mybatis/mapper/additional/select/mybatis-config.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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/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/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..cbc7d3ef0
--- /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 15b2d16b3..6f6117e17 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` 可以不同)。
后两个插件用于演示所有可用的属性,而且是两种不同的模式。
@@ -255,6 +254,7 @@ ${key} - ${props[key]}
实体和表的信息:
表名:${tableClass.tableName}
+表注释:${tableClass.remarks}
变量名:${tableClass.variableName}
小写名:${tableClass.lowerCaseName}
类名:${tableClass.shortClassName}
@@ -354,6 +354,7 @@ Blob列:
测试生成的**部分**结果如下。
实体:
+
```java
@Table(name = "`user_info`")
public class UserInfo {
@@ -364,6 +365,7 @@ public class UserInfo {
```
Dao:
+
```java
package test.mapper;
@@ -380,6 +382,7 @@ public interface UserInfoDao extends tk.mybatis.mapper.common.Mapper {
```
XML:
+
```xml
项目的发展离不开你的支持,请作者喝杯咖啡吧!
+> 项目的发展离不开你的支持,请作者喝杯咖啡吧!
>
>支付宝
>
->
+>
>
>微信
>
->
+>
diff --git a/generator/pom.xml b/generator/pom.xml
index 1653ef973..5cbf3ad77 100644
--- a/generator/pom.xml
+++ b/generator/pom.xml
@@ -28,7 +28,7 @@
tk.mybatismapper-modules
- 1.1.5
+ ${revision}mapper-generatorjar
@@ -37,9 +37,8 @@
Mybatis 通用 Mapper 代码生成器
- 1.1.5
- 2.3.28
- 1.3.7
+ 2.3.33
+ 1.4.2
@@ -58,30 +57,30 @@
org.projectlomboklombok
- 1.16.22
+ 1.18.34providedio.swaggerswagger-annotations
- 1.5.20
+ 1.6.14providedorg.hsqldbsqltool
- 2.3.3
+ 2.5.2test
- javax.persistence
- persistence-api
+ jakarta.persistence
+ jakarta.persistence-apitesttk.mybatismapper-base
- ${mapper-module.version}
+ ${project.version}test
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 985618dfa..0f0ace449 100644
--- a/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java
+++ b/generator/src/main/java/tk/mybatis/mapper/generator/MapperCommentGenerator.java
@@ -38,14 +38,19 @@
import java.util.Set;
public class MapperCommentGenerator implements CommentGenerator {
+
//开始的分隔符,例如mysql为`,sqlserver为[
private String beginningDelimiter = "";
//结束的分隔符,例如mysql为`,sqlserver为]
private String endingDelimiter = "";
//强制生成注解
private boolean forceAnnotation;
+ //强制不生成注解
+ private boolean forceNonAnnotation;
//是否生成swagger注解
private boolean needsSwagger;
+ //逻辑删除字段
+ private String logicDeleteColumn = "";
public MapperCommentGenerator() {
super();
@@ -90,10 +95,18 @@ 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);
}
+ String logicDeleteColumn = properties.getProperty("logicDeleteColumn");
+ if (StringUtility.stringHasValue(logicDeleteColumn)) {
+ this.logicDeleteColumn = logicDeleteColumn;
+ }
}
public String getDelimiterName(String name) {
@@ -168,16 +181,24 @@ 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) + "\")");
+ }
}
+
+ // 添加逻辑删除注解
+ if (column.equals(this.logicDeleteColumn)) {
+ field.addAnnotation("@LogicDelete");
+ }
+
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,9 +206,10 @@ 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注解
if (this.needsSwagger) {
String remarks = introspectedColumn.getRemarks();
@@ -242,7 +264,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());
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..657761d75 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.*;
@@ -39,6 +40,7 @@
* @author liuzh
*/
public class MapperPlugin extends FalseMethodPlugin {
+
private Set mappers = new HashSet();
private boolean caseSensitive = false;
private boolean useMapperCommentGenerator = true;
@@ -52,6 +54,8 @@ public class MapperPlugin extends FalseMethodPlugin {
private CommentGeneratorConfiguration commentCfg;
//强制生成注解
private boolean forceAnnotation;
+ //强制不生成注解
+ private boolean forceNonAnnotation;
//是否需要生成Data注解
private boolean needsData = false;
@@ -63,14 +67,24 @@ 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”
+ private boolean needsEqualsAndHashCodeAndCallSuper = false;
//是否生成字段名常量
private boolean generateColumnConsts = false;
//是否生成默认的属性的静态方法
private boolean generateDefaultInstanceMethod = false;
//是否生成swagger注解,包括 @ApiModel和@ApiModelProperty
private boolean needsSwagger = false;
+ //是否逻辑删除
+ private boolean logicDelete = false;
+
public String getDelimiterName(String name) {
StringBuilder nameBuilder = new StringBuilder();
@@ -88,12 +102,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接口
@@ -114,7 +127,7 @@ public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass,
*/
private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
//引入JPA注解
- topLevelClass.addImportedType("javax.persistence.*");
+ topLevelClass.addImportedType("jakarta.persistence.*");
//lombok扩展开始
//如果需要Data,引入包,代码增加注解
if (this.needsData) {
@@ -136,17 +149,39 @@ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable i
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");
+ }
+ }
+ // 如果需要Accessors,引入包,代码增加注解
if (this.needsAccessors) {
topLevelClass.addImportedType("lombok.experimental.Accessors");
topLevelClass.addAnnotation("@Accessors(chain = true)");
}
- //如果需要Getter,引入包,代码增加注解
- if (this.needsEqualsAndHashCode) {
- topLevelClass.addImportedType("lombok.EqualsAndHashCode");
- topLevelClass.addAnnotation("@EqualsAndHashCode");
+ 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");
}
- //lombok扩展结束
+ if (this.needsAllArgsConstructor) {
+ topLevelClass.addImportedType("lombok.AllArgsConstructor");
+ topLevelClass.addAnnotation("@AllArgsConstructor");
+ }
+ // lombok扩展结束
// region swagger扩展
if (this.needsSwagger) {
//导包
@@ -161,6 +196,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()
@@ -168,54 +224,74 @@ 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()) {
- 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);
+ context.getCommentGenerator().addFieldComment(field, introspectedTable, introspectedColumn);
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);
}
}
+
+ if(this.logicDelete)
+ {
+ topLevelClass.addImportedType("tk.mybatis.mapper.annotation.LogicDelete");
+ }
+
+
if (generateDefaultInstanceMethod) {
- Method defaultMethod = new Method();
+ //注意基本类型和包装的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("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()));
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) {
@@ -225,15 +301,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));
+ }
}
}
@@ -312,13 +400,23 @@ 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);
}
+
+ 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
@@ -334,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");
@@ -346,11 +445,18 @@ public void setProperties(Properties properties) {
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");
+ 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");
- if ("true".equalsIgnoreCase(swagger)) {
+ if ("TRUE".equalsIgnoreCase(swagger)) {
this.needsSwagger = true;
}
if (useMapperCommentGenerator) {
@@ -360,10 +466,16 @@ 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");
this.generateDefaultInstanceMethod = getPropertyAsBoolean("generateDefaultInstanceMethod");
+
+ this.logicDelete = Boolean.parseBoolean(this.properties.getProperty("logicDelete"));
}
protected String getProperty(String key) {
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..83aaedddd 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;
-
+
/**
* 编码
*/
@@ -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;
}
@@ -132,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/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;
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..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
@@ -39,13 +39,14 @@ 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 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 921153865..4ffd7a8bd 100644
--- a/generator/src/main/resources/generator/test-all.ftl
+++ b/generator/src/main/resources/generator/test-all.ftl
@@ -9,104 +9,105 @@ ${dateTime?string["yyyy-MM-dd HH:mm:ss"]}
所有配置的属性信息:
<#list props?keys as key>
-${key} - ${props[key]}
+ ${key} - ${props[key]}
#list>
<#list tableClassSet as tableClass>
-****************************************************************************************
-实体和表的信息:
-表名:${tableClass.tableName}
-变量名:${tableClass.variableName}
-小写名:${tableClass.lowerCaseName}
-类名:${tableClass.shortClassName}
-全名:${tableClass.fullClassName}
-包名:${tableClass.packageName}
+ ****************************************************************************************
+ 实体和表的信息:
+ 表名:${tableClass.tableName}
+ 表注释:${tableClass.remarks!""}
+ 变量名:${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}
- #if>
- 类型包名:${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}
+ #if>
+ 类型包名:${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}
#list>
#if>
<#if tableClass.baseFields??>
- 基础列:
+ 基础列:
<#list tableClass.baseFields as field>
- -------------------------------------
- 列名:${field.columnName}
- 列类型:${field.jdbcType}
- 字段名:${field.fieldName}
- <#if field.remarks??>
- 注释:${field.remarks}
- #if>
- 类型包名:${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}
+ #if>
+ 类型包名:${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}
#list>
#if>
<#if tableClass.blobFields??>
- Blob列:
+ Blob列:
<#list tableClass.blobFields as field>
- -------------------------------------
- 列名:${field.columnName}
- 列类型:${field.jdbcType}
- 字段名:${field.fieldName}
- <#if field.remarks??>
- 注释:${field.remarks}
- #if>
- 类型包名:${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}
+ #if>
+ 类型包名:${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}
#list>
#if>
-=====================================
-全部列:
+ =====================================
+ 全部列:
<#if tableClass.allFields??>
- 列名 - 字段名
+ 列名 - 字段名
<#list tableClass.allFields as field>
- ${field.columnName} - ${field.fieldName}
+ ${field.columnName} - ${field.fieldName}
#list>
#if>
#list>
\ 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..d8ba742d4 100644
--- a/generator/src/main/resources/generator/test-one.ftl
+++ b/generator/src/main/resources/generator/test-one.ftl
@@ -8,11 +8,12 @@ ${dateTime?string["yyyy-MM-dd HH:mm:ss"]}
所有配置的属性信息:
<#list props?keys as key>
-${key} - ${props[key]}
+ ${key} - ${props[key]}
#list>
实体和表的信息:
表名:${tableClass.tableName}
+表注释:${tableClass.remarks!""}
变量名:${tableClass.variableName}
小写名:${tableClass.lowerCaseName}
类名:${tableClass.shortClassName}
@@ -22,88 +23,88 @@ ${key} - ${props[key]}
列的信息:
=====================================
<#if tableClass.pkFields??>
-主键:
+ 主键:
<#list tableClass.pkFields as field>
- -------------------------------------
- 列名:${field.columnName}
- 列类型:${field.jdbcType}
- 字段名:${field.fieldName}
- <#if field.remarks??>
- 注释:${field.remarks}
- #if>
- 类型包名:${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}
+ #if>
+ 类型包名:${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}
#list>
#if>
<#if tableClass.baseFields??>
-基础列:
+ 基础列:
<#list tableClass.baseFields as field>
- -------------------------------------
- 列名:${field.columnName}
- 列类型:${field.jdbcType}
- 字段名:${field.fieldName}
- <#if field.remarks??>
- 注释:${field.remarks}
- #if>
- 类型包名:${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}
+ #if>
+ 类型包名:${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}
#list>
#if>
<#if tableClass.blobFields??>
-Blob列:
+ Blob列:
<#list tableClass.blobFields as field>
- -------------------------------------
- 列名:${field.columnName}
- 列类型:${field.jdbcType}
- 字段名:${field.fieldName}
- <#if field.remarks??>
- 注释:${field.remarks}
- #if>
- 类型包名:${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}
+ #if>
+ 类型包名:${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}
#list>
#if>
=====================================
全部列:
<#if tableClass.allFields??>
-列名 - 字段名
+ 列名 - 字段名
<#list tableClass.allFields as field>
- ${field.columnName} - ${field.fieldName}
+ ${field.columnName} - ${field.fieldName}
#list>
#if>
\ 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 b6c0da5b0..e04cc270f 100644
--- a/generator/src/test/resources/generatorConfig.xml
+++ b/generator/src/test/resources/generatorConfig.xml
@@ -41,8 +41,10 @@
-
-
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 9aeb3a47f..63a69da54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,18 +25,34 @@
4.0.0
-
- tk.mybatis
- mapper-parent
- 3
-
+ tk.mybatismapper-modules
- 1.1.5
+ ${revision}pom
- mapper-parent
+ mapper-modulesMybatis 通用 Mapper 聚合模块
- http://www.mybatis.tk
+ https://mybatis.io
+
+
+ 5.0.1
+ 17
+ 17
+ UTF-8
+ UTF-8
+
+ 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.6
+
@@ -52,13 +68,94 @@
+
+
+
+ jakarta.persistence
+ jakarta.persistence-api
+ ${jpa.version}
+
+
+
+
+ org.mybatis
+ 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
+
+
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+
+
+ org.hsqldb
+ hsqldb
+ ${hsqldb.version}
+ test
+
+
+
+
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+ junit
+ junit
+
+
+ ch.qos.logback
+ logback-classic
+
+
+ org.hsqldb
+ hsqldb
+
+
+
scm:git@github.com:abel533/mapper.gitscm:git@github.com:abel533/mapper.gitgit@github.com:abel533/mapper.git
-
-
+
+ allbasecore
@@ -67,5 +164,139 @@
weekendgeneratorspring-boot-starter
+ solon-plugin
+
+
+
+
+ src/test/resources
+
+
+ src/test/java
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+
+ -parameters
+
+
+
+
+ org.codehaus.mojo
+ flatten-maven-plugin
+ 1.6.0
+
+ true
+ resolveCiFriendliesOnly
+
+
+
+ flatten
+ process-resources
+
+ flatten
+
+
+
+ flatten.clean
+ clean
+
+ clean
+
+
+
+
+
+
+
+
+
+ release
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.3.1
+
+
+ package
+
+ jar-no-fork
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 3.8.0
+
+
+ -Xdoclint:none
+
+
+
+
+ package
+
+ jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ 3.2.5
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+
+
+ --pinentry-mode
+ loopback
+
+
+
+
+ org.sonatype.plugins
+ nexus-staging-maven-plugin
+ 1.7.0
+ 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/solon-plugin/pom.xml b/solon-plugin/pom.xml
new file mode 100644
index 000000000..a1c96260f
--- /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
+ 5.1.0
+ 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..bb27cf852
--- /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 jakarta.persistence.Column;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.Id;
+import jakarta.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
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 应该可以自动提示:

## 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 3f3192e83..97e10a6ad 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.mybatismapper-spring-boot
- 2.1.5
+ ${revision}mapper-spring-boot-autoconfiguremapper-spring-boot-autoconfigure
@@ -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.mybatismapper-core
@@ -74,8 +90,8 @@
true
- javax.annotation
- javax.annotation-api
+ jakarta.persistence
+ jakarta.persistence-apitrue
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
+ *
+ * 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..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
@@ -1,11 +1,11 @@
-/**
- * Copyright 2015-2018 the original author or authors.
+/*
+ * 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
*
- * 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,
@@ -15,21 +15,37 @@
*/
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;
+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;
@@ -55,34 +71,27 @@
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.MapperScannerConfigurer;
import tk.mybatis.spring.mapper.SpringBootBindUtil;
-import javax.sql.DataSource;
-import java.util.Arrays;
-import java.util.List;
-
/**
- * {@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
-@ConditionalOnClass({ SqlSessionFactory.class, SqlSessionFactoryBean.class })
+@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 +100,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 +135,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 +145,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 +170,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 extends LanguageDriver> 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 +213,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,85 +233,117 @@ 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) {
- logger.debug("Searching for mappers annotated with @Mapper");
+ if (!AutoConfigurationPackages.has(this.beanFactory)) {
+ logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.");
+ return;
+ }
+
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
- ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
- scanner.setMapperProperties(environment);
- try {
- if (this.resourceLoader != null) {
- scanner.setResourceLoader(this.resourceLoader);
+ 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()) {
- for (String pkg : packages) {
- logger.debug("Using auto-configuration base package '{}'", pkg);
- }
+ 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){
- packages.addAll(Arrays.asList(properties.getBasePackages()));
+ builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(packages));
+ }
+
+ builder.addPropertyValue("processPropertyPlaceHolders", true);
+ 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:}");
+ }
+
+ // 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 {
- //设置了包名的情况下,不需要指定该注解
- scanner.setAnnotationClass(Mapper.class);
+ builder.addPropertyValue("sqlSessionFactoryBeanName", sqlSessionFactoryBeanName.get());
}
- scanner.registerFilters();
- scanner.doScan(StringUtils.toStringArray(packages));
- } catch (IllegalStateException ex) {
- logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
}
+ 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.");
}
+
}
/**
@@ -276,4 +359,5 @@ public MapperCacheDisabler mapperCacheDisabler() {
}
}
+
}
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..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);
}
}
@@ -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);
}
}
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 9fcfe087b..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
@@ -1,34 +1,43 @@
/**
- * 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
+ *
+ * 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 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.
@@ -39,172 +48,634 @@
@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;
+
+ /**
+ * The default scripting language driver class. (Available when use together with mybatis-spring 2.0.2+)
+ */
+ private Class extends LanguageDriver> 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.
+ */
+ private CoreConfiguration configuration;
+
+ /**
+ * @since 1.1.0
+ */
+ public String getConfigLocation() {
+ return this.configLocation;
+ }
+
+ /**
+ * @since 1.1.0
+ */
+ public void setConfigLocation(String configLocation) {
+ this.configLocation = configLocation;
+ }
+
+ 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 2.1.0
+ */
+ public Class extends LanguageDriver> getDefaultScriptingLanguageDriver() {
+ return defaultScriptingLanguageDriver;
+ }
+
+ /**
+ * @since 2.1.0
+ */
+ public void setDefaultScriptingLanguageDriver(Class extends LanguageDriver> defaultScriptingLanguageDriver) {
+ this.defaultScriptingLanguageDriver = defaultScriptingLanguageDriver;
+ }
+
+ /**
+ * @since 1.2.0
+ */
+ public Properties getConfigurationProperties() {
+ return configurationProperties;
+ }
+
+ /**
+ * @since 1.2.0
+ */
+ public void setConfigurationProperties(Properties configurationProperties) {
+ this.configurationProperties = configurationProperties;
+ }
+
+ public CoreConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(CoreConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public Resource[] resolveMapperLocations() {
+ 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) {
+ try {
+ return resourceResolver.getResources(location);
+ } catch (IOException e) {
+ return new Resource[0];
+ }
+ }
+
+ /**
+ * The configuration properties for mybatis core module.
+ *
+ * @since 3.0.0
+ */
+ public static class CoreConfiguration {
+
+ /**
+ * Specifies the TypeHandler used by default for Enum.
+ */
+ Class extends TypeHandler> 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 extends Log> logImpl;
+ /**
+ * Specifies VFS implementations.
+ */
+ private Class extends VFS> 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 extends Log> getLogImpl() {
+ return logImpl;
+ }
+
+ public void setLogImpl(Class extends Log> logImpl) {
+ this.logImpl = logImpl;
+ }
+
+ public Class extends VFS> getVfsImpl() {
+ return vfsImpl;
+ }
+
+ public void setVfsImpl(Class extends VFS> 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 extends TypeHandler> getDefaultEnumTypeHandler() {
+ return defaultEnumTypeHandler;
+ }
+
+ public void setDefaultEnumTypeHandler(Class extends TypeHandler> 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 79d023a64..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
@@ -1,30 +1,36 @@
/**
- * 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
+ *
+ * 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.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,31 +39,69 @@
*/
public class SpringBootVFS extends VFS {
- private final ResourcePatternResolver resourceResolver;
+ 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());
- }
+ public SpringBootVFS() {
+ this.resourceResolver = new PathMatchingResourcePatternResolver(classLoaderSupplier.get());
+ }
- @Override
- public boolean isValid() {
- return true;
- }
+ @Override
+ public boolean isValid() {
+ return true;
+ }
+
+ /**
+ * 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);
+ }
+ }
- @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));
+ @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());
}
- 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-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.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..e62a7c18c
--- /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,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/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/pom.xml
index d2b19aad1..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.mybatismapper-spring-boot-samples
- 2.1.5
+ ${revision}mapper-spring-boot-sample-annotationjar
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..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;
/**
@@ -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/application.properties b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-annotation/src/main/resources/application.properties
index a077c532c..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
@@ -21,6 +21,10 @@
# 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
+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/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-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/pom.xml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/pom.xml
index 387161401..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.mybatismapper-spring-boot-samples
- 2.1.5
+ ${revision}mapper-spring-boot-sample-xmljar
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..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;
@@ -48,7 +50,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/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..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;
/**
@@ -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/application.yml b/spring-boot-starter/mapper-spring-boot-samples/mapper-spring-boot-sample-xml/src/main/resources/application.yml
index 997c1e7b7..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
@@ -22,15 +22,16 @@
# 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
logging:
level:
- root: WARN
+ root: DEBUG
tk.mybatis.sample.mapper: TRACE
mapper:
not-empty: true
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/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-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 08649fa83..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.mybatismapper-spring-boot
- 2.1.5
+ ${revision}mapper-spring-boot-samplespom
diff --git a/spring-boot-starter/mapper-spring-boot-starter/pom.xml b/spring-boot-starter/mapper-spring-boot-starter/pom.xml
index 9735662c9..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.mybatismapper-spring-boot
- 2.1.5
+ ${revision}mapper-spring-boot-startermapper-spring-boot-starter
diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml
index 4fce2ceef..a53feb6d5 100644
--- a/spring-boot-starter/pom.xml
+++ b/spring-boot-starter/pom.xml
@@ -28,11 +28,10 @@
4.0.0tk.mybatis
- mapper-parent
- 3
+ mapper-modules
+ ${revision}mapper-spring-boot
- 2.1.5pommapper-spring-boot
@@ -46,35 +45,32 @@
- 1.1.5
- 1.1.5
- 3.4.6
- 1.3.2
- 2.1.1.RELEASE
+ 3.0.4
+ 3.3.2spring-snapshots
- http://repo.spring.io/snapshot
+ https://repo.spring.io/snapshottruespring-milestones
- http://repo.spring.io/milestone
+ https://repo.spring.io/milestonespring-snapshots
- http://repo.spring.io/snapshot
+ https://repo.spring.io/snapshotspring-milestones
- http://repo.spring.io/milestone
+ https://repo.spring.io/milestone
@@ -83,32 +79,27 @@
tk.mybatismapper-core
- ${mapper-module.version}
+ ${project.version}tk.mybatismapper-base
- ${mapper-module.version}
+ ${project.version}tk.mybatismapper-weekend
- ${mapper-weekend.version}
+ ${project.version}tk.mybatismapper-spring
- ${mapper-module.version}
+ ${project.version}tk.mybatismapper-extra
- ${mapper-module.version}
-
-
- org.mybatis
- mybatis
- ${mybatis.version}
+ ${project.version}org.mybatis
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 92ca169c9..e3683dbb3 100644
--- a/spring/pom.xml
+++ b/spring/pom.xml
@@ -28,7 +28,7 @@
tk.mybatismapper-modules
- 1.1.5
+ ${revision}mapper-springjar
@@ -37,8 +37,8 @@
Mybatis 通用 Mapper 和 Spring 集成
- 4.3.8.RELEASE
- 1.3.1
+ 6.1.11
+ 3.0.4
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..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
+ * 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.
+ * 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 extends BeanNameGenerator> 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 extends Annotation> 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 extends MapperFactoryBean> 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,4 +208,4 @@
* @return
*/
String mapperHelperRef() 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 4872df054..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,123 +1,285 @@
-/**
- * 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
- *