分页插件

分页插件
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>

mapper接口
/**
* 查询菜单列表
* @param param
* @return
*/
List<SysMenu> getAllMenuList(SysMenuParam param);

mapper对应的xml文件
<select id="getAllMenuList" parameterType="com.example.model.po.request.sys.SysMenuParam"
resultType="com.example.model.po.base.mbg.SysMenu">
SELECT
MenuId,MenuCode,MenuIcon,MenuName,ParentCode,MenuFullCode,MenuFullName,Sort,EnableFlag,ViewId,DeleteFlag,CreateDate,CreateUser,UpdateDate,UpdateUser,Source
FROM SYS_Menu WHERE 1=1 and DeleteFlag=0
</select>

测试类
@Test
public void getListByPage(){
SysMenuParam sysMenuParam=new SysMenuParam();
sysMenuParam.setPageNum(2);
sysMenuParam.setPageSize(10);
//第一个参数:页数,第二个参数:每页的行数。应该是页面传过来的参数,这里面我的写固定值测试。
PageHelper.startPage(sysMenuParam.getPageNum(),sysMenuParam.getPageSize());
//PageHelper.startPage(1,10);
//查询集合
List<SysMenu> menuList = sysMenuMapperCustom.getAllMenuList(sysMenuParam);
System.out.println("分页集合数量:"+menuList.size());
menuList.forEach(info ->{
System.out.println(info);
});
}


service 层 方法
/**
* 根据条件获取所有角色列表
* 分页
* @param param
* @return
*/
public PageInfo getAllRoleApply(ApplyViewRoleParam param){
PageHelper.startPage(param.getPageNum(), param.getPageSize());
List<ApplyViewRoleVO> list = applyViewRoleMapperCustom.getAllRoleApply(param);
return new PageInfo(list);
}

controller 层
@ApiOperation(value = "分页获取申请列表",notes = "分页获取申请列表<p>必填参数</p> pageNum、pageSize")
@RequestMapping(value = "/getViewRoleListByKeyWord",method = RequestMethod.POST)
public JsonResult getViewRoleListByKeyWord(@RequestBody ApplyViewRoleParam param){
if(!checkPage(param)){
return JsonResult.error(ErrorCodeEnum.PAGE_PARAM_ERROR.getCode(),ErrorCodeEnum.PAGE_PARAM_ERROR.getMsg());
}
if (StringUtils.isBlank(param.getApplyViewId())){
return JsonResult.error(ErrorCodeEnum.PARAM_IS_NULL.getCode(),ErrorCodeEnum.PARAM_IS_NULL.getMsg());
}
return JsonResult.getResult(applyViewRoleService.getAllRoleApply(param));
}
原文地址:https://www.cnblogs.com/ming-blogs/p/10784425.html