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语句进行拼接,多条件模糊查询。
@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语句进行拼接,多条件模糊查询。
相关文章推荐
- Hibernate模糊查询之多条件任意组合查询
- 使用HQL语句方式实现多表多条件组合模糊查询
- 利用hibernate实现多条件组合查询的两种方式(2017年5月18日22:45:09)
- ASP下实现多条件模糊查询SQL语句
- 实现多条件模糊查询SQL语句
- ContentResolver.query的参数问题 按条件实现模糊查询
- OpenJweb 1.6中自定义组合查询条件的实现方式
- OpenJweb 1.6中自定义组合查询条件的实现方式
- hibernate 多条件组合查询之sql拼接
- 蛙蛙推荐:asp中的多条件组合查询实现
- 如何进行ibatis动态多条件组合查询以及模糊查询
- hibernate(jpa)根据实体动态生成查询条件,并实现分页问题的解决方案
- OpenJweb平台中自定义组合查询条件窗口的实现方式(经典之作)
- Hibernate的多条件查询通用方法(查询条件个数不限,能进行模糊、精确2种查...
- Hibernate实现模糊查询的方法
- 组合查询(通过Criteria接口实现动态构造查询条件)
- PowerBuilder中通用组合条件查询模板的实现
- hibernate 多条件组合查询 之 sql 拼接
- hibernate 模糊查询中查询条件包含单引号的问题
- Hibernate分页的实现(支持模糊查询)