若指定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 用法
最新推荐文章于 2024-08-24 20:08:59 发布