读书人

求一句 简略的HQL ,关于in

发布时间: 2011-12-19 23:23:36 作者: rapoo

求一句 简单的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(); 

读书人网 >Java Web开发

热点推荐