请将以下SQL查询转换为条件查询---------我有下表人物-
ID | 名称 | 代码 |
---|---|---|
1 | Tom | A |
2 | Harry | B |
3 | Tom | C |
4 | John | A |
5 | Sally | C |
6 | Tom | B |
7 | Tom | D |
您可以尝试以下代码:
ArrayList<String> values= new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
//Your creteria
Criteria cr = session.createCriteria(People.class);
//Array of conditions
List<Criterion> conditions = new ArrayList<Criterion>();
Criterion nameCr= Restrictions.eq("name", "Tom");
conditions.add(nameCr);
Criterion codeCr =Restrictions.in("code", values) ;
conditions.add(codeCr);
Conjunction conjunction = Restrictions.conjunction();
for (Criterion criterion : conditions) {
conjunction.add(criterion);
}
cr.add(conjunction);