action控制层:
Map<String, String> condition = new HashMap<String, String>();
if (getStartdate() != null && !getStartdate().equals("")) {
condition.put("startdate", getStartdate());
}
if (getCustomername() != null && !getCustomername().equals("")) {
condition.put("customername", getCustomername());
}
PageBean pb = gradeservice.getAllFives(pageIndex, pageSize,condition); //带condition传到service层
service服务层:
String hql = "from aa";
StringBuffer sql = new StringBuffer(hql);
if (condition.get("startdate") != null) {
sql.append(" and DATE_FORMAT( e.startdate, '%Y' ) ='"
+ condition.get("startdate") + "'");
}
if (condition.get("customername") != null) {
sql.append(" and e.customerName= '"
+ condition.get("customername") + "'");
}
PageBean pb = gradeinfodao.findByPaginateds(sql.toString(), null,
pageIndex, pageSize);