主要代码:
@Transactional
public List<Items> queryitems(int id, String name, String city, String price) {
String hql="from Items it where 1=1";
if(id!=0)
hql=hql+" and it.id like '%"+id+"%'";
if(name!=null&& !"".equals(name))
hql=hql+" and it.name like '%"+name+"%'";
if(city!=null&& !"".equals(city))
hql=hql+" and it.city like '%"+city+"%'";
if(price!=null&& !"".equals(price))
hql=hql+" and it.price like '%"+price+"%'";
return getSession().createQuery(hql).list();
}
hql语句进行拼接,多条件模糊查询。