springboot如何接收application/x-www-form-urlencoded的参数
注意事项
springboot版本2.4以上添加配置
spring.mvc.hiddenmethod.filter.enabled=true
接收方式
@RequestParam 注解接收
对应变量名一致即可
示例报文:
curl --location --request POST 'xxxxx' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'a1=1' \
--data-urlencode 'a2=2'
后端接收:
@PostMapping("test")
public void test(@RequestParam String a1,@RequestParam String a2){
}
对象的方式接收
不用加注解,直接放对象就行
示例报文:
curl --location --request POST 'xxxxx' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'passWord=1111'
后端接收:
@PostMapping("test")
public void test(AuthLoginBO authLoginBO){
}