Mybatis分页
< dependency> < groupId> com.github.pagehelper</ groupId> < artifactId> pagehelper-spring-boot-starter</ artifactId> < version> 1.4.2</ version> </ dependency>
public PageBean selectByPage ( String name, Integer gender, LocalDate begin, LocalDate end, Integer page, Integer pageSize) { PageHelper . startPage ( page, pageSize) ; List < Emp > empList = empMapper. selectEmps ( name, gender, begin, end) ; Page < Emp > p = ( Page < Emp > ) empList; PageBean pageBean = new PageBean ( p. getTotal ( ) , p. getResult ( ) ) ; return pageBean;
}
MybatisPlus分页
@Configuration
public class MybatisConfig { @Bean public MybatisPlusInterceptor mybatisPlusInterceptor ( ) { MybatisPlusInterceptor interceptor= new MybatisPlusInterceptor ( ) ; PaginationInnerInterceptor paginationInnerInterceptor= new PaginationInnerInterceptor ( DbType . MYSQL ) ; paginationInnerInterceptor. setMaxLimit ( 1000L ) ; interceptor. addInnerInterceptor ( paginationInnerInterceptor) ; return interceptor; }
}
@Override public void page ( EmployeePageQueryDTO employeePageQueryDTO) { Page < Employee > page= new Page < > ( employeePageQueryDTO. getPage ( ) , employeePageQueryDTO. getPageSize ( ) ) ; LambdaQueryWrapper < Employee > lambdaQueryWrapper= new LambdaQueryWrapper < > ( ) ; lambdaQueryWrapper. like ( StringUtils . hasLength ( employeePageQueryDTO. getName ( ) ) , Employee :: getName , employeePageQueryDTO. getName ( ) ) ; lambdaQueryWrapper. orderByDesc ( Employee :: getUpdateTime ) ; lambdaQueryWrapper. orderByAsc ( Employee :: getCreateTime ) ; employeeMapper. selectPage ( page, lambdaQueryWrapper) ; System . out. println ( page. getTotal ( ) ) ; System . out. println ( page. getRecords ( ) ) ; }