requestmapping和getmapping区别

Z, ZLW 996

requestmapping和getmapping区别:@RequestMapping可以指定GET、POST请求方式;@GetMapping等价于@RequestMapping的GET请求方式。@RequestMapping是一个无方法的注解。@GetMapping是组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写。

区别

@RequestMapping是一个无方法的注解。@GetMapping是组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写。

GET、POST是方法的映射,表示为
@RequestMapping(method = RequestMethod.${方法})

在一开始的映射是使用@RequestMapping(method = RequestMethod.${方法})来表示。后来Spring4.3中引进了@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping注解来帮助简化常用的HTTP方法的映射。

1、@GetMapping用于将HTTP get请求映射到特定处理程序的方法注解

具体来说,@GetMapping是一个组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写。

2、@PostMapping用于将HTTP post请求映射到特定处理程序的方法注解

具体来说,@PostMapping是一个组合注解,是@RequestMapping(method = RequestMethod.POST)的缩写

检验第一个使用的是GetMapping,第二个使用的是@RequestMapping:

@GetMapping("/getRule")public Rule getRule(){        Rule rule=new Rule(" @GetMapping","404");return rule;    }@RequestMapping(method = RequestMethod.GET  ,value = "/getRule2")public Rule getRule2(){        Rule rule=new Rule("@RequestMapping(method = RequestMethod.GET ","404");return rule;    }

回复

我来回复
  • 暂无回复内容

注册PingCode 在线客服
站长微信
站长微信
电话联系

400-800-1024

工作日9:30-21:00在线

分享本页
返回顶部