zoukankan      html  css  js  c++  java
  • 分页

    package com.java.activiti.page;
    import java.util.List;

    /*
    * 分页工具类
    */
    public class PageInfo<T> {
    public Integer pageSize = 5;
    private Integer count;// 总记录数
    private List<T> pageList;// 当前页的记录集合
    private Integer pageIndex;// 当前页号
    private Integer totalPages;// 总页数

    public Integer getPageSize() {
    return pageSize;
    }

    public void setPageSize(Integer pageSize) {
    this.pageSize = pageSize;
    }

    public Integer getCount() {
    return count;
    }


    public void setCount(Integer count) {
    this.count = count;
    }

    public List<T> getPageList() {
    return pageList;
    }

    public void setPageList(List<T> pageList) {
    this.pageList = pageList;
    }

    public Integer getPageIndex() {
    return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
    this.pageIndex = pageIndex;
    }

    public Integer getTotalPages() {
    this.totalPages = this.count / this.pageSize;
    if (this.count % this.pageSize != 0)
    this.totalPages++;
    return this.totalPages;
    }

    }

    例子:

    /**
    * 分页查询用户
    * @return
    * @throws Exception
    */
    @RequestMapping("/userPage")
    public String userPage(HttpServletResponse response,
    @RequestParam(value = "page", required = false) String page,
    @RequestParam(value = "rows", required = false) String rows,
    User user) throws Exception{
    Map<String,Object> userMap=new HashMap<String, Object>();
    userMap.put("id", user.getId());

    PageInfo<User> userPage = new PageInfo<User>();
    Integer pageSize=Integer.parseInt(rows);
    userPage.setPageSize(pageSize);

    // 第几页
    String pageIndex = page;
    if (pageIndex == null || pageIndex == "") {
    pageIndex = "1";
    }
    userPage.setPageIndex((Integer.parseInt(pageIndex) - 1)
    * pageSize);
    // 取得总页数
    int userCount=userService.userCount(userMap);
    userPage.setCount(userCount);
    userMap.put("pageIndex", userPage.getPageIndex());
    userMap.put("pageSize", userPage.getPageSize());

    List<User> cusDevPlanList = userService.userPage(userMap);
    JSONObject json = new JSONObject();
    // 把List格式转换成JSON
    JSONArray jsonArray = JSONArray.fromObject(cusDevPlanList);
    json.put("rows", jsonArray);
    json.put("total", userCount);
    ResponseUtil.write(response, json);
    return null;
    }

  • 相关阅读:
    Apache Ant 1.9.1 版发布
    Apache Subversion 1.8.0rc2 发布
    GNU Gatekeeper 3.3 发布,网关守护管理
    Jekyll 1.0 发布,Ruby 的静态网站生成器
    R语言 3.0.1 源码已经提交到 Github
    SymmetricDS 3.4.0 发布,数据同步和复制
    beego 0.6.0 版本发布,Go 应用框架
    Doxygen 1.8.4 发布,文档生成工具
    SunshineCRM 20130518发布,附带更新说明
    Semplice Linux 4 发布,轻量级发行版
  • 原文地址:https://www.cnblogs.com/minxiaofei/p/9771026.html
Copyright © 2011-2022 走看看