首页 > 代码库 > 分页 检索
分页 检索
controller 页面
public String list(Model model,String deptname,@RequestParam(defaultValue="http://www.mamicode.com/1",required=false) Integer pageIndex,@RequestParam(defaultValue=http://www.mamicode.com/ResourceKeys.DEFAULT_PAGE_SIZE) Integer pageSize){ PageUtil<Dept>pageModel = deptService.getAllDeptWithPages(deptname,pageIndex,pageSize); model.addAttribute("pageModel", pageModel); return “路径” }
xml 页面
<select id="getCategoryCount" parameterType="java.lang.String" resultType="long"> select count(*) from Dept <where> <if test="_parameter!=null"> and deptname like concat (‘%‘,#{_parameter},‘%‘) </if> </where> </select> <select id="getCategoryWithPages" parameterType="java.util.Map" resultType="Dept"> select *,(@rownum:=@rownum+1) i from (SELECT @rownum:=0) r, dept <where> <if test="deptname!=null"> and deptname like concat (‘%‘,#{deptname},‘%‘) </if> </where> limit #{skip},#{take} </select>
serviceImp
@Override public PageUtil<Dept> getAllDeptWithPages(String deptname, Integer pageIndex, Integer pageSize) { // TODO Auto-generated method stub PageUtil<Dept> pageModel =new PageUtil<Dept>(pageIndex,pageSize); Map<String, Object> map = new HashMap<String, Object>(); map.put("deptname",deptname); map.put("skip",(pageIndex-1)*pageSize); map.put("take",pageSize); List<Dept> list = dao.getCategoryWithPages(map); Long count =dao.getCategoryCount(deptname); pageModel.setDateList(list); pageModel.setTotalCount(count); return pageModel; }
jsp 文件写入
<c:forEach items="${pageModel.dateList }" var="emp" varStatus="status">
<tr>
<td>
<input id="id0" type="checkbox" name="chkDeptIds" value="http://www.mamicode.com/${emp.empid }" /></td>
<td>${(clients.pageIndex-1)*clients.pageSize+status.index+1 }</td>
<td>${emp.empname}</td>
</tr>
</c:forEach>
${(clients.pageIndex-1)*clients.pageSize+status.index+1 } 排列序号
PageUtil 分页类
package com.wskj.ssm.util; import java.util.List; public class PageUtil<T> { private Integer pageIndex = 1; private Integer pageSize = 10; private Integer pageCount = 0; public PageUtil (){ super(); } public PageUtil(Integer pageIndex, Integer pageSize) { super(); this.pageIndex = pageIndex; this.pageSize = pageSize; } private List<T> dateList; private Long totalCount = 0l; public Integer getPageIndex() { return pageIndex; } public void setPageIndex(Integer pageIndex) { this.pageIndex = pageIndex; } public Integer getPageSize() { return pageSize; } public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } public Integer getPageCount() { pageCount =(int) Math.ceil(this.totalCount * 1.0/this.pageSize); return pageCount; } public void setPageCount(Integer pageCount) { this.pageCount = pageCount; } public List<T> getDateList() { return dateList; } public void setDateList(List<T> dateList) { this.dateList = dateList; } public Long getTotalCount() { return totalCount; } public void setTotalCount(Long totalCount) { this.totalCount = totalCount; } }
分页 检索
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。