日期:2014-05-18  浏览次数:20666 次

求一句 简单的HQL ,关于in
String hql = " from TbA as t where t.waiId in (?) and t.startTime >=? and t.endTime <=? order by t.id asc";
  waiId 是Integer类型 那么 第一个参数如何设置? 我设置成 "1,2" 只是返回 当等于 1 的结果。 2的结果没有了。

------解决方案--------------------
String hql = " from TbA as t where t.waiId in ("+"1,2"+") and t.startTime >=? and t.endTime <=? order by t.id asc"; 

楼主这样写好像可以用Collection对象,我没用过
------解决方案--------------------
楼主这样写in(?,?)不就可以了么
------解决方案--------------------
 


Java code

//把参数存入数组
 String   vals[]=new   String[]{"1","2","3"};   
    //指定参数名为ids
 String hql = " from  TbA as t where t.waiId in (:ids) and t.startTime >=? and t.endTime <=?  order by t.id asc"; 
 
 Query   query   =   session.createQuery(hql);   
 
 query.setParameters(ids,vals);

query.set.......//其它参数

return query.list();