//因为不能分页,所以我们舍弃了这种方法,使用findAll2模糊查询
public List<Linkman> findAll(int begin, int pageSize, String linkman_name) {
String sql = "from Linkman where 1=1";
List<Object> prarm = new ArrayList<Object>();
//非空就执行模糊查询
if (!(null == linkman_name || "".equals(linkman_name))) {
sql += "and lkm_name=?";
prarm.add("%" + linkman_name + "%");
}
List<Linkman> list = (List<Linkman>) this.getHibernateTemplate().find(sql, prarm.toArray());
return list;
}
public List<Linkman> findAll2(int begin, int pageSize, String linkman_name) {
DetachedCriteria criteria = DetachedCriteria.forClass(Linkman.class);
//非空就执行模糊查询
if (!(null == linkman_name || "".equals(linkman_name))) {
criteria.add(Restrictions.like("lkm_name","%"+linkman_name+"%"));
}
List<Linkman> list = (List<Linkman>) this.getHibernateTemplate().findByCriteria(criteria, begin, pageSize);
return list;
}
if判断由于智商不够高只能写成这样的感觉性能有点低下