zoukankan      html  css  js  c++  java
  • PageInfo实现分页


    import com.github.pagehelper.Page;
    需要导入的jar Controller
    import com.github.pagehelper.PageInfo;


    @RequestMapping(value = "/getMoreBook",produces="application/json;charset=utf-8")//处理返回中文乱码
    @ResponseBody
    public String getMoreBook(String type,String majorCate,@RequestParam(required = false,defaultValue = "1")String page) {
    PageInfo<Book> books=new PageInfo<Book>();
    books=bookServiceImpl.getMoreBook(type,majorCate,page);
    JSONObject jsObj= new JSONObject();
    jsObj.put("status",1);
    jsObj.put("msg","ok");
    jsObj.put("content",books);
    return jsObj.toString();
    }

    Service
    PageInfo<Book> getMoreBook(String type, String majorCate, String page);
    ServiceImpl
    public PageInfo<Book> getMoreBook(String type, String majorCate, String page){
    try {
    PageHelper.startPage(Integer.parseInt(page), 10);
    List<Book> books = bookMapper.getMoreBook(type,majorCate);
    PageInfo<Book> pageInfo = new PageInfo<Book>(books);
    return pageInfo;
    } catch (Exception e) {
    e.printStackTrace();
    return null;
    }
    }

    返回的数据格式

    {
    "content": {
    "endRow": 100,
    "firstPage": 6,
    "hasNextPage": true,
    "hasPreviousPage": true,
    "isFirstPage": false,
    "isLastPage": false,
    "lastPage": 13,
    "list": [{},{}],
    "navigateFirstPage": 6,
    "navigateLastPage": 13,
    "navigatePages": 8,
    "navigatepageNums": [6, 7, 8, 9, 10, 11, 12, 13],
    "nextPage": 11,
    "pageNum": 10,
    "pageSize": 10,
    "pages": 189,
    "prePage": 9,
    "size": 10,
    "startRow": 91,
    "total": 1884
    },
    "status": 1,
    "msg": "ok"
    }

  • 相关阅读:
    java封装
    本人的其他博客
    codeforces 1000C
    1005E1 Median on Segments (Permutations Edition) 【思维+无序数组求中位数】
    1009E Intercity Travelling 【数学期望】
    codeforces 1009D Relatively Prime Graph【欧拉函数】
    1077E Thematic Contests 【二分答案】
    codeforces 1077D Cutting Out 【二分】
    【非原创】ZOJ
    数字千万别用puts!
  • 原文地址:https://www.cnblogs.com/foreverstudy/p/10436300.html
Copyright © 2011-2022 走看看