Explorar o código

Merge pull request #3865 from nieqiurong/fix_remove_ids

修复String主键删除失败.
qmdx %!s(int64=3) %!d(string=hai) anos
pai
achega
eb4cdf44e0

+ 2 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/DeleteBatchByIds.java

@@ -38,7 +38,7 @@ public class DeleteBatchByIds extends AbstractMethod {
             sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
                 tableInfo.getKeyColumn(),
                 SqlScriptUtils.convertForeach(
-                    SqlScriptUtils.convertChoose("@com.baomidou.mybatisplus.core.toolkit.ReflectionKit@isPrimitiveOrWrapper(item.getClass())",
+                    SqlScriptUtils.convertChoose("@org.apache.ibatis.type.SimpleTypeRegistry@isSimpleType(item.getClass())",
                         "#{item}", "#{item." + tableInfo.getKeyProperty() + "}"),
                     COLLECTION, null, "item", COMMA),
                 tableInfo.getLogicDeleteSql(true, true));
@@ -48,7 +48,7 @@ public class DeleteBatchByIds extends AbstractMethod {
             sqlMethod = SqlMethod.DELETE_BATCH_BY_IDS;
             sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(),
                 SqlScriptUtils.convertForeach(
-                    SqlScriptUtils.convertChoose("@com.baomidou.mybatisplus.core.toolkit.ReflectionKit@isPrimitiveOrWrapper(item.getClass())",
+                    SqlScriptUtils.convertChoose("@org.apache.ibatis.type.SimpleTypeRegistry@isSimpleType(item.getClass())",
                         "#{item}", "#{item." + tableInfo.getKeyProperty() + "}"),
                     COLLECTION, null, "item", COMMA));
             SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);

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

@@ -47,7 +47,7 @@ public class DeleteById extends AbstractMethod {
                 .collect(toList());
             if (CollectionUtils.isNotEmpty(fieldInfos)) {
                 String sqlSet = "SET " + SqlScriptUtils.convertIf(fieldInfos.stream()
-                    .map(i -> i.getSqlSet(EMPTY)).collect(joining(EMPTY)), "!@com.baomidou.mybatisplus.core.toolkit.ReflectionKit@isPrimitiveOrWrapper(_parameter.getClass())", true)
+                    .map(i -> i.getSqlSet(EMPTY)).collect(joining(EMPTY)), "!@org.apache.ibatis.type.SimpleTypeRegistry@isSimpleType(_parameter.getClass())", true)
                     + tableInfo.getLogicDeleteSql(false, false);
                 sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet, tableInfo.getKeyColumn(),
                     tableInfo.getKeyProperty(), tableInfo.getLogicDeleteSql(true, true));

+ 16 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserTest.java

@@ -530,4 +530,20 @@ class H2UserTest extends BaseTest {
             .eq(H2User::getPrice, 2)
             .getTargetSql();
     }
+    
+    @Test
+    void testRemove() {
+        //不报错即可,无需关注返回值
+        H2User h2User = new H2User(12L, "test");
+        userService.removeById((short) 100);
+        userService.removeById(100.00);
+        userService.removeById((float) 100);
+        userService.removeById(100);
+        userService.removeById(100000L);
+        userService.removeById(new BigDecimal("100"));
+        userService.removeById("100000");
+        userService.removeById(h2User);
+        userService.removeByIds(Arrays.asList((short) 100, 100, 100.00, (float) 100, 10000L, new BigDecimal("100"), h2User));
+    }
+    
 }