Query的setParameterList(name, list)生成的语句类似: bargain.category in (值列表).以下是setParameterList的官方注释: Bind multiple values to a named query parameter, guessing the Hibernate type from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).Parameters: name the name of the parameter vals a collection of values to list
Session session=new Configuration().configure().buildSessionFactory().openSession();
Transaction tx=session.beginTransaction();
String hql="from 实体类名 l where l.类属性=:参数 ";//注意参数前有:
Query query=s.createQuery(hql);
query..setString("参数 ",参数L);
return query.list();//返回查到的list集合
}
如果还不知道的话我也没办法了。呵呵!
//给categories中添加数据.
Query q = session.createQuery("FROM Bargain");
q.setParameterList("category", categories);
List<Bargain> bargains = q.list();
bargain.category in (值列表).以下是setParameterList的官方注释:
Bind multiple values to a named query parameter, guessing the Hibernate type from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).Parameters:
name the name of the parameter
vals a collection of values to list