我有一个应用程序与一些用户下拉列表。我想在服务器端基于其他一些select值执行下拉筛选。
这些列是: brand,version,platform,device,date
我要执行的查询是:
select distinct brand,device,version where platform="this" and date="that"
所选的下拉值作为 get
参数以执行此查询。我正在使用 Hibernate Criteria
以及 Projections
但没有达到预期的效果。
这是我的密码:
public List<String> filterDropDowns(String platform, String device, String date, String brand,
String version) {
Criteria crit = entityManager.unwrap(Session.class).createCriteria(Lab.class);
if (platform == null) {
crit.setProjection(Projections.distinct(Projections.property("platform")));
} else {
crit.setProjection(Projections.property("platform"));
}
if (device == null) {
crit.setProjection(Projections.distinct(Projections.property("device")));
} else {
crit.setProjection(Projections.property("device"));
}
if (date == null) {
crit.setProjection(Projections.distinct(Projections.property("date")));
} else {
crit.setProjection(Projections.property("date"));
}
if (brand == null) {
crit.setProjection(Projections.distinct(Projections.property("brand")));
} else {
crit.setProjection(Projections.property("brand"));
}
if (version == null) {
crit.setProjection(Projections.distinct(Projections.property("version")));
} else {
crit.setProjection(Projections.property("version"));
}
List<String> list = crit.list();
return list;
}
我这样称呼它:
@RequestMapping(value = "/filter", method = RequestMethod.GET)
public List<String> filterDropDowns(@RequestParam(value="platform", required=false) String platform,
@RequestParam(value="device", required=false) String device,
@RequestParam(value="date", required=false) String dateOfVideo,
@RequestParam(value="brand", required=false) String brand,
@RequestParam(value="version", required=false) String version){
return dropdownService.filterDropDowns(platform,device,date,brand,version);
}
得到的结果是我设置的最后一个标准,即不同的版本。
如何达到预期的效果。
暂无答案!
目前还没有任何答案,快来回答吧!