如何在JPQL查询中使用数组列表?我想要这样的东西:
我正在通过
private static final String[] MASKS = {"30109", "30111"};
进入
public List<Account> findAccount(String[] Masks){
StringBuilder sb = new StringBuilder("from AccountTable a where SUBSTRING(a.Account,1,5) in :Masks ");
Query q = em.createQuery(sb.toString(), AccountTable.class)
.setParameter("Masks",Masks);
}
目前,错误是
Encountered array-valued parameter binding, but was expecting [java.lang.String (n/a)]; nested exception is java.lang.IllegalArgumentException: Encountered array-valued parameter binding, but was expecting [java.lang.String (n/a)]
最佳答案
阅读this site似乎可以,但是您的数组必须是Collection
,也许是这样的:
public List<Account> findAccount(String[] Masks){
StringBuilder sb = new StringBuilder("from AccountTable a where SUBSTRING(a.Account,1,5) in :Masks ");
Query q = em.createQuery(sb.toString(), AccountTable.class)
.setParameter("Masks", Arrays.asList(MASKS));
}
应该可以帮到你。