2 breakorcontinue breakorcontinue 于 2016.02.03 14:53 提问

Hibernate分页效率问题 1C

项目中使用了公司封装的数据库操作jar,但Hibernate分页效率总是不高,怀疑底层是先查后分页的情况,底子不好 各位大神劳烦看下 是先查询后分的页吗?(请先回答此问题)
有什么优化建议没?
sqlstr 为sql语句,mapps为条件

  public Map getList(String sqlstr, Map mapps, int iPageNo, int iPageSize) throws DAOException

{
HibernateCallback callback = new HibernateCallback(this, sqlstr, mapps, iPageNo, iPageSize) { final HibernatePersistenceManager this$0;
private final String val$sqlstr;
private final Map val$mapps;
private final int val$iPageNo;
private final int val$iPageSize;

  public Object doInHibernate() throws HibernateException, SQLException { Query query = this.this$0.getHibernateTemplate().createQuery(session, 
      this.val$sqlstr);
    List list = new ArrayList();

    if ((this.val$mapps != null) && (!(this.val$mapps.isEmpty()))) {
      Iterator it = this.val$mapps.keySet().iterator();
      while (it.hasNext()) {
        String numStr = (String)it.next();
        int num = Integer.parseInt(numStr);
        query.setParameter(num, this.val$mapps.get(numStr));
      }

    }

    this.this$0.setPageNo(this.val$iPageNo);
    this.this$0.setPageSize(this.val$iPageSize);
    if ((this.val$mapps != null) && (!(this.val$mapps.isEmpty())))
      this.this$0.setQueryPage(query, this.val$mapps);
    else
      this.this$0.setQueryPage(query);

    list = query.list();

    Map map = new HashMap();

    map.put("RecTotal", this.this$0.getRecTotal());
    map.put("PageTotal", this.this$0.getPageTotal());
    map.put("List", list);

    return map;
  }

};
return ((Map)getHibernateTemplate().execute(callback));

}

1个回答

caozhy
caozhy   Ds   Rxr 2016.02.03 22:35

服务器端分页用存储过程,hibernate绑定
参考:http://www.docin.com/p-660794652.html

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!