web123456

springboot receives requests of application/x-www-form-urlencoded type

Request data

id:1
roleName:admin
roleDes: Have admin permissions

Several ways to deal with Controller

  1. The first type
@ApiOperation("Query User")
     @PostMapping("/detailByParam")
     public void detailByParam(@RequestParam (value = "id") Integer id,@RequestParam(value = "roleName") String roleName,@RequestParam(value = "roleDes") String roleDes) {
    	 (">>>,roleName="+roleName+",roleDes="+roleDes);
	 }
  • 1
  • 2
  • 3
  • 4
  • 5

Print information: >>>id=1,roleName=admin,roleDes=Have admin permission

  1. The second type
@ApiOperation("Query User")
     @PostMapping("/detailByParam")
     public void detailByParam(@RequestParam Map<String, String> params) {
         (">>>id")+",roleName="+("roleName")+",roleDes="+("roleDes"));
     }
  • 1
  • 2
  • 3
  • 4
  • 5

Print information: >>>id=1,roleName=admin,roleDes=Have admin permission

  1. The third type
@ApiOperation("Query User")
     @PostMapping("/detailByParam")
     public void detailByParam(@RequestBody String params) {
         (">>>"+params);
     }
  • 1
  • 2
  • 3
  • 4
  • 5

Print information: >>>id=1&roleName=admin&roleDes=%E6%8B%A5%E6%9C%89admin%E6%9D%83%E9%99%90

  1. The fourth type
@ApiOperation("Query User")
     @PostMapping("/detailByParam")
     public void detailByParam(@RequestBody GetRoleParam getRoleParam) {
         (">>>"+getRoleParam);
     }
  • 1
  • 2
  • 3
  • 4
  • 5

Returns the error message: "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported".