0
你好我寫一個REST控制器來一個有趣的問題春URL請求參數未發現
如果有一個控制器
@RequestMapping(value = "/test", method = RequestMethod.GET)
public ResponseEntity getAfterSalesFiles(@PathParam("store") final String store,
@PathParam("filter") final String filter,
@PathParam("sort") final Pageable pageable) {
System.out.println("filter " + filter);
System.out.println("page " + pageable.getPageNumber());
System.out.println("size " + pageable.getPageSize());
return new ResponseEntity<>(HttpStatus.OK);
}
,當我執行下面的curl命令
curl localhost:8109/product/test?page=3&size=25&filter=cookies
我在我的控制檯中獲得以下內容
filter null
page 3
size 20
所以頁面是否正確,大小和過濾器是錯誤的 如果我在url周圍交換變量,第一個參數是正確的人是錯誤的
編輯: 香港專業教育學院還試圖
@RequestMapping(value = "/test", method = RequestMethod.GET)
public ResponseEntity getAfterSalesFiles(@RequestParam(value = "store") final String store,
@RequestParam(value = "filter") final String filter,
@RequestParam(value ="sort") final Pageable pageable) {
System.out.println("filter " + filter);
System.out.println("page " + pageable.getPageNumber());
System.out.println("size " + pageable.getPageSize());
return new ResponseEntity<>(HttpStatus.OK);
}
與捲曲
curl localhost:8109/product/test?filter=cookies&store=bavo&size=25&page=3
,然後我得到以下輸出
{"timestamp":1438087790411,"status":400,"error":"Bad Request","exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required String parameter 'store' is not present","path":"/product/test"}
任何想法在哪裏看/如何調試呢?
問候, Bakil
你是指'@ PathVariable',對吧? –
沒有,因爲我沒有編碼在URL像localhost/{大小},但作爲本地主機?大小 –
然後它是一個@ @ RequestParam? '@ PathParam'不是Spring註釋... –