标签:
@RequestMapping(value = "/FeedPager.cqzk") @ResponseBody public String url_sa1(HttpServletRequest request, BootPage page) throws ServletException, IOException, RuntimeException { @SuppressWarnings("unchecked") BootPage pager = feedBackDao.getBySQLPage("select Feedback.id,Feedback.title,Feedback.content," + "Feedback.creattime,Rms_User.user_name from t_Feedback Feedback,Rms_User where Feedback.userId = Rms_User.user_id ", page, null); System.out.println((JSONArray.fromObject(pager)).getString(0).toString()); System.out.println((JSONArray.fromObject(pager)).getString(0).toString()); return (JSONArray.fromObject(pager)).getString(0).toString(); }
public BootPage getBySQLPage(String hql,BootPage pager,Map<String, Object> condition){ if (pager == null) { throw new IllegalArgumentException("分页 不能为空!"); } Query q = sessionFactory.getCurrentSession().createSQLQuery(hql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);; q.setFirstResult(pager.getOffset()); q.setMaxResults(pager.getLimit()); if(condition!=null){ Iterator<?> iter = condition.keySet().iterator(); while (iter.hasNext()) { String paramName = (String) iter.next(); Object paramValue = condition.get(paramName); q.setParameter(paramName, paramValue); } } pager.setRows(q.list()); pager.setTotal(this.countAllSQL(hql,condition)); return pager; } protected Long countAllSQL(String hql, Map<String, Object> condition) { if (hql == null) { return 0l; } String sql = " select count(*) total from ( " + hql + " ) as temp "; Query q = sessionFactory.getCurrentSession().createSQLQuery(sql); if(condition!=null){ Iterator<?> iter = condition.keySet().iterator(); while (iter.hasNext()) { String paramName = (String) iter.next(); Object paramValue = condition.get(paramName); q.setParameter(paramName, paramValue); } } return new Long(((Integer) q.uniqueResult()).intValue()); }
标签:
原文地址:http://my.oschina.net/u/2340612/blog/395307