其他分享
首页 > 其他分享> > 分页查询

分页查询

作者:互联网

依赖

<!--分页插件需导入2个依赖pagehelper、jsqlparser-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.11</version>
        </dependency>
        <dependency>
            <groupId>com.github.jsqlparser</groupId>
            <artifactId>jsqlparser</artifactId>
            <version>2.0</version>
        </dependency>

Controller中

@RequestMapping("/getmycheckout")
	public String getmycheckout(Model model,HttpSession httpSession,@RequestParam(required=false,defaultValue="1") Integer page,
        @RequestParam(required=false,defaultValue="6") Integer pageSize) {
		User user1= (User) httpSession.getAttribute("user");
		Userlist userlist=userlistService.findhasuserlist(user1.getId());
		PageHelper.startPage(page, pageSize);
		List<Userlist> list=userlistService.getmycheckout(userlist.getId());
		PageInfo<Userlist> p=new PageInfo<Userlist>(list);
		model.addAttribute("p", p);
		model.addAttribute("userlistcheck", list);
		model.addAttribute("mainPage","mycheckout.jsp");
		return "zuke/main";
	}

jsp中

<span id=pagelink>
   <div style="LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: right; margin-top: 10px">
       共[<B>${p.total}</B>]条记录,共[<B>${p.pages}</B>]页 ,
       <c:if test="${ p.pageNum > 1 }">
           [<A href="javascript:to_page(${p.prePage})">前一页</A>]
       </c:if>
       <input type="hidden" name="page" id="page" value="" /> 第<B>${p.pageNum}</B>页
       <c:if test="${ p.pageNum < p.pages }">
           [<A href="javascript:to_page(${p.nextPage})">后一页</A>]
       </c:if>
   </div>
</span>


<script language=javascript>
    // 提交分页的查询的表单
    function to_page(page) {
        if (page) {
            $("#page").val(page);
        }
        document.houseForm.submit();
    }
</script>

标签:查询,分页,list,addAttribute,false,model,getmycheckout,page
来源: https://www.cnblogs.com/chaostudy/p/13329363.html