用户登录
用户注册

分享至

hibernate hql and

  • 作者: 亖呉?盀
  • 来源: 51数据库
  • 2020-09-25
括号!

首先判断要查询的name和value和mark是否empty,如果不为empty再写到HQL语句作为空则不写
(name = ? or value =? or mark =?) and ID =?
String hql="........";
ArrayList para=new ArrayList();
if(! ( isEmpty(name) && isEmpty(value) && isEmpty(mark) ) ){
//再逐个判断是否empty,哪个不是empty,写到HQL中。
//hql增加一个、参数也增加一个。
//para
}



  if(transfer.getx()!=null && !"".equal(transfer.getx()))
{
querystring+=" and x='"+transfer.getx()+"'";
}
system.out.println("querystring="+querystring);



  from Goods where id = ? and (name = ? or name is null) and (value = ? or value is null) and (mark = ? or mark is null)
这样试试... or不能连接那么多的...



  把or全部改成and吧 怎么可能or和and一起用
软件
前端设计
程序设计
Java相关