File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
4-Spring/SpringBoot/code/mybatis-plus/src
main/java/com/tawe/mybatisplus/config
test/java/com/tawe/mybatisplus Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,15 @@ public class MyBatisPlusConfig {
3838 // 增加乐观锁
3939 @ Bean
4040 public MybatisPlusInterceptor mybatisPlusInterceptor () {
41+
4142 MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor ();
43+
44+ // 乐观锁插件
4245 interceptor .addInnerInterceptor (new OptimisticLockerInnerInterceptor ());
46+
47+ // 分页插件
48+ interceptor .addInnerInterceptor (new PaginationInnerInterceptor ());
49+
4350 return interceptor ;
4451 }
4552}
Original file line number Diff line number Diff line change 11package com .tawe .mybatisplus ;
22
3+ import com .baomidou .mybatisplus .extension .plugins .pagination .Page ;
34import com .tawe .mybatisplus .entity .User ;
45import com .tawe .mybatisplus .mapper .UserMapper ;
56import org .junit .jupiter .api .Test ;
67import org .springframework .beans .factory .annotation .Autowired ;
78import org .springframework .boot .test .context .SpringBootTest ;
89import org .springframework .test .context .junit4 .SpringRunner ;
910
11+ import java .util .Arrays ;
12+ import java .util .HashMap ;
1013import java .util .List ;
1114
1215@ SpringBootTest
@@ -64,4 +67,26 @@ public void testOptimisticLocker() {
6467 userMapper .updateById (user );
6568 }
6669
70+ @ Test
71+ public void testSelectFunctions () {
72+ // 根据 ID 查询
73+ User user1 = userMapper .selectById (1321036140195209217L );
74+ // 根据多个 IDs 查询
75+ List <User > users = userMapper .selectBatchIds (Arrays .asList (1L , 2L , 3L ));
76+
77+ // 根据 多个 条件 进行查询
78+ HashMap <String , Object > map = new HashMap <>();
79+ map .put ("id" , 1L );
80+ map .put ("name" , "David Tang2" );
81+
82+ userMapper .selectByMap (map );
83+
84+ }
85+
86+ @ Test
87+ public void testSelectPage () {
88+ Page <User > userPage = userMapper .selectPage (new Page <>(3 ,5 ), null );
89+ System .out .println (userPage );
90+ }
91+
6792}
You can’t perform that action at this time.
0 commit comments