下面這段代碼是錯的,我想知道怎麼去約束HibernateCallback<>泛型裡的值,或者告訴我另外一種方法(需要分頁查詢)
public List selectBookByPrice(final int pageNo,final int pageNum) {
List list = null;
HibernateCallback> callback = new HibernateCallback>() {
List list = null;
@Override
public List doInHibernate(Session session) throws HibernateException {
//當前頁碼初始下標
int minResult = (pageNo-1)*pageNum;
String hql = "from Book order by bookPrice";
//分頁查詢
Query q = session.createQuery(hql);
q.setFirstResult(minResult);
q.setMaxResults(pageNum);
list = q.list();
return list;
}
};
list=this.getHibernateTemplate().execute(callback);
return list;
}
我後來查了下,泛型裡面需要什麼就約束什麼值便可,比如是‘List<對象>’,就約束成HibernateCallBack>便可