我有一个人类跟着
public class Person{
String name;
//----------
}
我想查询名称如“name1”的人名单,名称如“name2”,名称如“name3”.... 所以,我想有这样的功能
public void queryPersonsWhithNameLike(List<String> names){
//here is my query
String queryStr = "select p from Person p where p.name LIKE :names.get(0) AND p.name LIKE :names.get(1) AND p.name LIKE :names.ger(2) AND......";
}
请问如何使用sql和jpql编写此类查询?
答案 0 :(得分:0)
public void queryPersonsWhithNameLike(List names){ 迭代List并构造一个查询:
String queryStr = "select p from Person p";
int count=0;
for(String str:names) {
if(count==0) queryStr+="WHERE p.name LIKE :name"+count;
else queryStr+=" AND p.name LIKE :name"+count;
count++;
}
... Initialize query
for(String str:names) {
... Set all the :name+count as parameters
}