[英]How to accept mulitple REST query parameters with same id in spring-mvc?
[英]How do you force Spring MVC4 REST webservices to only accept parameters in json format?
有沒有辦法強制Spring MVC4 REST Web服務接受某些格式的參數或請求? 我希望我的webservice接受JSON參數,只需將參數附加到url端點即可。 我嘗試了下面的例子,但你可以通過url傳遞一個參數,我希望他們以干凈的json格式傳遞它我如何在春天這樣做。
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> getUser(@PathVariable("id") long id) {
System.out.println("Fetching User with id " + id);
User user = userService.findById(id);
if (user == null) {
System.out.println("User with id " + id + " not found");
return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<User>(user, HttpStatus.OK);
}
@RequestMapping(...,consumes= MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/user/{id}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.