关于layui的分页插件的使用

来源:互联网 发布:深圳美生创谷淘宝地址 编辑:程序博客网 时间:2024/06/06 01:41

前台html,用于显示分页按钮:

 <div style="text-align: center" id="page">       </div>

前台js:

 layui.use(['laypage'], function(){// 页面引用  var currentPage='${pageInfo.currentPage}'; //当前页  var pageNum='${pageInfo.pageNum}'; //总页数  var totalCount="${pageInfo.totalCount}";  //查询总条数  var pageSize=6;  //每页条数    //分页laypage({  cont: 'page'  ,pages: pageNum  ,groups: 5  ,curr:currentPage  ,first: "首页"  ,last: "尾页"  ,jump: function(obj, first){    if(!first){    window.location.href="${pageContext.request.contextPath}/post/${postInfo.post.postid}/"+obj.curr+".html";    }  }});//模拟渲染var render = function(data, curr){  var arr = []  ,thisData = data.concat().splice(curr*nums-nums, nums);  layui.each(thisData, function(index, item){    arr.push('<li>'+ item +'</li>');  });  return arr.join('');};  }); });

后台处理的controller:

@RequestMapping("/post/{postId}/{currentPage}")public String getAnswer(@PathVariable long postId,  @PathVariable int currentPage,Model model) {if(currentPage==1) {  return "redirect:/post/"+postId+".html";}FlyPageInfo pageInfo=answerService.getPostAnswer(postId, currentPage, 6);PostCatalog catalog=postService.getPostCatalog(postId);model.addAttribute("postInfo", catalog);model.addAttribute("pageInfo", pageInfo);return "jie/detail";}

后台serviceImpl:

//分页 帖子的回答public FlyPageInfo getPostAnswer(long postid,int page, int rows) {FlyAnswerExample example=new FlyAnswerExample();example.setOrderByClause("created asc");example.createCriteria().andPostidEqualTo(postid);PageHelper.startPage(page, rows);List<FlyAnswer> answerList=answerMapper.selectByExampleWithBLOBs(example);for (FlyAnswer flyAnswer : answerList) {try {flyAnswer.setAnstime(DateUtil.getDate(flyAnswer.getCreated()));} catch (ParseException e) {e.printStackTrace();}}PageInfo<FlyAnswer> pageInfo=new PageInfo<FlyAnswer>(answerList);long total = pageInfo.getTotal();FlyPageInfo flyPageInfo=new FlyPageInfo(page,TotalUtil.gePagetTotal(total, rows), total, answerList);return flyPageInfo;}



原创粉丝点击