MyBatisPlus实现分页查询
配置类
/**
* @ClassName MyPageConfig
* @Description 分页查询
* @Author cc
* @Date 2022/3/18 18:06
* @Version 1.0
**/
@Configuration
public class MyPageConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
###相关实现代码
@Override
public Page getPage(Integer currentPage, Integer size, Book book) {
Page page = new Page(currentPage,size);
LambdaQueryWrapper<Book> qw = new LambdaQueryWrapper<Book>();
qw.like(Strings.isNotEmpty(book.getName()),Book ::getName,book.getName());
qw.like(Strings.isNotEmpty(book.getAuthor()),Book ::getAuthor,book.getAuthor());
return bookMapper.selectPage(page,qw);
}