Browse Source

修正错误,完善测试(累死了)

miemie 6 years ago
parent
commit
6dda68cea1

+ 6 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/AbstractMethod.java

@@ -159,6 +159,12 @@ public abstract class AbstractMethod {
                     set.append(fieldInfo.getEl()).append("},")
                         .append(convertIfTag(true, fieldInfo, null, true));
                 }
+            }else {
+                set.append(fieldInfo.getColumn()).append("=#{");
+                if (null != prefix) {
+                    set.append(prefix);
+                }
+                set.append(fieldInfo.getEl()).append("},");
             }
         }
         // UpdateWrapper SqlSet 部分

+ 1 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/MysqlMetaObjectHandler.java

@@ -15,7 +15,6 @@ package com.baomidou.mybatisplus.test.mysql;
  * the License.
  */
 
-import java.sql.Timestamp;
 import java.time.LocalDateTime;
 
 import org.apache.ibatis.reflection.MetaObject;
@@ -41,7 +40,6 @@ public class MysqlMetaObjectHandler extends MetaObjectHandler {
         System.out.println("*************************");
         System.out.println("insert fill");
         System.out.println("*************************");
-
         // 测试下划线
         Object createDatetime = this.getFieldValByName("createDatetime", metaObject);
         System.out.println("createDatetime=" + createDatetime);
@@ -58,7 +56,7 @@ public class MysqlMetaObjectHandler extends MetaObjectHandler {
         System.out.println("update fill");
         System.out.println("*************************");
         //测试实体没有的字段,配置在公共填充,不应该set到实体里面
-        this.setFieldValByName("updateDatetime", LocalDateTime.now(), metaObject);
+        this.setFieldValByName("updateDatetime1", LocalDateTime.now(), metaObject);
         this.setFieldValByName("updateDatetime", LocalDateTime.now(), metaObject);
     }
 }

+ 57 - 36
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/MysqlTestDataMapperTest.java

@@ -19,7 +19,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.transaction.annotation.Transactional;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -71,14 +70,12 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
-    @Transactional
     public void deleteById() {
         mapper.deleteById(1014132604940615682L);
         logicMapper.deleteById(1014132604940615682L);
     }
 
     @Test
