Spring中@RestController和@GetMapping

  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 Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,314评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,032评论 6 342
  • Spring的模型-视图-控制器(MVC)框架是围绕一个DispatcherServlet来设计的,这个Servl...
    alexpdh阅读 7,484评论 0 3
  • 1、Spring MVC请求流程 (1)初始化:(对DispatcherServlet和ContextLoderL...
    拾壹北阅读 5,938评论 0 12
  • 翻译自Spring官方文档 4.1.2版本 相关文章: Spring参考手册 1 Spring Framework...
    liycode阅读 3,978评论 0 2