日期:2014-05-19 浏览次数:20762 次
public List<Restaurant> getListSerach(String add, String rType,
int pageSize, int pageNo) {
Session session=super.getSession();
String hql="from Restaurant res where res.foodAddress like %?% and res.foodType like %?% order by newid()";
Query query=session.createQuery(hql);
query.setString(0, add);
query.setString(1, rType);
List<Restaurant> list=query.list();
return list;
}
public int getTotalSerach(String add, String rType) {
Session session=super.getSession();
String hql="select count(res.id) from Restaurant res where res.foodAddress like %"+'?'+"% and res.foodType like %"+'?'+"% ";
Query query=session.createQuery(hql);
query.setString(0, rType);
Long record=(Long) query.uniqueResult();
return record.intValue();
}
public ActionForward getListSerach(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
int pageSize=8;
int pageNo=Integer.parseInt(request.getParameter("reqPage"));
String add=new String(request.getParameter("add").getBytes("ISO-8859-1"),"UTF-8");
String rType=new String(request.getParameter("rType").getBytes("ISO-8859-1"),"UTF-8");
List<Restaurant> list=resBiz.getListSerach(add, rType, pageSize, pageNo);
int record=resBiz.getTotalSerach(add, rType);
request.setAttribute("add", add);
request.setAttribute("rType", rType);
request.setAttribute("list", list);
request.setAttribute("currentPage", pageNo);
request.setAttribute("pageSize", pageSize);
request.setAttribute("maxPage", record % pageSize == 0 ?
record/ pageSize : (record / pageSize + 1));
return mapping.findForward("viewResList");
}