SSM 后端实现简单分页

  1. SQL(主要是limit语句,设置开始位置和每页大小)
    <!--获取所有,简单分页-->
    <select id="selectAllGuide" resultMap="BaseResultMap">
    select * from guide where del_flag = 0 LIMIT #{startLine},#{pageSize}
    </select>
  2. Mapper
    List<Guide> selectAllGuide(@Param("startLine") Integer startLine,@Param("pageSize") Integer pageSize);
  3. 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);
  4. 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,"查询成功");
    }
posted @ 2020-05-22 21:33  CEO雷总  阅读(362)  评论(0编辑  收藏  举报