看两个例子:
(1)命名参数
String hql="from student where sname=:name and sage>:age";
Query query=session.createQuery(hql);
query.setParameter("name","michael");
query.setParameter("age",new Integer(23));
List list=query.list();
(2)按参数位置
String hql="from student where sname=? and sage>?";
Query query=session.createQuery(hql);
query.setParameter(0,"michael");
query.setParameter(1,new Integer(23));
List list=query.list();