displaytag按需分页的包装及实例(三)

2014-11-24 11:01:11 · 作者: · 浏览: 2
ring custcode = mv.getCustcode();
KTimestamp start = Kalendar.StringToKTimestamp("yyyy-MM-dd", mv.getStartdate());
KTimestamp end = Kalendar.StringToKTimestamp("yyyy-MM-dd", mv.getEnddate());
return posbatchDao.findByCustAndDateForPage(fromIndex,toIndex,compid,custcode,start,Kalendar.getKTimestampAfterDays(end, 1));
}
public int findFullSizeByCustAndDate(IncidentalMV mv, int compid) {
String custcode = mv.getCustcode();
KTimestamp start = Kalendar.StringToKTimestamp("yyyy-MM-dd", mv.getStartdate());
KTimestamp end = Kalendar.StringToKTimestamp("yyyy-MM-dd", mv.getEnddate());
return posbatchDao.findFullSizeByCustAndDate(compid, custcode, start, end);
}
3.3)Dao类
[java]
public List findByCustAndDateForPage(int fromIndex,int toIndex,int compid,String custcode, KTimestamp start,
KTimestamp end) {
StringBuffer buff = new StringBuffer();
buff.append("select p from Posbatch p left join fetch p.customer c left join fetch p.wicustomer w left join fetch p.createPerson cp " +
"where p.compid = and p.ctime >= and p.ctime< ");
buff.append(" order by p.batchnum desc");
return super.find(buff.toString(), fromIndex, toIndex, compid,start,end);
}
public int findFullSizeByCustAndDate(int compid,String custcode, KTimestamp start,
KTimestamp end) {
StringBuffer buff = new StringBuffer();
buff.append("select count(*) from Posbatch p " +
"where p.compid = and p.ctime >= and p.ctime< ");
buff.append(custcode!=null && !custcode.equals("") " and p.custcode = " : "");
buff.append(" order by p.batchnum desc");
return super.findFullSize(buff.toString(),compid,start,end);
}
此Dao用了Hibernate 的 left join fetch 的方式,因此直接注入Posbatch的关联对象,便于displaytag的显示。
另外,此Dao继承了自己的BaseHibernateDAO,findFullSize()以及find()方法的代码如下:
[java]
public List find(String hql ,int fromIndex,int toIndex, Object... params){
Query query = getSession().createQuery(hql);
for(int i = 0 , len = params.length ; i < len ; i++){
query.setParameter(i , params[i]);
}
query.setFirstResult(fromIndex);
query.setMaxResults(toIndex - fromIndex);
return query.list();
}
public int findFullSize(String hql,Object... params){
Query query = getSession().createQuery(hql);
for(int i = 0 , len = params.length ; i < len ; i++){
query.setParameter(i , params[i]);
}
return ((Long)query.list().get(0)).intValue();
}
3.4) 页面显示(JSP)
[ html]
requestURI="queryIncidental" decorator="com.whyonly.center.pos.mv.PosbatchWrapper"
>
此处用了一个包装器,用户显示日期。如果不需要对数据进行特殊的处理,直接忽略他。