Commit acb6b046855ac197735075db9dc8b8a97bc8bf75
1 parent
68ba20bc
feat(common): PageResult + MP pagination config REQ-USR-003
Showing
2 changed files
with
43 additions
and
0 deletions
backend/src/main/java/com/xly/erp/common/response/PageResult.java
0 → 100644
| 1 | +package com.xly.erp.common.response; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.NoArgsConstructor; | ||
| 7 | + | ||
| 8 | +import java.util.ArrayList; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +/** REQ-USR-003 引入的通用分页 VO。`data` 字段嵌套此结构。 */ | ||
| 12 | +@Data | ||
| 13 | +@NoArgsConstructor | ||
| 14 | +@AllArgsConstructor | ||
| 15 | +public class PageResult<T> { | ||
| 16 | + private long total; | ||
| 17 | + private List<T> list = new ArrayList<>(); | ||
| 18 | + private long pageNum; | ||
| 19 | + private long pageSize; | ||
| 20 | + | ||
| 21 | + public static <T> PageResult<T> of(IPage<T> page) { | ||
| 22 | + return new PageResult<>(page.getTotal(), page.getRecords(), page.getCurrent(), page.getSize()); | ||
| 23 | + } | ||
| 24 | +} |
backend/src/main/java/com/xly/erp/config/MybatisPlusConfig.java
0 → 100644
| 1 | +package com.xly.erp.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 | +/** REQ-USR-003 引入:注册 MyBatis-Plus 分页拦截器,让 `Page<T>` 自动追加 LIMIT 子句。 */ | ||
| 10 | +@Configuration | ||
| 11 | +public class MybatisPlusConfig { | ||
| 12 | + | ||
| 13 | + @Bean | ||
| 14 | + public MybatisPlusInterceptor mybatisPlusInterceptor() { | ||
| 15 | + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); | ||
| 16 | + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); | ||
| 17 | + return interceptor; | ||
| 18 | + } | ||
| 19 | +} |