- SQL(主要是limit语句,设置开始位置和每页大小)
<!--获取所有,简单分页-->
<select id="selectAllGuide" resultMap="BaseResultMap">
select * from guide where del_flag = 0 LIMIT #{startLine},#{pageSize}
</select>
- Mapper
List<Guide> selectAllGuide(@Param("startLine") Integer startLine,@Param("pageSize") Integer pageSize);
- Service
//简单分页功能
//默认页码为第一页,默认每页大小10
Integer defaultPageNum = 1;
Integer defaultPageSize = 10;
if (pageNum == null) {
pageNum = defaultPageNum;
}
if(pageSize == null){
pageSize = defaultPageSize;
}
Integer startLine = (pageNum - 1) * pageSize;
guideList = guideMapper.selectAllGuide(startLine, pageSize);
- controller(传入页码和每页数量)
public CommonReturnType getGuides(@Param("pageNum") Integer pageNum,@Param("pageSize")Integer pageSize, @RequestBody Guide guide) {
String title = guide.getTitle();
String documentId = guide.getDocumentId();
List<Guide> guideList = guideService.getGuideList(pageNum,pageSize,title,documentId);
return CommonReturnType.create(guideList,"查询成功");
}