|
@@ -0,0 +1,27 @@
|
|
1
|
+package com.api;
|
|
2
|
+
|
|
3
|
+import com.api.dao.ProductMapper;
|
|
4
|
+import com.api.entity.ProductEntity;
|
|
5
|
+import org.junit.Test;
|
|
6
|
+import org.junit.runner.RunWith;
|
|
7
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
8
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
9
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
10
|
+
|
|
11
|
+@RunWith(SpringRunner.class)
|
|
12
|
+@SpringBootTest
|
|
13
|
+public class MybatisPlusTest2 {
|
|
14
|
+ @Autowired
|
|
15
|
+ private ProductMapper productMapper;
|
|
16
|
+ // 测试乐观锁
|
|
17
|
+ @Test
|
|
18
|
+ public void testOpt() {
|
|
19
|
+ ProductEntity productZhang = productMapper.selectById(0);
|
|
20
|
+ ProductEntity productWang = productMapper.selectById(0);
|
|
21
|
+ productZhang.setProductPrice(productZhang.getProductPrice()+1);
|
|
22
|
+ int updateZhang = productMapper.updateById(productZhang);
|
|
23
|
+ productWang.setProductPrice(productWang.getProductPrice()-11);
|
|
24
|
+ int updateWang = productMapper.updateById(productWang);
|
|
25
|
+
|
|
26
|
+ }
|
|
27
|
+}
|