Files
Knowledge/0 编程/java/关于@GetMapping与@PostMapping与@RequestHeader+fc05da31-1a6d-444c-ab7b-98ffe56e9b11.md
T

43 lines
1.3 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
1.@GetMapping: 参数可以放置在 header,地址【query string】。
     (1)用来指定web端必须以GET请求方式访问。
     (2)用@GetMapping注解的方法,无论方法参数类型是常用数据类型,还是自定义引用数据类型,
        在没有使用@RequestHeader注解的情况下,参数都是拼接在地址里面去的【query string】。
     (3)使用@RequestHeader注解方法参数时,参数必须放置在请求头【header】里去。
2.@RequestHeader:指定方法的参数是从请求的请求头【header】里取的。注意: @RequestHeader只能
        注解常用数据类型【一般是string】,不能注解引用数据类型
3.@PostMapping:参数可以放置在地址栏【query string】,header,请求体里。
(1)用来指定web端必须以POST请求方式访问。
(2)@PostMapping注解方法时,web端可以从header,地址【query string】,body里向后端传递参数。
(3)在方法参数里没有指定参数被@RequestHeader,@RequestBody注解时。默认是从地址栏
取数据,同时:后台可以使用实体对象做方法形参从地址栏取参数。用@RequestHeader,
@RequestBody注解的参数分别是从请求头,请求体里取参数。