好比你的表主键是id,你要删除id 是 34,56,99 这样的。。数组
uid是拼好的 好比 '34','56','99' ,之前我会这样写ui
String queryString = "update Mail set dm=1 where uid in("+uid+")"; Query queryObject = sess.createSQLQuery(queryString); queryObject.executeUpdate(); tran.commit();
但其实能够这样使用setParameterList,uid 作成一个数组就能够了,不用拼的那么麻烦。spa
String queryString = "update Mail set dm=1 where uid in(:ids)"; Query queryObject = sess.createSQLQuery(queryString); queryObject.setParameterList("ids", uid); queryObject.executeUpdate(); tran.commit();
另一个须要注意,使用这个时,uid数组的长度须大于0,不然会报异常 net.sf.hibernate.exception.SQLGrammarExceptionhibernate
参考:code
http://chedsk.blog.163.com/blog/static/23581288201132353226700/blog