springmvc pager-taglib分页

阅读更多
实体类:
package com.adsm.common.util;

/**
 * 分页信息
 * Created by hu on 2016/1/17.
 */
public class Page {
    public final static int PAGESIZE = 2;
    private int pageSize = PAGESIZE;   // 每页条数
    private int pageCount = 4;         // 最多显示的总页数
    private int totalCount = 0;        // 总记录数

    public int getPageSize() {
        return pageSize;
    }

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

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
}


admin.jsp(显示页面)
<%@ taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager"%>



	



page.jsp(包含页面)
<%--
  Created by IntelliJ IDEA.
  User: hu
  Date: 2016/1/17
  Time: 9:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>



controller:
/**
     * 显示用户列表
     */
    @RequestMapping(value = "/userList", method = RequestMethod.GET)
    public String userList(HttpServletRequest request, HttpServletResponse response, Map map) {
        String offset = request.getParameter("pager.offset");// 相当于原来的(cpage-1)*pageSize
        if(offset == null || offset.length() == 0){
            offset = "0";
        }
        logger.info("offset:" + offset);
        SUserCore sUserCore = new SUserCore();
        sUserCore.setEnable((byte) 1);
        sUserCore.setStatus((byte) 0);
        List totalUserCores = sUserCoreService.selectList(sUserCore);

        Map pageMap = new HashMap<>();
        pageMap.put("enable", (byte) 1);
        pageMap.put("status", (byte) 0);
        pageMap.put("cpage", Integer.parseInt(offset));
        pageMap.put("pageSize", Page.PAGESIZE);
        List sUserCores = sUserCoreService.selectListForPage(pageMap);

        // 分页
        Page page = new Page();
        page.setTotalCount(totalUserCores.size());
        logger.info("page:" + JacksonJsonUtil.beanToJson(page));

        map.put("users", sUserCores);
        map.put("page", page);
        return "admin";
    }

你可能感兴趣的:(springmvc pager-taglib分页)