014 取派员分页查询 - bos
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了014 取派员分页查询 - bos相关的知识,希望对你有一定的参考价值。
一、页面调整
1.修改staff.jsp中的表格的获取datagrid数据的url为staffAction_pageQuery.action
二、封装PageBean工具类
public class PageBean<T> {
private int currentPage;
private int pageSize;
private DetachedCriteria detachedCriteria;
private int total;
private List<T> rows;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public DetachedCriteria getDetachedCriteria() {
return detachedCriteria;
}
public void setDetachedCriteria(DetachedCriteria detachedCriteria) {
this.detachedCriteria = detachedCriteria;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}
三、服务端实现
1.编写StaffAction.pageQuery
/**
* 分页查询取派员
* @return
*/
public String pageQuery(){
PageBean<Staff> pageBean = new PageBean<Staff>();
pageBean.setCurrentPage(page);
pageBean.setPageSize(rows);
DetachedCriteria dc = DetachedCriteria.forClass(Staff.class);
pageBean.setDetachedCriteria(dc);
staffService.pageQuery(pageBean);
//将pageBean转为json写到页面中
JsonConfig jsonConfig = new JsonConfig();
//设置排除属性
jsonConfig.setExcludes(new String[]{"currentPage", "detachedCriteria", "pageSize"});
String json = JSONObject.fromObject(pageBean, jsonConfig).toString();
System.out.println(json);
ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
BOSUtils.getWriter().write(json);
return NONE;
}
2.编写StaffService.pageQuery
@Override
public void pageQuery(PageBean<Staff> pageBean) {
staffDao.pageQuery(pageBean);
}
3.在BaseDao抽取通用的分页查询方法,并在BaseDaoImpl中实现
@Override
@SuppressWarnings("unchecked")
public void pageQuery(PageBean<T> pageBean) {
int currentPage = pageBean.getCurrentPage();
int pageSize = pageBean.getPageSize();
DetachedCriteria detachedCriteria = pageBean.getDetachedCriteria();
//指定Hibernate框架发出sql的形式 - 查询记录总数
detachedCriteria.setProjection(Projections.rowCount());
List<Long> countList = (List<Long>) getHibernateTemplate().findByCriteria(detachedCriteria);
Long count = countList.get(0);
pageBean.setTotal(count.intValue());
//清空指定的查询记录数,以进行分页查询
detachedCriteria.setProjection(null);
int firstResult = (currentPage-1)*pageSize;
int maxResults = pageSize;
List<T> rows = (List<T>) getHibernateTemplate().findByCriteria(detachedCriteria,firstResult,maxResults);
pageBean.setRows(rows);
}
以上是关于014 取派员分页查询 - bos的主要内容,如果未能解决你的问题,请参考以下文章
bos 第5天(定区的添加定区的分页查询hessian远程调用实现获取客户信息)
JAVAEE——BOS物流项目04:学习计划datagrid分页查询批量删除修改功能
bos 第3天(easyui弹窗边界问题取派员的添加修改和批量删除)