文章目录
文章参考
- Http请求中Content-Type讲解以及在Spring MVC注解中produce和consumes配置详解
RequestMapping 注解说明
@Target({
ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Mapping public @interface RequestMapping {
String[] value() default {
}; RequestMethod[] method() default {
}; String[] params() default {
}; String[] headers() default {
}; String[] consumes() default {
}; String[] produces() default {
}; }
案例
@Controller @RequestMapping(value = "/users", method = RequestMethod.POST, consumes="application/json", produces="application/json") @ResponseBody public List<User> addUser(@RequestBody User userl) {
// implementation omitted return List<User> users; }
方法仅处理request Content-Type为“application/json”类型的请求. produces标识==>处理request请求中Accept头中包含了”application/json”的请求,同时暗示了返回的内容类型为application/json;
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231279.html原文链接:https://javaforall.net
