|
@@ -15,13 +15,13 @@
|
|
|
*/
|
|
|
package com.baomidou.mybatisplus.mapper;
|
|
|
|
|
|
-import java.lang.reflect.ParameterizedType;
|
|
|
-import java.lang.reflect.Type;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.logging.Logger;
|
|
|
-
|
|
|
+import com.baomidou.mybatisplus.MybatisConfiguration;
|
|
|
+import com.baomidou.mybatisplus.annotations.FieldStrategy;
|
|
|
+import com.baomidou.mybatisplus.annotations.IdType;
|
|
|
+import com.baomidou.mybatisplus.toolkit.SqlReservedWords;
|
|
|
+import com.baomidou.mybatisplus.toolkit.TableFieldInfo;
|
|
|
+import com.baomidou.mybatisplus.toolkit.TableInfo;
|
|
|
+import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
|
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
|
|
|
import org.apache.ibatis.executor.keygen.KeyGenerator;
|
|
@@ -34,13 +34,12 @@ import org.apache.ibatis.scripting.LanguageDriver;
|
|
|
import org.apache.ibatis.scripting.defaults.RawSqlSource;
|
|
|
import org.apache.ibatis.session.Configuration;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.MybatisConfiguration;
|
|
|
-import com.baomidou.mybatisplus.annotations.FieldStrategy;
|
|
|
-import com.baomidou.mybatisplus.annotations.IdType;
|
|
|
-import com.baomidou.mybatisplus.toolkit.SqlReservedWords;
|
|
|
-import com.baomidou.mybatisplus.toolkit.TableFieldInfo;
|
|
|
-import com.baomidou.mybatisplus.toolkit.TableInfo;
|
|
|
-import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
|
|
|
+import java.lang.reflect.ParameterizedType;
|
|
|
+import java.lang.reflect.Type;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -537,14 +536,21 @@ public class AutoSqlInjector implements ISqlInjector {
|
|
|
protected String sqlWhereByMap() {
|
|
|
StringBuilder where = new StringBuilder();
|
|
|
where.append("\n<if test=\"cm!=null and !cm.isEmpty\">");
|
|
|
- where.append("\n WHERE ");
|
|
|
+ where.append("\n<where> ");
|
|
|
where.append("\n<foreach collection=\"cm.keys\" item=\"k\" separator=\"AND\"> ");
|
|
|
+ if (MybatisConfiguration.FIELD_STRATEGY == FieldStrategy.NOT_EMPTY){
|
|
|
+ where.append("\n<if test=\"cm[k] != null and cm[k] != ''\">");
|
|
|
+ }else{
|
|
|
+ where.append("\n<if test=\"cm[k] != null\">");
|
|
|
+ }
|
|
|
if (DBType.MYSQL.equals(dbType)) {
|
|
|
where.append("\n`${k}` = #{cm[${k}]}");
|
|
|
}else{
|
|
|
where.append("\n${k} = #{cm[${k}]}");
|
|
|
}
|
|
|
+ where.append("\n</if>");
|
|
|
where.append("\n</foreach>");
|
|
|
+ where.append("\n</where> ");
|
|
|
where.append("\n</if>");
|
|
|
return where.toString();
|
|
|
}
|