فهرست منبع

处理逻辑删除填充与乐观锁冲突.

https://github.com/baomidou/mybatis-plus/issues/6315
nieqiurong 11 ماه پیش
والد
کامیت
693f8c6dd3

+ 10 - 6
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisParameterHandler.java

@@ -85,12 +85,16 @@ public class MybatisParameterHandler extends DefaultParameterHandler {
             if (parameter instanceof Map) {
                 // 处理单参数使用注解标记的时候,尝试提取et来获取实体参数
                 Map<?, ?> map = (Map<?, ?>) parameter;
-                if (map.containsKey(Constants.ENTITY)) {
-                    Object et = map.get(Constants.ENTITY);
-                    if (et != null) {
-                        entity = et;
-                        tableInfo = TableInfoHelper.getTableInfo(entity.getClass());
-                    }
+                Object et = null;
+                if(map.containsKey(Constants.ENTITY)){
+                    et = map.get(Constants.ENTITY);
+
+                } else if(map.containsKey(Constants.MP_FILL_ET)){
+                    et = map.get(Constants.MP_FILL_ET);
+                }
+                if (et != null) {
+                    entity = et;
+                    tableInfo = TableInfoHelper.getTableInfo(entity.getClass());
                 }
             } else {
                 tableInfo = TableInfoHelper.getTableInfo(parameter.getClass());

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/DeleteByIds.java

@@ -85,7 +85,7 @@ public class DeleteByIds extends AbstractMethod {
         String sqlSet = "SET ";
         if (CollectionUtils.isNotEmpty(fieldInfos)) {
             sqlSet += SqlScriptUtils.convertIf(fieldInfos.stream()
-                .map(i -> i.getSqlSet(Constants.ENTITY + StringPool.DOT)).collect(joining(EMPTY)), String.format("%s != null", Constants.ENTITY), true);
+                .map(i -> i.getSqlSet(Constants.MP_FILL_ET + StringPool.DOT)).collect(joining(EMPTY)), String.format("%s != null", Constants.MP_FILL_ET), true);
         }
         sqlSet += StringPool.EMPTY + tableInfo.getLogicDeleteSql(false, false);
         return String.format(sqlMethod.getSql(), tableInfo.getTableName(),

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/mapper/BaseMapper.java

@@ -213,7 +213,7 @@ public interface BaseMapper<T> extends Mapper<T> {
         TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
         Map<String, Object> params = new HashMap<>();
         if (useFill && tableInfo.isWithLogicDelete() && tableInfo.isWithUpdateFill()) {
-            params.put(Constants.ENTITY, tableInfo.newInstance());
+            params.put(Constants.MP_FILL_ET, tableInfo.newInstance());
         }
         params.put(Constants.COLL, collections);
         return sqlSession.delete(mapperInterface.getName() + StringPool.DOT + SqlMethod.DELETE_BY_IDS.getMethod(), params);

+ 8 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/Constants.java

@@ -52,6 +52,14 @@ public interface Constants extends StringPool, Serializable {
      * 实体类
      */
     String ENTITY = "et";
+
+    /**
+     * 填充实体
+     *
+     * @since 3.5.8
+     */
+    String MP_FILL_ET = "mpFillEt";
+
     /**
      * 实体类 带后缀 ==> .
      */