-    @Transactional
     public void deleteByMap() {
         Map<String, Object> map = new HashMap<>();
         map.put("id", 1014361515785568258L);
@@ -88,15 +85,16 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
-    @Transactional
     public void delete() {
         mapper.delete(new QueryWrapper<TestData>().lambda()
             .eq(TestData::getId, 1014132604940615682L)
             .eq(TestData::getTestInt, 1));
+        logicMapper.delete(new QueryWrapper<LogicTestData>().lambda()
+            .eq(LogicTestData::getId, 1014132604940615682L)
+            .eq(LogicTestData::getTestInt, 1));
     }
 
     @Test
-    @Transactional
     public void deleteBatchIds() {
         List<Long> ids = Arrays.asList(1014132604940615682L, 1014132604940615652L);
         mapper.deleteBatchIds(ids);
@@ -104,53 +102,94 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
-    @Transactional
-    public void updateByIdTest() {
+    public void updateById() {
         mapper.updateById(new TestData().setId(1014132604940615682L).setTestInt(1111111111));
+        logicMapper.updateById(new LogicTestData().setId(1014132604940615682L).setTestInt(1111111111));
     }
 
     @Test
-    @Transactional
-    public void updateTest() {
+    public void update() {
         // type 1
         mapper.update(new TestData(), null);
+        logicMapper.update(new LogicTestData(), null);
         // type 2
         mapper.update(new TestData(), new UpdateWrapper<TestData>()
             .set("test_int", 5));
-        // type 3
+        logicMapper.update(new LogicTestData(), new UpdateWrapper<LogicTestData>()
+            .set("test_int", 5));
+//        // type 3
         mapper.update(new TestData(), new UpdateWrapper<TestData>()
             .set("test_int", 5).eq("id", 1014361515554881538L));
-        // type 4
+        logicMapper.update(new LogicTestData(), new UpdateWrapper<LogicTestData>()
+            .set("test_int", 5).eq("id", 1014361515554881538L));
+//        // type 4
         mapper.update(new TestData(), new UpdateWrapper<TestData>()
             .eq("id", 1014361515554881538L));
-        // type 5
+        logicMapper.update(new LogicTestData(), new UpdateWrapper<LogicTestData>()
+            .eq("id", 1014361515554881538L));
+//        // type 5
         mapper.update(new TestData(), new UpdateWrapper<TestData>()
             .setEntity(new TestData().setTestInt(1)));
-        // type 6
+        logicMapper.update(new LogicTestData(), new UpdateWrapper<LogicTestData>()
+            .setEntity(new LogicTestData().setTestInt(1)));
+//        // type 6
         mapper.update(new TestData(), new UpdateWrapper<TestData>()
             .setEntity(new TestData().setTestInt(1))
             .eq("id", 1014361515554881538L));
-        // type 7
+        logicMapper.update(new LogicTestData(), new UpdateWrapper<LogicTestData>()
+            .setEntity(new LogicTestData().setTestInt(1))
+            .eq("id", 1014361515554881538L));
+//        // type 7
         mapper.update(new TestData(), new UpdateWrapper<TestData>()
             .setEntity(new TestData().setTestInt(1))
             .set("test_int", 55555)
             .eq("id", 1014361515554881538L));
+        logicMapper.update(new LogicTestData(), new UpdateWrapper<LogicTestData>()
+            .setEntity(new LogicTestData().setTestInt(1))
+            .set("test_int", 55555)
+            .eq("id", 1014361515554881538L));
     }
 
     @Test
-    @Transactional
     public void selectById() {
         mapper.selectById(1L);
+        logicMapper.selectById(1L);
     }
 
     @Test
-    @Transactional
     public void selectBatchIds() {
-        mapper.selectBatchIds(Arrays.asList(1014132604940615682L, 1014132604940615652L));
+        List<Long> ids = Arrays.asList(1014132604940615682L, 1014132604940615652L);
+        mapper.selectBatchIds(ids);
+        logicMapper.selectBatchIds(ids);
+    }
+
+    @Test
+    public void selectByMap() {
+        Map<String, Object> map = new HashMap<>();
+        map.put("id", 1L);
+        map.put("test_int", 1);
+        mapper.selectByMap(map);
+        logicMapper.selectByMap(map);
+    }
+
+    @Test
+    public void selectOne() {
+        mapper.selectOne(new QueryWrapper<TestData>().lambda()
+            .eq(TestData::getId,1L).eq(TestData::getTestInt,1));
+        logicMapper.selectOne(new QueryWrapper<LogicTestData>().lambda()
+            .eq(LogicTestData::getId,1L).eq(LogicTestData::getTestInt,1));
+    }
+
+    @Test
+    public void selectList() {
+        mapper.selectList(new QueryWrapper<TestData>().lambda()
+            .eq(TestData::getId,1L).eq(TestData::getTestInt,1));
+        logicMapper.selectList(new QueryWrapper<LogicTestData>().lambda()
+            .eq(LogicTestData::getId,1L).eq(LogicTestData::getTestInt,1));
+        logicMapper.selectList(null);
     }
 
     @Test
-    @Transactional
     public void commonSelectList() {
         println(mapper.selectList(new QueryWrapper<TestData>()
             .eq("id", 1L)
@@ -159,7 +198,6 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
-    @Transactional
     public void specialSelectList() {
         println(mapper.selectList(new QueryWrapper<TestData>().lambda()
             .nested(i -> i.eq(TestData::getId, 1L))
@@ -174,23 +212,6 @@ public class MysqlTestDataMapperTest {
     }
 
     @Test
-    @Transactional
-    public void update() {
-        mapper.update(new TestData().setId(1L).setTestStr("123123"),
-            new UpdateWrapper<TestData>().eq("id", 1L));
-    }
-
-    @Test
-    @Transactional
-    public void selectByMap() {
-        Map<String, Object> map = new HashMap<>();
-        map.put("id", 1L);
-        map.put("test_int", 1);
-        println(mapper.selectByMap(map));
-    }
-
-    @Test
-    @Transactional
     public void selectPage() {
         IPage<TestData> page = new Page<>();
         page.setSize(5).setCurrent(1);