</pre><pre name="code" class="java">
public List<UnitGroup> getUnitGroupByUnitId(Integer unitId,String productId) throws Exception { String hql = "select o1.id from TableName o1 where o1.pId in (:pids)"; Session session = getHibernateSession(); Query query = session.createQuery(hql.toString()); if(productId.contains(",")){ String[] proIds = productId.split(","); Object[] productIds = new Object[proIds.length]; for(int i = 0 ; i < proIds.length ; i ++){ productIds[i] = Integer.parseInt(proIds[i]); } query.setParameterList("pids",productIds); } return query.list(); }
in括号里边的值写成一个变量,下边用
query.setParameterList();
一共两个参数,第一个参数就是in括号里边的参数 :pids,第二个参数就是Object[]数组
所以写成:
query.setParameterList("pids",productIds);