Browse Source

修复 github issues/379

hubin 7 years ago
parent
commit
091fb1e307

+ 19 - 6
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicUpdateById.java

@@ -34,13 +34,26 @@ public class LogicUpdateById extends LogicAbstractMethod {
 
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        String sql;
         SqlMethod sqlMethod = SqlMethod.UPDATE_BY_ID;
-        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet(true, false, tableInfo, "et."),
-            tableInfo.getKeyColumn(), new StringBuilder("et.").append(tableInfo.getKeyProperty()).toString(),
-            new StringBuilder("<if test=\"et instanceof java.util.Map\">")
-                .append("<if test=\"et.MP_OPTLOCK_VERSION_ORIGINAL!=null\">")
-                .append(" AND ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}")
-                .append("</if></if> AND ").append(getLogicDeleteSql(tableInfo)));
+        if (tableInfo.isLogicDelete()) {
+
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet(true, false, tableInfo, "et."),
+                tableInfo.getKeyColumn(), new StringBuilder("et.").append(tableInfo.getKeyProperty()).toString(),
+                new StringBuilder("<if test=\"et instanceof java.util.Map\">")
+                    .append("<if test=\"et.MP_OPTLOCK_VERSION_ORIGINAL!=null\">")
+                    .append(" AND ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}")
+                    .append("</if></if> AND ").append(getLogicDeleteSql(tableInfo)));
+        } else {
+            sqlMethod = SqlMethod.UPDATE_BY_ID;
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(),
+                sqlSet(false, false, tableInfo, "et."),
+                tableInfo.getKeyColumn(), "et." + tableInfo.getKeyProperty(),
+                new StringBuilder("<if test=\"et instanceof java.util.Map\">")
+                    .append("<if test=\"et.MP_OPTLOCK_VERSION_ORIGINAL!=null\">")
+                    .append(" AND ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}")
+                    .append("</if></if>"));
+        }
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
         return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
     }

+ 5 - 5
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java

@@ -169,20 +169,20 @@ public class TableInfo {
                 if (field.isKeyFlag()) {
                     // 主键
                     if (field.isConvert() || field.isKeyIdentityFlag()) {
-                        pkgSet.add("com.baomidou.mybatisplus.annotations.TableId");
+                        pkgSet.add(com.baomidou.mybatisplus.annotation.TableId.class.getCanonicalName());
                     }
                     // 自增
                     if (field.isKeyIdentityFlag()) {
-                        pkgSet.add("com.baomidou.mybatisplus.enums.IdType");
+                        pkgSet.add(com.baomidou.mybatisplus.annotation.IdType.class.getCanonicalName());
                     }
                 } else if (field.isConvert()) {
                     // 普通字段
-                    pkgSet.add("com.baomidou.mybatisplus.annotations.TableField");
+                    pkgSet.add(com.baomidou.mybatisplus.annotation.TableField.class.getCanonicalName());
                 }
                 if (null != field.getFill()) {
                     // 填充字段
-                    pkgSet.add("com.baomidou.mybatisplus.annotations.TableField");
-                    pkgSet.add("com.baomidou.mybatisplus.enums.FieldFill");
+                    pkgSet.add(com.baomidou.mybatisplus.annotation.TableField.class.getCanonicalName());
+                    pkgSet.add(com.baomidou.mybatisplus.annotation.FieldFill.class.getCanonicalName());
                 }
             }
             if (!pkgSet.isEmpty()) {