Spring中@RestController和@GetMappi

2017-08-08  本文已影响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.

上一篇下一篇

猜你喜欢

热点阅读