日期:2014-05-16  浏览次数:20627 次

hibernate 和 MySql in的参数变量

Mysql :

?

select appid  from mem_apps where appid in (?)

如果?=25,3 那么此语句的结果只有一条,形如下面的语句:

select appid  from mem_apps where appid in ('25,3')

要得到多条记录 ,可以采用下面的写法:

select appid  from mem_apps where INSTR(CONCAT(',',?,','),CONCAT(',',appid,','))>0

类似于

select appid  from mem_apps where appid in ('25','3')
?

String hql = "from UserObd u where u.chariotest in (:list) and u.rectime > :syntime";
Query query = super.getSession().createQuery(hql).setParameterList("list",chariotest).setDate("syntime", synTime);
return query.list();
?