pagehepler分页后数据再次拼装

public PageInfo<ShowComment> findComment(Long topicId, int pageNum, int pageSize) {
        //sql语句执行之前,添加pagehepler
        PageHelper.startPage(pageNum,pageSize);
        List<Comment> comments = null;
        comments = commentMapper.showComment(topicId);
        //得到整个pageHepler的page对象
        
         Page page = (Page)comments;
         List<ShowComment> showComments = new ArrayList<ShowComment>();
        //查询回复评论
        if(null!=comments) {
            List<ShowReply> showReplies = new ArrayList<ShowReply>();
            for (Comment c : comments) {
              //查询所有原评论回复
                showReplies= commentMapper.showReply(c.getComment_id());
               //拼装一条完整的评论
                ShowComment showComment = new ShowComment();
                showComment.setComment(c);
                showComment.setCommentReplies(showReplies);
                //加入评论集合
                showComments.add(showComment);
            }
        }
        PageInfo<ShowComment>  pageInfo = new PageInfo<ShowComment>(null);
        pageInfo.setList(showComments);
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPages(page.getPages());
        return  pageInfo;
    }

版权声明:本文为weixin_41217541原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。