@SuppressWarnings("unchecked") public List<Article> getPageQueryList(final int pageNo, final int pageSize){ return getHibernateTemplate().executeFind(new HibernateCallback(){ @Override public 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表中的字段名