您的位置:首页 > 其它

hibernate实现多条件组合的模糊查询

2017-03-06 20:43 375 查看
主要代码:

@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语句进行拼接,多条件模糊查询。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: