فهرست منبع

添加注入全NULL插入修改

Caratacus 8 سال پیش
والد
کامیت
6a794d72bf

+ 1 - 1
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/TableId.java

@@ -47,6 +47,6 @@ public @interface TableId {
      * </p>
      * </p>
      * {@link IdType}
      * {@link IdType}
      */
      */
-    IdType type();
+    IdType type() default IdType.NONE;
 
 
 }
 }

+ 1 - 1
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/IdType.java

@@ -27,7 +27,7 @@ public enum IdType {
 	AUTO(0, "数据库ID自增"), INPUT(1, "用户输入ID"),
 	AUTO(0, "数据库ID自增"), INPUT(1, "用户输入ID"),
 
 
 	/* 以下2种类型、只有当插入对象ID 为空,才自动填充。 */
 	/* 以下2种类型、只有当插入对象ID 为空,才自动填充。 */
-	ID_WORKER(2, "全局唯一ID"), UUID(3, "全局唯一ID");
+	ID_WORKER(2, "全局唯一ID"), UUID(3, "全局唯一ID"),NONE(4, "该类型为未设置主键类型");
 
 
 	/** 主键 */
 	/** 主键 */
 	private final int key;
 	private final int key;

+ 4 - 2
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/SqlMethod.java

@@ -19,7 +19,7 @@ package com.baomidou.mybatisplus.enums;
  * <p>
  * <p>
  * MybatisPlus 支持 SQL 方法
  * MybatisPlus 支持 SQL 方法
  * </p>
  * </p>
- * 
+ *
  * @author hubin
  * @author hubin
  * @Date 2016-01-23
  * @Date 2016-01-23
  */
  */
@@ -29,6 +29,7 @@ public enum SqlMethod {
 	 * 插入
 	 * 插入
 	 */
 	 */
 	INSERT_ONE("insert", "插入一条数据", "<script>INSERT INTO %s %s VALUES %s</script>"),
 	INSERT_ONE("insert", "插入一条数据", "<script>INSERT INTO %s %s VALUES %s</script>"),
+	INSERT_ONE_ALL_COLUMN("insertAllColumn", "插入一条数据(选择字段, null 字段不插入)", "<script>INSERT INTO %s %s VALUES %s</script>"),
 
 
 	/**
 	/**
 	 * 删除
 	 * 删除
@@ -42,6 +43,7 @@ public enum SqlMethod {
 	 * 修改
 	 * 修改
 	 */
 	 */
 	UPDATE_BY_ID("updateById", "根据ID 修改数据", "<script>UPDATE %s %s WHERE %s=#{%s}</script>"),
 	UPDATE_BY_ID("updateById", "根据ID 修改数据", "<script>UPDATE %s %s WHERE %s=#{%s}</script>"),
+	UPDATE_ALL_COLUMN_BY_ID("updateAllColumnById", "根据ID 选择修改数据", "<script>UPDATE %s %s WHERE %s=#{%s}</script>"),
 	UPDATE("update", "根据 whereEntity 条件,更新记录", "<script>UPDATE %s %s %s</script>"),
 	UPDATE("update", "根据 whereEntity 条件,更新记录", "<script>UPDATE %s %s %s</script>"),
 
 
 	/**
 	/**
@@ -59,7 +61,7 @@ public enum SqlMethod {
 	SELECT_OBJS("selectObjs", "查询满足条件所有数据", "<script>SELECT %s FROM %s %s</script>");
 	SELECT_OBJS("selectObjs", "查询满足条件所有数据", "<script>SELECT %s FROM %s %s</script>");
 
 
 	private final String method;
 	private final String method;
-	
+
 	private final String desc;
 	private final String desc;
 
 
 	private final String sql;
 	private final String sql;

+ 71 - 47
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java

@@ -15,15 +15,14 @@
  */
  */
 package com.baomidou.mybatisplus.mapper;
 package com.baomidou.mybatisplus.mapper;
 
 
-import com.baomidou.mybatisplus.entity.GlobalConfiguration;
-import com.baomidou.mybatisplus.entity.TableFieldInfo;
-import com.baomidou.mybatisplus.entity.TableInfo;
-import com.baomidou.mybatisplus.enums.FieldStrategy;
-import com.baomidou.mybatisplus.enums.IdType;
-import com.baomidou.mybatisplus.enums.SqlMethod;
-import com.baomidou.mybatisplus.toolkit.SqlReservedWords;
-import com.baomidou.mybatisplus.toolkit.StringUtils;
-import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.ibatis.builder.MapperBuilderAssistant;
 import org.apache.ibatis.builder.MapperBuilderAssistant;
 import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
 import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
 import org.apache.ibatis.executor.keygen.KeyGenerator;
 import org.apache.ibatis.executor.keygen.KeyGenerator;
@@ -40,13 +39,15 @@ import org.apache.ibatis.scripting.LanguageDriver;
 import org.apache.ibatis.scripting.defaults.RawSqlSource;
 import org.apache.ibatis.scripting.defaults.RawSqlSource;
 import org.apache.ibatis.session.Configuration;
 import org.apache.ibatis.session.Configuration;
 
 
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.entity.TableFieldInfo;
+import com.baomidou.mybatisplus.entity.TableInfo;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+import com.baomidou.mybatisplus.enums.IdType;
+import com.baomidou.mybatisplus.enums.SqlMethod;
+import com.baomidou.mybatisplus.toolkit.SqlReservedWords;
+import com.baomidou.mybatisplus.toolkit.StringUtils;
+import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -130,7 +131,8 @@ public class AutoSqlInjector implements ISqlInjector {
 			this.injectDeleteByIdSql(false, mapperClass, modelClass, table);
 			this.injectDeleteByIdSql(false, mapperClass, modelClass, table);
 			this.injectDeleteByIdSql(true, mapperClass, modelClass, table);
 			this.injectDeleteByIdSql(true, mapperClass, modelClass, table);
 			/* 修改 */
 			/* 修改 */
-			this.injectUpdateByIdSql(mapperClass, modelClass, table);
+			this.injectUpdateByIdSql(true,mapperClass, modelClass, table);
+			this.injectUpdateByIdSql(false, mapperClass, modelClass, table);
 			/* 查询 */
 			/* 查询 */
 			this.injectSelectByIdSql(false, mapperClass, modelClass, table);
 			this.injectSelectByIdSql(false, mapperClass, modelClass, table);
 			this.injectSelectByIdSql(true, mapperClass, modelClass, table);
 			this.injectSelectByIdSql(true, mapperClass, modelClass, table);
@@ -143,7 +145,8 @@ public class AutoSqlInjector implements ISqlInjector {
 		 * 正常注入无需主键方法
 		 * 正常注入无需主键方法
 		 */
 		 */
 		/* 插入 */
 		/* 插入 */
-		this.injectInsertOneSql(mapperClass, modelClass, table);
+		this.injectInsertOneSql(true,mapperClass, modelClass, table);
+		this.injectInsertOneSql(false, mapperClass, modelClass, table);
 		/* 删除 */
 		/* 删除 */
 		this.injectDeleteSql(mapperClass, modelClass, table);
 		this.injectDeleteSql(mapperClass, modelClass, table);
 		this.injectDeleteByMapSql(mapperClass, table);
 		this.injectDeleteByMapSql(mapperClass, table);
@@ -166,13 +169,13 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * 自定义方法,注入点(子类需重写该方法)
 	 * 自定义方法,注入点(子类需重写该方法)
 	 */
 	 */
 	public void inject(Configuration configuration, MapperBuilderAssistant builderAssistant, Class<?> mapperClass,
 	public void inject(Configuration configuration, MapperBuilderAssistant builderAssistant, Class<?> mapperClass,
-			Class<?> modelClass, TableInfo table) {
+					   Class<?> modelClass, TableInfo table) {
 		// to do nothing
 		// to do nothing
 	}
 	}
 
 
 	/**
 	/**
 	 * 避免扫描到BaseMapper
 	 * 避免扫描到BaseMapper
-	 * 
+	 *
 	 * @param mapperClass
 	 * @param mapperClass
 	 * @return
 	 * @return
 	 */
 	 */
@@ -198,11 +201,13 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * 注入插入 SQL 语句
 	 * 注入插入 SQL 语句
 	 * </p>
 	 * </p>
 	 *
 	 *
+	 * @param selective
+	 *            是否选择插入
 	 * @param mapperClass
 	 * @param mapperClass
 	 * @param modelClass
 	 * @param modelClass
 	 * @param table
 	 * @param table
 	 */
 	 */
-	protected void injectInsertOneSql(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+	protected void injectInsertOneSql(boolean selective, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
 		/*
 		/*
 		 * INSERT INTO table <trim prefix="(" suffix=")" suffixOverrides=",">
 		 * INSERT INTO table <trim prefix="(" suffix=")" suffixOverrides=",">
 		 * <if test="xx != null">xx,</if> </trim> <trim prefix="values ("
 		 * <if test="xx != null">xx,</if> </trim> <trim prefix="values ("
@@ -212,6 +217,8 @@ public class AutoSqlInjector implements ISqlInjector {
 		KeyGenerator keyGenerator = new NoKeyGenerator();
 		KeyGenerator keyGenerator = new NoKeyGenerator();
 		StringBuilder fieldBuilder = new StringBuilder();
 		StringBuilder fieldBuilder = new StringBuilder();
 		StringBuilder placeholderBuilder = new StringBuilder();
 		StringBuilder placeholderBuilder = new StringBuilder();
+		SqlMethod sqlMethod = selective ? SqlMethod.INSERT_ONE :  SqlMethod.INSERT_ONE_ALL_COLUMN;
+
 		fieldBuilder.append("\n<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">\n");
 		fieldBuilder.append("\n<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">\n");
 		placeholderBuilder.append("\n<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">\n");
 		placeholderBuilder.append("\n<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">\n");
 		String keyProperty = null;
 		String keyProperty = null;
@@ -232,17 +239,22 @@ public class AutoSqlInjector implements ISqlInjector {
 		}
 		}
 
 
 		List<TableFieldInfo> fieldList = table.getFieldList();
 		List<TableFieldInfo> fieldList = table.getFieldList();
+
 		for (TableFieldInfo fieldInfo : fieldList) {
 		for (TableFieldInfo fieldInfo : fieldList) {
-			fieldBuilder.append(convertIfTagIgnored(fieldInfo, false));
-			fieldBuilder.append(fieldInfo.getColumn()).append(",");
-			fieldBuilder.append(convertIfTagIgnored(fieldInfo, true));
-			placeholderBuilder.append(convertIfTagIgnored(fieldInfo, false));
-			placeholderBuilder.append("#{").append(fieldInfo.getEl()).append("},");
-			placeholderBuilder.append(convertIfTagIgnored(fieldInfo, true));
+			if(selective){
+				fieldBuilder.append(convertIfTagIgnored(fieldInfo, false));
+				fieldBuilder.append(fieldInfo.getColumn()).append(",");
+				fieldBuilder.append(convertIfTagIgnored(fieldInfo, true));
+				placeholderBuilder.append(convertIfTagIgnored(fieldInfo, false));
+				placeholderBuilder.append("#{").append(fieldInfo.getEl()).append("},");
+				placeholderBuilder.append(convertIfTagIgnored(fieldInfo, true));
+			}else{
+				fieldBuilder.append(fieldInfo.getColumn()).append(",");
+				placeholderBuilder.append("#{").append(fieldInfo.getEl()).append("},");
+			}
 		}
 		}
 		fieldBuilder.append("\n</trim>");
 		fieldBuilder.append("\n</trim>");
 		placeholderBuilder.append("\n</trim>");
 		placeholderBuilder.append("\n</trim>");
-		SqlMethod sqlMethod = SqlMethod.INSERT_ONE;
 		String sql = String.format(sqlMethod.getSql(), table.getTableName(), fieldBuilder.toString(),
 		String sql = String.format(sqlMethod.getSql(), table.getTableName(), fieldBuilder.toString(),
 				placeholderBuilder.toString());
 				placeholderBuilder.toString());
 		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
 		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
@@ -317,12 +329,12 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * @param modelClass
 	 * @param modelClass
 	 * @param table
 	 * @param table
 	 */
 	 */
-	protected void injectUpdateByIdSql(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-		SqlMethod sqlMethod = SqlMethod.UPDATE_BY_ID;
-		String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlSet(table, null), table.getKeyColumn(),
-				table.getKeyProperty());
-		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-		this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+	protected void injectUpdateByIdSql(boolean selective,Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+		SqlMethod sqlMethod =selective ?  SqlMethod.UPDATE_BY_ID : SqlMethod.UPDATE_ALL_COLUMN_BY_ID;
+        String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlSet(selective, table,null), table.getKeyColumn(),
+                table.getKeyProperty());
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
 	}
 	}
 
 
 	/**
 	/**
@@ -336,7 +348,7 @@ public class AutoSqlInjector implements ISqlInjector {
 	 */
 	 */
 	protected void injectUpdateSql(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
 	protected void injectUpdateSql(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
 		SqlMethod sqlMethod = SqlMethod.UPDATE;
 		SqlMethod sqlMethod = SqlMethod.UPDATE;
-		String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlSet(table, "et."), sqlWhereEntityWrapper(table));
+		String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlSet(true,table, "et."), sqlWhereEntityWrapper(table));
 		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
 		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
 		this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
 		this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
 	}
 	}
@@ -498,6 +510,10 @@ public class AutoSqlInjector implements ISqlInjector {
 		return where.toString();
 		return where.toString();
 	}
 	}
 
 
+
+
+
+
 	/**
 	/**
 	 * <p>
 	 * <p>
 	 * SQL 更新 set 语句
 	 * SQL 更新 set 语句
@@ -508,18 +524,26 @@ public class AutoSqlInjector implements ISqlInjector {
 	 *            前缀
 	 *            前缀
 	 * @return
 	 * @return
 	 */
 	 */
-	protected String sqlSet(TableInfo table, String prefix) {
+	protected String sqlSet(boolean selective,TableInfo table, String prefix) {
 		StringBuilder set = new StringBuilder();
 		StringBuilder set = new StringBuilder();
 		set.append("<trim prefix=\"SET\" suffixOverrides=\",\">");
 		set.append("<trim prefix=\"SET\" suffixOverrides=\",\">");
 		List<TableFieldInfo> fieldList = table.getFieldList();
 		List<TableFieldInfo> fieldList = table.getFieldList();
 		for (TableFieldInfo fieldInfo : fieldList) {
 		for (TableFieldInfo fieldInfo : fieldList) {
-			set.append(convertIfTag(true, fieldInfo, prefix, false));
-			set.append(fieldInfo.getColumn()).append("=#{");
-			if (null != prefix) {
-				set.append(prefix);
-			}
-			set.append(fieldInfo.getEl()).append("},");
-			set.append(convertIfTag(true, fieldInfo, null, true));
+            if (selective){
+                set.append(convertIfTag(true, fieldInfo, prefix, false));
+                set.append(fieldInfo.getColumn()).append("=#{");
+                if (null != prefix) {
+                    set.append(prefix);
+                }
+                set.append(fieldInfo.getEl()).append("},");
+                set.append(convertIfTag(true, fieldInfo, null, true));
+            }else{
+                set.append(fieldInfo.getColumn()).append("=#{");
+                if (null != prefix) {
+                    set.append(prefix);
+                }
+                set.append(fieldInfo.getEl()).append("},");
+            }
 		}
 		}
 		set.append("\n</trim>");
 		set.append("\n</trim>");
 		return set.toString();
 		return set.toString();
@@ -787,7 +811,7 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * 查询
 	 * 查询
 	 */
 	 */
 	public MappedStatement addSelectMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource, Class<?> resultType,
 	public MappedStatement addSelectMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource, Class<?> resultType,
-			TableInfo table) {
+													TableInfo table) {
 		if (null != table) {
 		if (null != table) {
 			String resultMap = table.getResultMap();
 			String resultMap = table.getResultMap();
 			if (null != resultMap) {
 			if (null != resultMap) {
@@ -806,7 +830,7 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * 插入
 	 * 插入
 	 */
 	 */
 	public MappedStatement addInsertMappedStatement(Class<?> mapperClass, Class<?> modelClass, String id, SqlSource sqlSource,
 	public MappedStatement addInsertMappedStatement(Class<?> mapperClass, Class<?> modelClass, String id, SqlSource sqlSource,
-			KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
+													KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
 		return this.addMappedStatement(mapperClass, id, sqlSource, SqlCommandType.INSERT, modelClass, null, Integer.class,
 		return this.addMappedStatement(mapperClass, id, sqlSource, SqlCommandType.INSERT, modelClass, null, Integer.class,
 				keyGenerator, keyProperty, keyColumn);
 				keyGenerator, keyProperty, keyColumn);
 	}
 	}
@@ -828,8 +852,8 @@ public class AutoSqlInjector implements ISqlInjector {
 	}
 	}
 
 
 	public MappedStatement addMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource,
 	public MappedStatement addMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource,
-			SqlCommandType sqlCommandType, Class<?> parameterClass, String resultMap, Class<?> resultType,
-			KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
+											  SqlCommandType sqlCommandType, Class<?> parameterClass, String resultMap, Class<?> resultType,
+											  KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
 		String statementName = mapperClass.getName() + "." + id;
 		String statementName = mapperClass.getName() + "." + id;
 		if (configuration.hasStatement(statementName)) {
 		if (configuration.hasStatement(statementName)) {
 			System.err.println("{" + statementName
 			System.err.println("{" + statementName

+ 35 - 15
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/BaseMapper.java

@@ -29,7 +29,7 @@ import org.apache.ibatis.session.RowBounds;
  * <p>
  * <p>
  * 这个 Mapper 支持 id 泛型
  * 这个 Mapper 支持 id 泛型
  * </p>
  * </p>
- * 
+ *
  * @author hubin
  * @author hubin
  * @Date 2016-01-23
  * @Date 2016-01-23
  */
  */
@@ -39,18 +39,28 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 插入一条记录
 	 * 插入一条记录
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param entity
 	 * @param entity
 	 *            实体对象
 	 *            实体对象
 	 * @return int
 	 * @return int
 	 */
 	 */
 	Integer insert(T entity);
 	Integer insert(T entity);
+	/**
+	 * <p>
+	 * 插入一条记录
+	 * </p>
+	 *
+	 * @param entity
+	 *            实体对象
+	 * @return int
+	 */
+	Integer insertAllColumn(T entity);
 
 
 	/**
 	/**
 	 * <p>
 	 * <p>
 	 * 根据 ID 删除
 	 * 根据 ID 删除
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param id
 	 * @param id
 	 *            主键ID
 	 *            主键ID
 	 * @return int
 	 * @return int
@@ -61,7 +71,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 根据 columnMap 条件,删除记录
 	 * 根据 columnMap 条件,删除记录
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param columnMap
 	 * @param columnMap
 	 *            表字段 map 对象
 	 *            表字段 map 对象
 	 * @return int
 	 * @return int
@@ -72,7 +82,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 根据 entity 条件,删除记录
 	 * 根据 entity 条件,删除记录
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param wrapper
 	 * @param wrapper
 	 *            实体对象封装操作类(可以为 null)
 	 *            实体对象封装操作类(可以为 null)
 	 * @return int
 	 * @return int
@@ -83,7 +93,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 删除(根据ID 批量删除)
 	 * 删除(根据ID 批量删除)
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param idList
 	 * @param idList
 	 *            主键ID列表
 	 *            主键ID列表
 	 * @return int
 	 * @return int
@@ -94,18 +104,28 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 根据 ID 修改
 	 * 根据 ID 修改
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param entity
 	 * @param entity
 	 *            实体对象
 	 *            实体对象
 	 * @return int
 	 * @return int
 	 */
 	 */
 	Integer updateById(T entity);
 	Integer updateById(T entity);
+	/**
+	 * <p>
+	 * 根据 ID 修改
+	 * </p>
+	 *
+	 * @param entity
+	 *            实体对象
+	 * @return int
+	 */
+	Integer updateAllColumnById(T entity);
 
 
 	/**
 	/**
 	 * <p>
 	 * <p>
 	 * 根据 whereEntity 条件,更新记录
 	 * 根据 whereEntity 条件,更新记录
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param entity
 	 * @param entity
 	 *            实体对象
 	 *            实体对象
 	 * @param wrapper
 	 * @param wrapper
@@ -118,7 +138,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 根据 ID 查询
 	 * 根据 ID 查询
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param id
 	 * @param id
 	 *            主键ID
 	 *            主键ID
 	 * @return T
 	 * @return T
@@ -129,7 +149,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 查询(根据ID 批量查询)
 	 * 查询(根据ID 批量查询)
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param idList
 	 * @param idList
 	 *            主键ID列表
 	 *            主键ID列表
 	 * @return List<T>
 	 * @return List<T>
@@ -140,7 +160,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 查询(根据 columnMap 条件)
 	 * 查询(根据 columnMap 条件)
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param columnMap
 	 * @param columnMap
 	 *            表字段 map 对象
 	 *            表字段 map 对象
 	 * @return List<T>
 	 * @return List<T>
@@ -151,7 +171,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 根据 entity 条件,查询一条记录
 	 * 根据 entity 条件,查询一条记录
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param entity
 	 * @param entity
 	 *            实体对象
 	 *            实体对象
 	 * @return T
 	 * @return T
@@ -162,7 +182,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 根据 Wrapper 条件,查询总记录数
 	 * 根据 Wrapper 条件,查询总记录数
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param wrapper
 	 * @param wrapper
 	 *            实体对象
 	 *            实体对象
 	 * @return int
 	 * @return int
@@ -173,7 +193,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 根据 entity 条件,查询全部记录
 	 * 根据 entity 条件,查询全部记录
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param wrapper
 	 * @param wrapper
 	 *            实体对象封装操作类(可以为 null)
 	 *            实体对象封装操作类(可以为 null)
 	 * @return List<T>
 	 * @return List<T>
@@ -206,7 +226,7 @@ public interface BaseMapper<T> {
 	 * <p>
 	 * <p>
 	 * 根据 entity 条件,查询全部记录(并翻页)
 	 * 根据 entity 条件,查询全部记录(并翻页)
 	 * </p>
 	 * </p>
-	 * 
+	 *
 	 * @param rowBounds
 	 * @param rowBounds
 	 *            分页查询条件(可以为 RowBounds.DEFAULT)
 	 *            分页查询条件(可以为 RowBounds.DEFAULT)
 	 * @param wrapper
 	 * @param wrapper

+ 26 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/service/IService.java

@@ -15,13 +15,13 @@
  */
  */
 package com.baomidou.mybatisplus.service;
 package com.baomidou.mybatisplus.service;
 
 
-import com.baomidou.mybatisplus.mapper.Wrapper;
-import com.baomidou.mybatisplus.plugins.Page;
-
 import java.io.Serializable;
 import java.io.Serializable;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
+import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+
 /**
 /**
  * <p>
  * <p>
  * 顶级 Service
  * 顶级 Service
@@ -45,7 +45,18 @@ public interface IService<T> {
 
 
 	/**
 	/**
 	 * <p>
 	 * <p>
-	 * 插入(批量)
+	 * 插入一条记录(选择字段, null 字段不插入)
+	 * </p>
+	 *
+	 * @param entity
+	 *            实体对象
+	 * @return boolean
+	 */
+	boolean insertAllColumn(T entity);
+
+	/**
+	 * <p>
+	 * 插入(批量),该方法不适合 Oracle
 	 * </p>
 	 * </p>
 	 *
 	 *
 	 * @param entityList
 	 * @param entityList
@@ -146,6 +157,17 @@ public interface IService<T> {
 	 */
 	 */
 	boolean updateById(T entity);
 	boolean updateById(T entity);
 
 
+	/**
+	 * <p>
+	 * 根据 ID 选择修改
+	 * </p>
+	 *
+	 * @param entity
+	 *            实体对象
+	 * @return boolean
+	 */
+	boolean updateAllColumnById(T entity);
+
 	/**
 	/**
 	 * <p>
 	 * <p>
 	 * 根据 whereEntity 条件,更新记录
 	 * 根据 whereEntity 条件,更新记录

+ 268 - 261
mybatis-plus/src/main/java/com/baomidou/mybatisplus/service/impl/ServiceImpl.java

@@ -15,6 +15,15 @@
  */
  */
 package com.baomidou.mybatisplus.service.impl;
 package com.baomidou.mybatisplus.service.impl;
 
 
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
+import org.apache.ibatis.session.SqlSession;
+import org.springframework.beans.factory.annotation.Autowired;
+
 import com.baomidou.mybatisplus.entity.TableInfo;
 import com.baomidou.mybatisplus.entity.TableInfo;
 import com.baomidou.mybatisplus.enums.SqlMethod;
 import com.baomidou.mybatisplus.enums.SqlMethod;
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
@@ -29,14 +38,6 @@ import com.baomidou.mybatisplus.toolkit.MapUtils;
 import com.baomidou.mybatisplus.toolkit.ReflectionKit;
 import com.baomidou.mybatisplus.toolkit.ReflectionKit;
 import com.baomidou.mybatisplus.toolkit.StringUtils;
 import com.baomidou.mybatisplus.toolkit.StringUtils;
 import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
 import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
-import org.apache.ibatis.session.SqlSession;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Map;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -48,259 +49,265 @@ import java.util.Map;
  */
  */
 public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
 public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
 
 
-	private static final Log logger = LogFactory.getLog(ServiceImpl.class);
-
-	@Autowired
-	protected M baseMapper;
-
-	@SuppressWarnings("unchecked")
-	protected Class<T> currentModleClass() {
-		return ReflectionKit.getSuperClassGenricType(getClass(), 1);
-	}
-
-	/**
-	 * <p>
-	 * 批量操作 SqlSession
-	 * </p>
-	 */
-	protected SqlSession sqlSessionBatch() {
-		return SqlHelper.sqlSessionBatch(currentModleClass());
-	}
-
-	/**
-	 * 获取SqlStatement
-	 *
-	 * @param sqlMethod
-	 * @return
-	 */
-	protected String sqlStatement(SqlMethod sqlMethod) {
-		return SqlHelper.table(currentModleClass()).getSqlStatement(sqlMethod.getMethod());
-	}
-
-	/**
-	 * <p>
-	 * 判断数据库操作是否成功
-	 * </p>
-	 * <p>
-	 * 注意!! 该方法为 Integer 判断,不可传入 int 基本类型
-	 * </p>
-	 *
-	 * @param result
-	 *            数据库操作返回影响条数
-	 * @return boolean
-	 */
-	protected static boolean retBool(Integer result) {
-		return SqlHelper.retBool(result);
-	}
-
-	public boolean insert(T entity) {
-		return retBool(baseMapper.insert(entity));
-	}
-
-	public boolean insertBatch(List<T> entityList) {
-		return insertBatch(entityList, 30);
-	}
-
-	/**
-	 * 批量插入
-	 *
-	 * @param entityList
-	 * @param batchSize
-	 * @return
-	 */
-	public boolean insertBatch(List<T> entityList, int batchSize) {
-		if (CollectionUtils.isEmpty(entityList)) {
-			throw new IllegalArgumentException("Error: entityList must not be empty");
-		}
-		SqlSession batchSqlSession = sqlSessionBatch();
-		try {
-			int size = entityList.size();
-			String sqlStatement = sqlStatement(SqlMethod.INSERT_ONE);
-			for (int i = 0; i < size; i++) {
-				batchSqlSession.insert(sqlStatement, entityList.get(i));
-				if (i >= 1 && i % batchSize == 0) {
-					batchSqlSession.flushStatements();
-				}
-			}
-			batchSqlSession.flushStatements();
-		} catch (Exception e) {
-			logger.error("Error: Cannot execute insertBatch Method. Cause:" + e);
-			return false;
-		} finally {
-			batchSqlSession.close();
-		}
-		return true;
-
-	}
-
-	/**
-	 * <p>
-	 * TableId 注解存在更新记录,否插入一条记录
-	 * </p>
-	 *
-	 * @param entity
-	 *            实体对象
-	 * @return boolean
-	 */
-	public boolean insertOrUpdate(T entity) {
-		if (null != entity) {
-			Class<?> cls = entity.getClass();
-			TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
-			if (null != tableInfo && StringUtils.isNotEmpty(tableInfo.getKeyProperty())) {
-				Object idVal = ReflectionKit.getMethodValue(cls, entity, tableInfo.getKeyProperty());
-				if (StringUtils.checkValNull(idVal)) {
-					return insert(entity);
-				} else {
-					/*
-					 * 更新成功直接返回,失败执行插入逻辑
+    private static final Log logger = LogFactory.getLog(ServiceImpl.class);
+
+    @Autowired
+    protected M baseMapper;
+
+    @SuppressWarnings("unchecked")
+    protected Class<T> currentModleClass() {
+        return ReflectionKit.getSuperClassGenricType(getClass(), 1);
+    }
+
+    /**
+     * <p>
+     * 批量操作 SqlSession
+     * </p>
+     */
+    protected SqlSession sqlSessionBatch() {
+        return SqlHelper.sqlSessionBatch(currentModleClass());
+    }
+
+    /**
+     * 获取SqlStatement
+     *
+     * @param sqlMethod
+     * @return
+     */
+    protected String sqlStatement(SqlMethod sqlMethod) {
+        return SqlHelper.table(currentModleClass()).getSqlStatement(sqlMethod.getMethod());
+    }
+
+    /**
+     * <p>
+     * 判断数据库操作是否成功
+     * </p>
+     * <p>
+     * 注意!! 该方法为 Integer 判断,不可传入 int 基本类型
+     * </p>
+     *
+     * @param result 数据库操作返回影响条数
+     * @return boolean
+     */
+    protected static boolean retBool(Integer result) {
+        return SqlHelper.retBool(result);
+    }
+
+    public boolean insert(T entity) {
+        return retBool(baseMapper.insert(entity));
+    }
+
+    public boolean insertAllColumn(T entity) {
+        return retBool(baseMapper.insertAllColumn(entity));
+    }
+
+    public boolean insertBatch(List<T> entityList) {
+        return insertBatch(entityList, 30);
+    }
+
+    /**
+     * 批量插入
+     *
+     * @param entityList
+     * @param batchSize
+     * @return
+     */
+    public boolean insertBatch(List<T> entityList, int batchSize) {
+        if (CollectionUtils.isEmpty(entityList)) {
+            throw new IllegalArgumentException("Error: entityList must not be empty");
+        }
+        SqlSession batchSqlSession = sqlSessionBatch();
+        try {
+            int size = entityList.size();
+            String sqlStatement = sqlStatement(SqlMethod.INSERT_ONE);
+            for (int i = 0; i < size; i++) {
+                batchSqlSession.insert(sqlStatement, entityList.get(i));
+                if (i >= 1 && i % batchSize == 0) {
+                    batchSqlSession.flushStatements();
+                }
+            }
+            batchSqlSession.flushStatements();
+        } catch (Exception e) {
+            logger.error("Error: Cannot execute insertBatch Method. Cause:" + e);
+            return false;
+        } finally {
+            batchSqlSession.close();
+        }
+        return true;
+
+    }
+
+    /**
+     * <p>
+     * TableId 注解存在更新记录,否插入一条记录
+     * </p>
+     *
+     * @param entity 实体对象
+     * @return boolean
+     */
+    public boolean insertOrUpdate(T entity) {
+        if (null != entity) {
+            Class<?> cls = entity.getClass();
+            TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
+            if (null != tableInfo && StringUtils.isNotEmpty(tableInfo.getKeyProperty())) {
+                Object idVal = ReflectionKit.getMethodValue(cls, entity, tableInfo.getKeyProperty());
+                if (StringUtils.checkValNull(idVal)) {
+                    return insert(entity);
+                } else {
+                    /*
+                     * 更新成功直接返回,失败执行插入逻辑
 					 */
 					 */
-					return updateById(entity) || insert(entity);
-				}
-			} else {
-				throw new MybatisPlusException("Error:  Can not execute. Could not find @TableId.");
-			}
-		}
-		return false;
-	}
-
-	public boolean insertOrUpdateBatch(List<T> entityList) {
-		return insertOrUpdateBatch(entityList, 30);
-	}
-
-	public boolean insertOrUpdateBatch(List<T> entityList, int batchSize) {
-		if (CollectionUtils.isEmpty(entityList)) {
-			throw new IllegalArgumentException("Error: entityList must not be empty");
-		}
-		SqlSession batchSqlSession = sqlSessionBatch();
-		try {
-			int size = entityList.size();
-			for (int i = 0; i < size; i++) {
-				insertOrUpdate(entityList.get(i));
-				if (i >= 1 && i % batchSize == 0) {
-					batchSqlSession.flushStatements();
-				}
-			}
-			batchSqlSession.flushStatements();
-		} catch (Exception e) {
-			logger.error("Error: Cannot execute insertOrUpdateBatch Method. Cause:" + e);
-			return false;
-		} finally {
-			batchSqlSession.close();
-		}
-		return true;
-	}
-
-	public boolean deleteById(Serializable id) {
-		return retBool(baseMapper.deleteById(id));
-	}
-
-	public boolean deleteByMap(Map<String, Object> columnMap) {
-		if (MapUtils.isEmpty(columnMap)) {
-			throw new MybatisPlusException("deleteByMap columnMap is empty.");
-		}
-		return retBool(baseMapper.deleteByMap(columnMap));
-	}
-
-	public boolean delete(Wrapper<T> wrapper) {
-		return retBool(baseMapper.delete(wrapper));
-	}
-
-	public boolean deleteBatchIds(List<? extends Serializable> idList) {
-		return retBool(baseMapper.deleteBatchIds(idList));
-	}
-
-	public boolean updateById(T entity) {
-		return retBool(baseMapper.updateById(entity));
-	}
-
-	public boolean update(T entity, Wrapper<T> wrapper) {
-		return retBool(baseMapper.update(entity, wrapper));
-	}
-
-	public boolean updateBatchById(List<T> entityList) {
-		return updateBatchById(entityList, 30);
-	}
-
-	public boolean updateBatchById(List<T> entityList, int batchSize) {
-		if (CollectionUtils.isEmpty(entityList)) {
-			throw new IllegalArgumentException("Error: entityList must not be empty");
-		}
-		SqlSession batchSqlSession = sqlSessionBatch();
-		try {
-			int size = entityList.size();
-			String sqlStatement = sqlStatement(SqlMethod.UPDATE_BY_ID);
-			for (int i = 0; i < size; i++) {
-				batchSqlSession.update(sqlStatement, entityList.get(i));
-				if (i >= 1 && i % batchSize == 0) {
-					batchSqlSession.flushStatements();
-				}
-			}
-			batchSqlSession.flushStatements();
-		} catch (Exception e) {
-			logger.error("Error: Cannot execute insertBatch Method. Cause:" + e);
-			return false;
-		} finally {
-			batchSqlSession.close();
-		}
-		return true;
-	}
-
-	public T selectById(Serializable id) {
-		return baseMapper.selectById(id);
-	}
-
-	public List<T> selectBatchIds(List<? extends Serializable> idList) {
-		return baseMapper.selectBatchIds(idList);
-	}
-
-	public List<T> selectByMap(Map<String, Object> columnMap) {
-		return baseMapper.selectByMap(columnMap);
-	}
-
-	public T selectOne(Wrapper<T> wrapper) {
-		return SqlHelper.getObject(baseMapper.selectList(wrapper));
-	}
-
-	public Map<String, Object> selectMap(Wrapper<T> wrapper) {
-		return SqlHelper.getObject(baseMapper.selectMaps(wrapper));
-	}
-
-	public Object selectObj(Wrapper<T> wrapper) {
-		return SqlHelper.getObject(baseMapper.selectObjs(wrapper));
-	}
-
-	public int selectCount(Wrapper<T> wrapper) {
-		return SqlHelper.retCount(baseMapper.selectCount(wrapper));
-	}
-
-	public List<T> selectList(Wrapper<T> wrapper) {
-		return baseMapper.selectList(wrapper);
-	}
-
-	@SuppressWarnings("unchecked")
-	public Page<T> selectPage(Page<T> page) {
-		return selectPage(page, Condition.instance());
-	}
-
-	public List<Map<String, Object>> selectMaps(Wrapper<T> wrapper) {
-		return baseMapper.selectMaps(wrapper);
-	}
-
-	public List<Object> selectObjs(Wrapper<T> wrapper) {
-		return baseMapper.selectObjs(wrapper);
-	}
-
-	@SuppressWarnings({ "rawtypes", "unchecked" })
-	public Page<Map<String, Object>> selectMapsPage(Page page, Wrapper<T> wrapper) {
-		SqlHelper.fillWrapper(page, wrapper);
-		page.setRecords(baseMapper.selectMapsPage(page, wrapper));
-		return page;
-	}
-
-	public Page<T> selectPage(Page<T> page, Wrapper<T> wrapper) {
-		SqlHelper.fillWrapper(page, wrapper);
-		page.setRecords(baseMapper.selectPage(page, wrapper));
-		return page;
-	}
+                    return updateById(entity) || insert(entity);
+                }
+            } else {
+                throw new MybatisPlusException("Error:  Can not execute. Could not find @TableId.");
+            }
+        }
+        return false;
+    }
+
+    public boolean insertOrUpdateBatch(List<T> entityList) {
+        return insertOrUpdateBatch(entityList, 30);
+    }
+
+    public boolean insertOrUpdateBatch(List<T> entityList, int batchSize) {
+        if (CollectionUtils.isEmpty(entityList)) {
+            throw new IllegalArgumentException("Error: entityList must not be empty");
+        }
+        SqlSession batchSqlSession = sqlSessionBatch();
+        try {
+            int size = entityList.size();
+            for (int i = 0; i < size; i++) {
+                insertOrUpdate(entityList.get(i));
+                if (i >= 1 && i % batchSize == 0) {
+                    batchSqlSession.flushStatements();
+                }
+            }
+            batchSqlSession.flushStatements();
+        } catch (Exception e) {
+            logger.error("Error: Cannot execute insertOrUpdateBatch Method. Cause:" + e);
+            return false;
+        } finally {
+            batchSqlSession.close();
+        }
+        return true;
+    }
+
+    public boolean deleteById(Serializable id) {
+        return retBool(baseMapper.deleteById(id));
+    }
+
+    public boolean deleteByMap(Map<String, Object> columnMap) {
+        if (MapUtils.isEmpty(columnMap)) {
+            throw new MybatisPlusException("deleteByMap columnMap is empty.");
+        }
+        return retBool(baseMapper.deleteByMap(columnMap));
+    }
+
+    public boolean delete(Wrapper<T> wrapper) {
+        return retBool(baseMapper.delete(wrapper));
+    }
+
+    public boolean deleteBatchIds(List<? extends Serializable> idList) {
+        return retBool(baseMapper.deleteBatchIds(idList));
+    }
+
+    public boolean updateById(T entity) {
+        return retBool(baseMapper.updateById(entity));
+    }
+
+    public boolean updateAllColumnById(T entity) {
+        return retBool(baseMapper.updateAllColumnById(entity));
+    }
+
+    public boolean update(T entity, Wrapper<T> wrapper) {
+        return retBool(baseMapper.update(entity, wrapper));
+    }
+
+    public boolean updateBatchById(List<T> entityList) {
+        return updateBatchById(entityList, 30);
+    }
+
+    public boolean updateBatchById(List<T> entityList, int batchSize) {
+        if (CollectionUtils.isEmpty(entityList)) {
+            throw new IllegalArgumentException("Error: entityList must not be empty");
+        }
+        SqlSession batchSqlSession = sqlSessionBatch();
+        try {
+            int size = entityList.size();
+            String sqlStatement = sqlStatement(SqlMethod.UPDATE_BY_ID);
+            for (int i = 0; i < size; i++) {
+                batchSqlSession.update(sqlStatement, entityList.get(i));
+                if (i >= 1 && i % batchSize == 0) {
+                    batchSqlSession.flushStatements();
+                }
+            }
+            batchSqlSession.flushStatements();
+        } catch (Exception e) {
+            logger.error("Error: Cannot execute insertBatch Method. Cause:" + e);
+            return false;
+        } finally {
+            batchSqlSession.close();
+        }
+        return true;
+    }
+
+    public T selectById(Serializable id) {
+        return baseMapper.selectById(id);
+    }
+
+    public List<T> selectBatchIds(List<? extends Serializable> idList) {
+        return baseMapper.selectBatchIds(idList);
+    }
+
+    public List<T> selectByMap(Map<String, Object> columnMap) {
+        return baseMapper.selectByMap(columnMap);
+    }
+
+    public T selectOne(Wrapper<T> wrapper) {
+        return SqlHelper.getObject(baseMapper.selectList(wrapper));
+    }
+
+    public Map<String, Object> selectMap(Wrapper<T> wrapper) {
+        return SqlHelper.getObject(baseMapper.selectMaps(wrapper));
+    }
+
+    public Object selectObj(Wrapper<T> wrapper) {
+        return SqlHelper.getObject(baseMapper.selectObjs(wrapper));
+    }
+
+    public int selectCount(Wrapper<T> wrapper) {
+        return SqlHelper.retCount(baseMapper.selectCount(wrapper));
+    }
+
+    public List<T> selectList(Wrapper<T> wrapper) {
+        return baseMapper.selectList(wrapper);
+    }
+
+    @SuppressWarnings("unchecked")
+    public Page<T> selectPage(Page<T> page) {
+        return selectPage(page, Condition.instance());
+    }
+
+    public List<Map<String, Object>> selectMaps(Wrapper<T> wrapper) {
+        return baseMapper.selectMaps(wrapper);
+    }
+
+    public List<Object> selectObjs(Wrapper<T> wrapper) {
+        return baseMapper.selectObjs(wrapper);
+    }
+
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    public Page<Map<String, Object>> selectMapsPage(Page page, Wrapper<T> wrapper) {
+        SqlHelper.fillWrapper(page, wrapper);
+        page.setRecords(baseMapper.selectMapsPage(page, wrapper));
+        return page;
+    }
+
+    public Page<T> selectPage(Page<T> page, Wrapper<T> wrapper) {
+        SqlHelper.fillWrapper(page, wrapper);
+        page.setRecords(baseMapper.selectPage(page, wrapper));
+        return page;
+    }
 
 
 }
 }

+ 2 - 1
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/TableInfoHelper.java

@@ -35,6 +35,7 @@ import com.baomidou.mybatisplus.entity.GlobalConfiguration;
 import com.baomidou.mybatisplus.entity.TableFieldInfo;
 import com.baomidou.mybatisplus.entity.TableFieldInfo;
 import com.baomidou.mybatisplus.entity.TableInfo;
 import com.baomidou.mybatisplus.entity.TableInfo;
 import com.baomidou.mybatisplus.enums.FieldStrategy;
 import com.baomidou.mybatisplus.enums.FieldStrategy;
+import com.baomidou.mybatisplus.enums.IdType;
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.mapper.SqlRunner;
 import com.baomidou.mybatisplus.mapper.SqlRunner;
 
 
@@ -197,7 +198,7 @@ public class TableInfoHelper {
                 /*
                 /*
 				 * 主键策略( 注解 > 全局 > 默认 )
 				 * 主键策略( 注解 > 全局 > 默认 )
 				 */
 				 */
-                if (StringUtils.checkValNull(tableId.type())) {
+                if (IdType.NONE != tableId.type()) {
                     tableInfo.setIdType(tableId.type());
                     tableInfo.setIdType(tableId.type());
                 } else {
                 } else {
                     tableInfo.setIdType(globalConfig.getIdType());
                     tableInfo.setIdType(globalConfig.getIdType());

+ 10 - 9
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/GlobalConfigurationTest.java

@@ -15,6 +15,16 @@
  */
  */
 package com.baomidou.mybatisplus.test;
 package com.baomidou.mybatisplus.test;
 
 
+import java.io.InputStream;
+import java.util.Date;
+import java.util.UUID;
+
+import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.ibatis.session.RowBounds;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.junit.Assert;
+
 import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
 import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
 import com.baomidou.mybatisplus.entity.GlobalConfiguration;
 import com.baomidou.mybatisplus.entity.GlobalConfiguration;
 import com.baomidou.mybatisplus.mapper.Condition;
 import com.baomidou.mybatisplus.mapper.Condition;
@@ -22,15 +32,6 @@ import com.baomidou.mybatisplus.test.mysql.entity.NotPK;
 import com.baomidou.mybatisplus.test.mysql.entity.Test;
 import com.baomidou.mybatisplus.test.mysql.entity.Test;
 import com.baomidou.mybatisplus.test.mysql.mapper.NotPKMapper;
 import com.baomidou.mybatisplus.test.mysql.mapper.NotPKMapper;
 import com.baomidou.mybatisplus.test.mysql.mapper.TestMapper;
 import com.baomidou.mybatisplus.test.mysql.mapper.TestMapper;
-import org.apache.commons.dbcp2.BasicDataSource;
-import org.apache.ibatis.session.RowBounds;
-import org.apache.ibatis.session.SqlSession;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.junit.Assert;
-
-import java.io.InputStream;
-import java.util.Date;
-import java.util.UUID;
 
 
 /**
 /**
  * <p>
  * <p>