RequestMapping、GetMapping、PostMapping的区别
背景:在学习到ssm整合后练习做项目时,不知道何时使用@RequestMapping@GetMapping和@PostMapping三个注解,所以上网查了后并做出了总结
解释:
@RequestMapping是一个无方法的注解。
@GetMapping和@PostMapping是组合注解,分别是@RequestMapping(method = RequestMethod.GET)和@RequestMapping(method = RequestMethod.POST的缩写。
GET、POST是方法的映射,表示为
@RequestMapping(method = RequestMethod.${方法})
原理剖析:
- get是从服务器上获取数据,post是向服务器传送数据。
- get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。
- post是通过HTTP post机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。
- 对于get方式,服务器端用Request.QueryString获取变量的值,对于post方式,服务器