Reputation: 23
I am having a problem where Spring is giving me RequestParams that are null, even though I believe the Http request contains the variables and is formatted properly.
Here is the bugged code.
@RequestMapping(value="/{username}/party/{partymember}",method=RequestMethod.PUT, produces="application/json", consumes="application/x-www-form-urlencoded")
public ResponseEntity<String> updatePartyMember(@PathVariable String username,
@PathVariable String partymember,
@RequestParam(value="membername", required=false) String newMemberName,
@RequestParam(value="job", required=false) String newJob)
Here is another function that works properly.
@RequestMapping(value="/{username}/party", method=RequestMethod.POST, produces="application/json", consumes="application/x-www-form-urlencoded")
public ResponseEntity<String> addPartyMember(@PathVariable String username,
@RequestParam(value="membername", required=false) String partyMemberName,
@RequestParam(value="job", required=false) String partyMemberJob)
While debugging I took a working query for the second function and changed only the url and request method and I was able to call the first function. This leads me to believe there's nothing wrong with the queries I sent to the server.
Upvotes: 2
Views: 5283
Reputation: 986
Spring handles request parameters only for GET and POST methods. If you use PUT, you have to pass data by using @RequestBody.
Upvotes: 2