springboot mybatis-plus分页
mybatis-plus 分页方法(单纯分页方法)
1、创建配置类 MPConfig
@Configuration
public class MPConfig {
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}
2、在service和serviceImpl里配置
1、service配置
public interface BookService extends IService<**实体类名**> {
public IPage<实体类名> getpage(int currentPage,int pageSize);
}
2、serviceImpl配置
@Autowired
private Mapper Mapper; // 需要哪个mapper,就导入哪个
@Override
public IPage<实体类名> getpage(int currentPage, int pageSize) {
IPage page = new Page(currentPage,pageSize);
Mapper.selectPage(page,null);
return page;
}
3、controller配置
@Autowired
private Service service; // 需要哪个service,就导入哪个
@GetMapping("{currentPage}/{pageSize}")
public R getpage(@PathVariable int currentPage,@PathVariable int pageSize){
IPage<Book> page = bookService.getpage(currentPage,pageSize);
return R.success(page);
}