原文地址为:
Spring MVC中consumes 和 produces 用法
转载请注明本文地址: Spring MVC中consumes 和 produces 用法
若指定consumes为application/json,那么服务器仅处理request Content-Type为“application/json”类型的请求
@Controller
@RequestMapping(value = "/msgId", method = RequestMethod.POST, consumes="application/json")
public void addPet(@RequestBody Msg, Model model) {
// TODO
}
如下是,指定响应类型为application/json的数据
@Controller @RequestMapping(value = "/user/{userId}", method = RequestMethod.GET, produces="application/json") @ResponseBody public User getUser(@PathVariable String UserId, Model model) { // implementation omitted }
转载请注明本文地址: Spring MVC中consumes 和 produces 用法