Преглед изворни кода

先提交测试,后期去除h2StudentService注入.

聂秋秋 пре 6 година
родитељ
комит
4b4314338c

+ 10 - 4
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserServiceImpl.java

@@ -20,6 +20,8 @@ import java.util.List;
 import java.util.Map;
 
 import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2Student;
+import com.baomidou.mybatisplus.test.h2.service.IH2StudentService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -43,6 +45,9 @@ public class H2UserServiceImpl extends ServiceImpl<H2UserMapper, H2User> impleme
 
     @Autowired
     private H2UserMapper userMapper;
+    
+    @Autowired
+    private IH2StudentService h2StudentService;
 
     @Override
     public int myInsert(String name, int version) {
@@ -112,8 +117,8 @@ public class H2UserServiceImpl extends ServiceImpl<H2UserMapper, H2User> impleme
     @Override
     @Transactional(rollbackFor = RuntimeException.class)
     public void testSaveOrUpdateBatchTransactional() {
-        saveOrUpdateBatch(Arrays.asList(new H2User("savOrUpdate1"),new H2User("savOrUpdate2"),new H2User("savOrUpdate3")),1);
-        saveOrUpdateBatch(Arrays.asList(new H2User("savOrUpdate4"),new H2User("savOrUpdate5"),new H2User("savOrUpdate6")),1);
+        saveOrUpdateBatch(Arrays.asList(new H2User("savOrUpdate1",0),new H2User("savOrUpdate2",0),new H2User("savOrUpdate3",0)),1);
+        saveOrUpdateBatch(Arrays.asList(new H2User("savOrUpdate4",0),new H2User("savOrUpdate5",0),new H2User("savOrUpdate6",0)),1);
         throw new MybatisPlusException("测试普通插入事务回滚");
     }
     
@@ -121,8 +126,9 @@ public class H2UserServiceImpl extends ServiceImpl<H2UserMapper, H2User> impleme
     @Transactional(rollbackFor = RuntimeException.class)
     public void testSimpleAndBatchTransactional() {
         save(new H2User("simpleAndBatchTx1",0));
-        saveBatch(Arrays.asList(new H2User("simpleAndBatchTx2"),new H2User("simpleAndBatchTx3"),new H2User("simpleAndBatchTx4")),1);
-        saveOrUpdateBatch(Arrays.asList(new H2User("simpleAndBatchTx5"),new H2User("simpleAndBatchTx6"),new H2User("simpleAndBatchTx7")),1);
+        h2StudentService.saveBatch(Arrays.asList(new H2Student(null, "tx1", 2),new H2Student(null, "tx1", 2),new H2Student(null, "tx1", 2)));
+        saveBatch(Arrays.asList(new H2User("simpleAndBatchTx2",0),new H2User("simpleAndBatchTx3",0),new H2User("simpleAndBatchTx4",0)),1);
+        saveOrUpdateBatch(Arrays.asList(new H2User("simpleAndBatchTx5",0),new H2User("simpleAndBatchTx6",0),new H2User("simpleAndBatchTx7",0)),1);
         throw new MybatisPlusException("测试事务回滚");
     }
 }