使用查询实现的方法有两种:1、使用hql语句直接查询。2、使用createCriteria查询。 请看查询截图: 请看查询截图: 实现代码service层如下: public PageBean advanceSearchByPage(Integer pagecode, Integer pagesize, String[] name, String[] value) { List list = new ArrayList(); for(int i=0;i<name.length;i++) { if("realname".equals(name[i])) { if(!"".equals(value[i].trim())) list.add(Expression.eq("realname", value[i])); } if("banji".equals(name[i])) { if(!"".equals(value[i].trim())) { Banji banji = bdao.findByPK(Banji.class, new Integer(value[i])); list.add(Expression.eq("banji", banji)); } } if("major".equals(name[i])) { if(!"".equals(value[i].trim())) list.add(Expression.eq("major", value[i])); } } return studao.findByCriterion(Student.class, pagecode,pagesize, list); } Dao层代码如下: public PageBean findByCriterion(final Class<T> clazz, final int pagecode, final int pagesize, final List<Criterion> criteria) { return (PageBean) this.getHibernateTemplate().execute( new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { // TODO Auto-generated method stub Criteria crit = session.createCriteria(clazz).setCacheable(true); for (Criterion criterion : criteria) { crit.add(criterion); } List<T> list = crit.list(); int count = list.size(); PageBean pb = new PageBean(); pb.setAllcount(count); pb.setPagesize(pagesize); pb.setPagecode(pagecode); if (count > 0) { crit.setFirstResult((pagecode - 1) * pagesize); crit.setMaxResults(pagesize); pb.setData(crit.list()); } return pb; } }); }