有没有办法强制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);
}
答案 0 :(得分:2)
@RequestMapping(...,consumes= MediaType.APPLICATION_JSON_VALUE)
答案 1 :(得分:1)
<select name="arrangement" id="arrangement">
[[!getArrangementOptions]]
</select>