【发布时间】:2014-06-25 14:29:52
【问题描述】:
我需要一些技术输入来解决这个问题:
我想搜索具有不同参数的合约。现在我搜索五个参数:FromDate、EndDate、Season、Name 和 Category。将来应该可以搜索参数的动态方式。所有参数都是合约域对象的值。
var contract= {fromDate:moment($('#datepickerVon').val(), 'DD-MM-YYYY').format('DD-MM-YYYY'),
endDate:moment($('#datepickerBis').val(), 'DD-MM-YYYY').format('DD-MM-YYYY'),
season:$('#season').val(),
name:$('#name').val(),
category:$('#category').val()};
$.ajax({
url:'/contract/search/',
dataType: "json",
type: "GET",
traditional : true,
contentType: "application/json",
data: contract,
success: function(data) {
}
});
我使用了这个控制器方法
@RequestMapping(value = "/search/", method = RequestMethod.GET, headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<String> getContractFromSearch(
@RequestParam Map<String, String> allRequestParams, ModelMap model) {List<Vertrag> result = Contract.findAllContractsPerParameter(
allRequestParams.get("fromDate"),
allRequestParams.get("endDate"),
Season.findSeason(allRequestParams.get("season").toUpperCase()),
Name.findName(allRequestParams.get("name").toUpperCase()),
Category.findCategory(allRequestParams.get("category").toUpperCase()));
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
return new ResponseEntity<String>(Contract.toJsonArray(result), headers,
HttpStatus.OK);
}
Season、Name、Category 是 Contract 的依赖项。因此,对于 jpa 查询,我需要每个对象的完整对象。为此,我想要一种动态的方式,而不是为所有人编写类似的代码。但我很确定还有另一种更好的解决方案。 可能可以使用合同对象(域和 json)本身以及 jpa 查询来做到这一点。
感谢您的意见。
【问题讨论】:
-
在 Spring MVC 中使用命令对象绑定
-
感谢您的意见,您能否提供更多信息。谢谢
标签: java jquery json spring jpa