Criteria criteria = session.createCriteria(objectName.class);
criteria.add(Expression.like("attributeName", "%aaa%");
criteria.list();
String name = aaa;
Date begintime;
Date endtime;
String hql = "from table t where 1=1 ";
wherehql = "";
if(name!=null && !name.equals("")){
wherehql+ = "and t.name like '%" + name + "%'";
}else if(begintime!=null||endtime!=null && !begintime.equals("")||endtime.equals("")){
wherehql+ = "and t.begintime >什么 and t.endtime < 什么";
}
getHibernateTemplate().find(hql+wherehql, null);
public List queryAllByLike(String condition)
{
List l=null;
String hql="from t_user as p where p.name like ?";
Query q=this.session.createQuery(hql);
//把参数设置
condition="%"+condition+"%";
q.setString(0,condition);
//执行查询
l=q.list();
this.session.close();
return l;
}