我有一个应用程序,为用户提供了一些下拉菜单。我想在一些其他选择值的基础上执行下拉过滤器服务器端。
列是: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);
}
我得到的结果是我设定的最后一个标准,即不同的版本。
如何达到预期效果。