在左侧的菜单页面(menu.jsp)中修改提交路径
编写web层
一般而言,我们在实现分页查询XXX列表的功能时,都会创建一个封装分页数据的实体类。这里,我们也不例外,在com.meimeixia.crm.domain包下创建一个这样子的实体类。
package com.meimeixia.crm.domain;
import java.util.List;
public class PageBean<T> {
private Integer currentPage; //当前页数
private Integer pageSize; //每页显示的记录数
private Integer totalCount; //总记录数
private Integer totalPage; //总页数
private List<T> list; //每页查询到的数据的集合,要用到泛型,也即查客户,list里面装的是客户,查联系人,list里面装的是联系人
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getTotalCount() {
return totalCount;
}
public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
}
public Integer getTotalPage() {
return totalPage;
}
public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
}
然后,我们就要在CustomerAction类中编写一个分页查询客户列表的方法了。在该方法中,需要接收分页查询的参数,这里最好使用离线条件查询对象(即DetachedCriteria对象),因为用了它之后,在我们底层Hibernate模板调用的时候,直接就可以进行分页查询了,而且后期咱们进行条件查询(条件查询还能带分页),使用DetachedCriteria这个对象就会变得非常方便。
package com.meimeixia.crm.web.action;
import org.hibernate.criterion.DetachedCriteria;
import com.meimeixia.crm.domain.Customer;
import com.meimeixia.crm.domain