首先是dataobject,项目是用的是SpringMVC
public class MbChannelExtensionDO { private static final long serialVersionUID = 741231858441822688L; //========== properties ========== /** * This property corresponds to db column ID. */ private String id; /** * This property corresponds to db column BANK_NAME. */ private String bankName; /** * This property corresponds to db column PRODUCT_TYPE. */ private String productType; /** * This property corresponds to db column EXCHANGE_TYPE. */ private String exchangeType; /** * This property corresponds to db column SIGN_VERIFY_ELE. */ private String signVerifyEle; /** * This property corresponds to db column CHANNEL_ID. */ private String channelId; /** * This property corresponds to db column GMT_CREATE. */ private Date gmtCreate; /** * This property corresponds to db column CREATOR. */ private String creator; /** * This property corresponds to db column GMT_MODIFIED. */ private Date gmtModified; /** * This property corresponds to db column UPDATOR. */ private String updator; /** * This property corresponds to db column STATUS. */ private String status; //========== getters and setters ========== /** * Getter method for property id. * * @return property value of id */ public String getId() { return id; } /** * Setter method for property id. * * @param id value to be assigned to property id */ public void setId(String id) { this.id = id; } /** * Getter method for property BANK_NAME. * * @return property value of bankName */ public String getBankName() { return bankName; } /** * Setter method for property BANK_NAME. * * @param bankName value to be assigned to property bankName */ public void setBankName(String bankName) { this.bankName = bankName; } /** * Getter method for property PRODUCT_TYPE. * * @return property value of productTYPE */ public String getProductType() { return productType; } /** * Setter method for property PRODUCT_TYPE. * * @param productType value to be assigned to property productType */ public void setProductType(String productType) { this.productType = productType; } /** * Getter method for property SIGN_VERIFY_ELE. * * @return property value of signVerifyEle */ public String getSignVerifyEle() { return signVerifyEle; } /** * Setter method for property SIGN_VERIFY_ELE. * * @param signVerifyEle value to be assigned to property signVerifyEle */ public void setSignVerifyEle(String signVerifyEle) { this.signVerifyEle = signVerifyEle; } /** * Getter method for property EXCHANGE_TYPE. * * @return property value of signVerifyEle */ public String getExchangeType() { return exchangeType; } /** * Setter method for property EXCHANGE_TYPE. * * @param exchangeType value to be assigned to property exchangeType */ public void setExchangeType(String exchangeType ) { this.exchangeType = exchangeType;} /** * Getter method for property channelId. * * @return property value of channelId */ public String getChannelId() { return channelId; } /** * Setter method for property channelId. * * @param channelId value to be assigned to property channelId */ public void setChannelId(String channelId) { this.channelId = channelId; } /** * Getter method for property gmtCreate. * * @return property value of gmtCreate */ public Date getGmtCreate() { return gmtCreate; } /** * Setter method for property gmtCreate. * * @param gmtCreate value to be assigned to property gmtCreate */ public void setGmtCreate(Date gmtCreate) { this.gmtCreate = gmtCreate; } /** * Getter method for property creator. * * @return property value of creator */ public String getCreator() { return creator; } /** * Setter method for property creator. * * @param creator value to be assigned to property creator */ public void setCreator(String creator) { this.creator = creator; } /** * Getter method for property gmtModified. * * @return property value of gmtModified */ public Date getGmtModified() { return gmtModified; } /** * Setter method for property gmtModified. * * @param gmtModified value to be assigned to property gmtModified */ public void setGmtModified(Date gmtModified) { this.gmtModified = gmtModified; } /** * Getter method for property updator. * * @return property value of updator */ public String getUpdator() { return updator; } /** * Setter method for property updator. * * @param updator value to be assigned to property updator */ public void setUpdator(String updator) { this.updator = updator; } /** * Getter method for property status. * * @return property value of status */ public String getStatus() { return status; } /** * Setter method for property status. * * @param status value to be assigned to property status */ public void setStatus(String status) { this.status = status; }接着是使用分页的Page类
public class PageDO { /** * 总条数 */ private int totalNumber; /** * 当前第几页 */ private int currentPage; /** * 总页数 */ private int totalPage; /** * 每页显示条数 */ private int pageNumber = 10; /** * 依据当前对象中属性值计算并设置相关属性值 */ public void count() { // 计算总页数 int totalPageTemp = this.totalNumber / this.pageNumber; int plus = (this.totalNumber % this.pageNumber) == 0 ?
0 : 1; totalPageTemp = totalPageTemp + plus; if(totalPageTemp <= 0) { totalPageTemp = 1; } this.totalPage = totalPageTemp; // 设置当前页数 // 总页数小于当前页数,应将当前页数设置为总页数 if(this.totalPage < this.currentPage) { this.currentPage = this.totalPage; } // 当前页数小于1设置为1 if(this.currentPage < 1) { this.currentPage = 1; } } public int getTotalNumber() { return totalNumber; } public void setTotalNumber(int totalNumber) { this.totalNumber = totalNumber; this.count(); } public int getCurrentPage() { return currentPage; } public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public int getTotalPage() { return totalPage; } public void setTotalPage(int totalPage) { this.totalPage = totalPage; } public int getPageNumber() { return pageNumber; } public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; this.count(); } }
DAO层实现分页的两个方法/** * select MbChannelExtensionDO object by page to DB table MB_CHANNEL_EXTENSION, return primary key * *下面是mybatis的mapping文件* The sql statement for this operation is
* select * from MB_CHANNEL_EXTENSION where id not in(select id from MB_CHANNEL_EXTENSION * where rownum<=(PAGESIZE*(CURRENTPAGE-1))) and rownum<=PAGESIZE order by id; * * @param page,mbChannelExtension * @return List* @throws DataAccessException */ @Override public List getMbChannelExtensionByPage(MbChannelExtensionDO mbChannelExtensionDO,PageDO page) throws DataAccessException { if (page == null) { throw new IllegalArgumentException("Can't select by a null page."); } Map map=new HashMap(); map.put("page",page); map.put("mbChannelExtension",mbChannelExtensionDO); return getSqlMapClientTemplate().queryForList("MS-MB-CHANNEL-EXTENSION-SELECT-BY-PAGE", map); } @Override public int countOfMbChannelExtension(MbChannelExtensionDO mbChannelExtensionDO ) throws DataAccessException { int count=(Integer)getSqlMapClientTemplate().queryForObject("MS-MB-CHANNEL-EXTENSION-COUNT",mbChannelExtensionDO); return count; }
下面是controller层
@RequestMapping("/channlExtension") public String selectCustomer(MbChannelExtensionDO customer,PageDO page, HttpServletRequest request) { if(page==null){ page=new PageDO(); page.setPageNumber(1); page.count(); } MbChannelExtensionDO channelExtension = new MbChannelExtensionDO(); channelExtension = customer; page.setTotalNumber(channelExtensionService.countOfMbChannelExtension(customer)); this.tcustomerList = this.channelExtensionService.getMbChannelExtensionByPage(customer,page); request.setAttribute("tcustomerList", tcustomerList); request.setAttribute("page",page); request.setAttribute("channelExtension",channelExtension); return "/channlExtension/channlExtension"; }前端html和js