- Java code
public class Test { public static void main(String[] args) { ClazzDao cd = new ClazzDaoImpl(); String hqlQuery = "from Clazz"; String hqlCount = "select count(*) from Clazz"; PageModel<Clazz> pageModel = cd.get(hqlQuery, hqlCount, 1, 10); for (Clazz c : pageModel.getList()) { System.out.println("班级名称"+c.getName()); } System.out.println("总记录:" + pageModel.getTotalRecords()); System.out.println("总页数:" + pageModel.getTotalPages()); System.out.println("第一页:" + pageModel.getTopPageNo()); System.out.println("前一页:" + pageModel.getPreviousPageNo()); System.out.println("下一页:" + pageModel.getNextPageNo()); System.out.println("最后一页:" + pageModel.getBottomPageNo()); } }package com.aftvc.dao.impl;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import javax.annotation.Resource;import org.hibernate.HibernateException;import org.hibernate.Query;import org.hibernate.Session;import org.springframework.orm.hibernate3.HibernateCallback;import org.springframework.orm.hibernate3.HibernateTemplate;import org.springframework.stereotype.Component;import com.aftvc.dao.ClazzDao;import com.aftvc.model.Clazz;import com.aftvc.util.PageModel;import com.aftvc.vo.ClazzInfo;@Component("clazzDao")public class ClazzDaoImpl implements ClazzDao { private HibernateTemplate hibernateTemplate; public HibernateTemplate getHibernateTemplate() { return hibernateTemplate; } @Resource public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { this.hibernateTemplate = hibernateTemplate; } @SuppressWarnings("unchecked") public PageModel<Clazz> get(final String hqlQuery, final String hqlCount, final int pageNo, final int pageSize) { List<Clazz> clazzs = hibernateTemplate .executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(hqlQuery) .setFirstResult((pageNo - 1) * pageSize) .setMaxResults(pageSize); return query.list(); } }); int totalRecords = getCount(hqlCount); PageModel<Clazz> pageModel = new PageModel<Clazz>(totalRecords, pageNo, pageSize, clazzs); return pageModel; } @SuppressWarnings("unchecked") private int getCount(String hql) { List<Long> count = (List<Long>) hibernateTemplate.find(hql); if (count != null && count.size() > 0) return ((Long) count.get(0)).intValue(); return 0; }}
请各位 帮忙看看是 怎么回事 !
------解决方案--------------------
你把报错贴出来。 代码没看,估计问题出在资源文件的加载。