| | |
| | | |
| | | /** |
| | | * 转换为Spring Data的Pageable对象 |
| | | * 注意:前端页码从1开始,Spring Data页码从0开始,需要转换 |
| | | */ |
| | | public Pageable toPageable() { |
| | | Sort sortObj = Sort.unsorted(); |
| | |
| | | Sort.Direction direction = "asc".equalsIgnoreCase(order) ? Sort.Direction.ASC : Sort.Direction.DESC; |
| | | sortObj = Sort.by(direction, sort); |
| | | } |
| | | return org.springframework.data.domain.PageRequest.of(page, size, sortObj); |
| | | // 将前端的1-based页码转换为Spring Data的0-based页码 |
| | | int springDataPage = Math.max(0, page - 1); |
| | | return org.springframework.data.domain.PageRequest.of(springDataPage, size, sortObj); |
| | | } |
| | | |
| | | // Getters and Setters |