Hibernate中用纯SQL查询,并通过hibernate分页返回List<对象>
@SuppressWarnings("unchecked")public List<Article> getPageQueryList(final int pageNo, final int pageSize){return getHibernateTemplate().executeFind(new HibernateCallback(){@Overridepublic Object doInHibernate(Session session)throws HibernateException, SQLException {//addEntity建立于实体Bean的映射关系Query query = session.createSQLQuery("SELECT [ID],[TITLE],[KEYWORD],[CONTENT] FROM [dbo].[ARTICLE] WHERE FLAG=1").addEntity(Article.class);query.setFirstResult((pageNo - 1) * pageSize).setMaxResults(pageSize);return query.list();}});}
?
?必须注意的是Article对象的每个字段必须映射相应的ARTICLE表中的字段名