枝
我正在使用GAE jdoql并编写了如下查询:
Query query = pm.newQuery(BloodDonor.class);
query.setFilter(" state == :stateName && district == :distName &&" +
" city == :cityName && bloodGroup == :blood");
@SuppressWarnings("unchecked")
List<BloodDonor> donors = (List<BloodDonor>) query.execute(state.toLowerCase(), district.toLowerCase(),
city.toLowerCase(), bloodGroup.toLowerCase());
这不起作用,因为执行方法不支持3个以上的参数。那么如何传递3个以上
答案 0 :(得分:1)
根据the documentation,您可以多次调用addFilter
方法添加多个过滤器:
Query query = pm.newQuery("BloodDonor");
query.addFilter("state", Query.FilterOperator.EQUAL, state.toLowerCase());
query.addFilter("district", Query.FilterOperator.EQUAL, city.toLowerCase());
query.addFilter("bloodGroup", Query.FilterOperator.EQUAL, bloodGroup.toLowerCase());
PreparedQuery pq = datastore.prepare(q);
for (Entity result : pq.asIterable()) {
// Do stuff
}
答案 1 :(得分:0)