in 条件已知,形式为(1,3,5,7)
执行查询(select)、修改(update)或删除(delete)操作时
sql语句:
select * from tab where tab.id in (1,3,5,7);
update tab set col = 2 where id in (1,3,5,7);
delete from tab where id in (1,3,5,7);
利用HQL的参数绑定编写以上语句
需要将in参数封装成数组或List
//参数形式
Integer[] ids = new Integer[]{1,3,5,7};
String hql = "from Tab where id in (:ids)";
Query query = getSession().createQuery();
query.setParameterList("ids",ids);
List < Tab > tabList = query.list();
setParameterList第二个参数可以为List 和 int数组