Commit 863861338bb14af26aecf11ec3456f851ea3a4b0
1 parent
0281d6ed
feat(usr): MyBatis-Plus 分页拦截器配置 REQ-USR-001
Showing
2 changed files
with
30 additions
and
0 deletions
backend/src/main/java/com/xly/test4/common/config/MybatisPlusConfig.java
0 → 100644
| 1 | +package com.xly.test4.common.config; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.DbType; | ||
| 4 | +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | ||
| 5 | +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; | ||
| 6 | +import org.springframework.context.annotation.Bean; | ||
| 7 | +import org.springframework.context.annotation.Configuration; | ||
| 8 | + | ||
| 9 | +@Configuration | ||
| 10 | +public class MybatisPlusConfig { | ||
| 11 | + | ||
| 12 | + @Bean | ||
| 13 | + public MybatisPlusInterceptor mybatisPlusInterceptor() { | ||
| 14 | + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); | ||
| 15 | + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); | ||
| 16 | + return interceptor; | ||
| 17 | + } | ||
| 18 | +} |
backend/src/test/java/com/xly/test4/ApplicationContextIT.java
| @@ -2,6 +2,8 @@ package com.xly.test4; | @@ -2,6 +2,8 @@ package com.xly.test4; | ||
| 2 | 2 | ||
| 3 | import java.util.Map; | 3 | import java.util.Map; |
| 4 | 4 | ||
| 5 | +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | ||
| 6 | +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; | ||
| 5 | import org.junit.jupiter.api.Test; | 7 | import org.junit.jupiter.api.Test; |
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | import org.springframework.boot.test.context.SpringBootTest; | 9 | import org.springframework.boot.test.context.SpringBootTest; |
| @@ -19,6 +21,9 @@ class ApplicationContextIT { | @@ -19,6 +21,9 @@ class ApplicationContextIT { | ||
| 19 | @Autowired | 21 | @Autowired |
| 20 | private JdbcTemplate jdbcTemplate; | 22 | private JdbcTemplate jdbcTemplate; |
| 21 | 23 | ||
| 24 | + @Autowired | ||
| 25 | + private MybatisPlusInterceptor mybatisPlusInterceptor; | ||
| 26 | + | ||
| 22 | @Test | 27 | @Test |
| 23 | void contextLoads() { | 28 | void contextLoads() { |
| 24 | assertThat(context).isNotNull(); | 29 | assertThat(context).isNotNull(); |
| @@ -46,4 +51,11 @@ class ApplicationContextIT { | @@ -46,4 +51,11 @@ class ApplicationContextIT { | ||
| 46 | Integer.class); | 51 | Integer.class); |
| 47 | assertThat(authCount).isEqualTo(4); | 52 | assertThat(authCount).isEqualTo(4); |
| 48 | } | 53 | } |
| 54 | + | ||
| 55 | + @Test | ||
| 56 | + void paginationInterceptorRegistered() { | ||
| 57 | + assertThat(mybatisPlusInterceptor).isNotNull(); | ||
| 58 | + assertThat(mybatisPlusInterceptor.getInterceptors()) | ||
| 59 | + .anyMatch(i -> i instanceof PaginationInnerInterceptor); | ||
| 60 | + } | ||
| 49 | } | 61 | } |