一、mybatis-plus配置类
/**
* mybatis-plus配置
*/
@Configuration
public class MybatisPlusConfig {
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
二、分页工具类
public class PageUtils implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 总记录数
*/
private int totalCount;
/**
* 每页记录数
*/
private int pageSize;
/**
* 总页数
*/
private int totalPage;
/**
* 当前页数
*/
private int currPage;
/**
* 列表数据
*/
private List list;
/**
* 分页
* @param list 列表数据
* @param totalCount 总记录数
* @param pageSize 每页记录数
* @param currPage 当前页数
*/
public PageUtils(List list, int totalCount, int pageSize, int currPage) {
this.list = list;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currPage = currPage;
this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
}
/**
* 分页
*/
public PageUtils(IPage page) {
this.list = page.getRecords();
this.totalCount = (int)page.getTotal();
this.pageSize = (int)page.getSize();
this.currPage = (int)page.getCurrent();
this.totalPage = (int)page.getPages();
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
}
三、多表关联分页查询实现代码
1、Controller层
/**
* 分页查询
* @param params 查询条件
*/
@RequestMapping("/list")
@RequiresPermissions("or:orde:list")
public R list(@RequestParam Map params){
PageUtils page=orderFormService.queryPage(params);
return R.ok().put("page",page);
}
2、Service 层
//分页查询
PageUtils queryPage(Map params);
3、Service 实现层
//分页查询
@Override
public PageUtils queryPage(Map params){
String id= (String) params.get("id");
IPage page = new Query().getPage(params);
List list=orderFormDao.selectList(page,id);
page.setRecords(list);
return new PageUtils(page);
}
4、Dao 层
//分页查询
List selectList(IPage page,@Param("id") String id);
5、XML格式的mapper文件
select
a.*,b.*
from a
left join b on a.OR_NUM =b.OR_NUM
a.ID = #{id}