美文网首页
Spring中@RestController和@GetMappi

Spring中@RestController和@GetMappi

作者: 江小石 | 来源:发表于2017-08-08 09:44 被阅读0次
  1. Controller, RestController的共同点
    都是用来表示spring某个类的是否可以接收HTTP请求
  2. Controller, RestController的不同点
    @Controller标识一个Spring类是Spring MVC controller处理器
    @RestController: a convenience annotation that does nothing more than adding the@Controller and@ResponseBodyannotations。
    总结:@RestController是@Controller和@ResponseBody的结合体,两个标注合并起来的作用。

Spring4.3中引进了{@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping},来帮助简化常用的HTTP方法的映射,并更好地表达被注解方法的语义。
以@GetMapping为例,Spring官方文档说:
@GetMapping是一个组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写。该注解将HTTP Get 映射到 特定的处理方法上。
Difference between @GetMapping & @RequestMapping:
@GetMapping does not support the consumes attribute of @RequestMapping.

相关文章

网友评论

      本文标题:Spring中@RestController和@GetMappi

      本文链接:https://www.haomeiwen.com/subject/skzzlxtx.html