我认为你会用自定义查询最快地做到这一点(如选择示例中所示)
com.avaje.ebean.Query<Xyz> query = com.avaje.ebean.Ebean.createQuery(Xyz.class);
query.where("lower(first_name) like :first_name OR lower(last_name) like :last_name ")
.setParameter("first_name", "John".toLowerCase()+"%")
.setParameter("last_name", "Doe".toLowerCase() + "%");
List<Xyz> xyzList = query.findList();
您还可以使用编号参数进行更高级的组合,即:
List<String> sqlList = new ArrayList<>();
List<Object> paramsList = new ArrayList<>();
sqlList.add("lower(first_name) like ?");
paramsList.add("John".toLowerCase() + "%");
sqlList.add("lower(last_name) like ?");
paramsList.add("John".toLowerCase() + "%");
if (optionallyCheckTheNick) {
sqlList.add("lower(nick) like ?");
paramsList.add("johnie".toLowerCase() + "%");
}
Query<Xyz> query = Ebean.createQuery(Xyz.class);
query.where(StringUtils.join(sqlList, " OR "));
int i = 1; // first param uses index 1 NOT 0!
for (Object param : paramsList) {
query.setParameter(i, param);
i++;
}
List<Xyz> xyzList = query.findList()
只要确保你总是sqlList
成对添加paramsList
!