//例如 UserInfo.class传到beanClass
public Pagination findPaginationObjBySql(final String sql, final int pageIndex, final int pageSize,<span style="color:#ff0000;"> final Class beanClass</span>) {
return (Pagination) hibernateTemplate.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql)<span style="color:#ff0000;">.addEntity(beanClass);;</span>
if (pageSize > 0) {
query.setFirstResult((pageIndex - 1) * pageSize);
query.setMaxResults(pageSize);
}
List items = query.list();
long rowsCount = 0;
rowsCount = getRowsCountBySqlDataSize(sql);
Pagination pagination = new Pagination(pageIndex, pageSize, rowsCount);
pagination.setItems(items);
return pagination;
}
});
}