收集我見過很多類似地雷的問題,但是我無法找到一個解決這個問題爲止。春:綁定在控制器參數
我實現對Spring + Hibernate的網格過濾和分頁。方法load()
必須接收用於分頁的特定參數(page
,start
和limit
)和關鍵值參數列表,這是問題所在。
的參數來這樣的:
page:1
start:0
limit:23
filter:[{"operator":"like","value":"tes","property":"desc"},{"operator":"like","value":"teste","property":"model_desc"}]
或(編碼版本):
page=1&start=0&limit=23&filter=%5B%7B%22operator%22%3A%22like%22%2C%22value%22%3A%22tes%22%2C%22property%22%3A%22desc%22%7D%2C%7B%22operator%22%3A%22like%22%2C%22value%22%3A%22teste%22%2C%22property%22%3A%22model_desc%22%7D%5D
濾波器參數來作爲一String
,問題是使彈簧解析或者作爲例如ArrayList<Map<String,String>>
或ArrayList<SomeFilterClass>
。
這是我的控制器方法的簽名(註釋行都沒有工作,他們在這裏只是爲了展示一下我試過到目前爲止):
public Map<String, Object> loadData(@RequestParam(value = "page", required = true) int page,
@RequestParam(value = "start", required = true) int start,
@RequestParam(value = "limit", required = true) int limit,
// @ModelAttribute("filter") ArrayList<Map<String, String>> filter) {
// @RequestParam(value = "filter", required = false) Map<String, Object>[] filter) {
// @RequestParam(value = "filter", required = false) List<Map<String, String>> filter) {
@ModelAttribute("filter") RemoteFilter filter)
這個類,RemoteFilter
,是我構建的包裝類,遵循其他帖子的建議,但它並沒有工作。其結構是:
public class RemoteFilter {
private ArrayList<Filter> filter;
//Getters and Setters....
class Filter {
private String operator;
private String value;
private String property;
//Getters and Setters....
}
}
如果有人幫助我,我將非常高興。
謝謝!
這聽起來像你是通過Ajax調用控制器,有沒有你使用GET任何原因(並有URL編碼JSON),而不是ofPOSTing和使用Spring @RequestBody到JSON轉換成Java對象? –