码迷,mamicode.com
首页 > 其他好文 > 详细

分页 检索

时间:2017-03-10 21:57:00      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:span   val   oid   value   排列   void   result   index   attribute   

controller 页面

public String list(Model model,String deptname,@RequestParam(defaultValue="1",required=false) Integer pageIndex,@RequestParam(defaultValue=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="${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;
    }
    
    
}

 









 

分页 检索

标签:span   val   oid   value   排列   void   result   index   attribute   

原文地址:http://www.cnblogs.com/HeXiaoZhou/p/6533045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!