How does springboot receive requests of type application/x-www-form-urlencoded
This article mainly introduces how springboot receives application/x-www-form-urlencoded type requests, which can be used for reference by interested friends. I hope you will gain a lot after reading this article. Let's take a look at it.
Request data
Id:1
RoleName:admin
RoleDes: with admin permission
Several processing methods of Controller
First kind
@ ApiOperation ("query user") @ PostMapping ("/ detailByParam") public void detailByParam (@ RequestParam (value = "id") Integer id,@RequestParam (value = "roleName") String roleName,@RequestParam (value = "roleDes") String roleDes) {System.out.println ("> id=" + id+ ", roleName=" + roleName+ ", roleDes=" + roleDes);}
Print information:
> id=1,roleName=admin,roleDes= has admin permission
The second kind
@ ApiOperation ("query user") @ PostMapping ("/ detailByParam") public void detailByParam (@ RequestParam Map params) {System.out.println ("> id=" + params.get ("id") + ", roleName=" + params.get ("roleName") + ", roleDes=" + params.get ("roleDes");}
Print information:
> id=1,roleName=admin,roleDes= has admin permission
The third kind
@ ApiOperation ("query user") @ PostMapping ("/ detailByParam") public void detailByParam (@ RequestBody String params) {System.out.println ("> >" + params);}
Print information:
> id=1&roleName=admin&roleDes=%E6%8B%A5%E6%9C%89admin%E6%9D%83%E9%99%90
The fourth kind
@ ApiOperation ("query user") @ PostMapping ("/ detailByParam") public void detailByParam (@ RequestBody GetRoleParam getRoleParam) {System.out.println ("> >" + getRoleParam);}
Return an error message:
"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"
SpringMVC application/x-www-form-urlencoded receiving mode test
Premise: for ease of understanding
All classes use @ Controller instead of RestController
Method uses @ RequestMapping
All postman requests are as follows
1. No comments are added before the parameter
1.1 request
Success!
1.2 map
Failure!
1.3 pojo
Success!
two。 Add @ RequestParam before the parameter
2.1 request
Failure!
2.2 map
Success!
2.3 poji
Failure!
3. Add @ RequestBody before the parameter
3.1 request
Failure!
3.2 map
Failure!
3.3 pojo
Request
Map
Pojo
No comments
√
×
√
@ RequestParam
×
√
×
@ RequestBody
×
×
×
Thank you for reading this article carefully. I hope the article "how to receive application/x-www-form-urlencoded requests from springboot" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!