How to send a send request using spring @RequestBody in a leisure client

I have a Person class.

class Person{ Integer id; String firstName; String lastName; //other params, constructors, getters & setters } 

& My method

  @RequestMapping(value = "/test", method = RequestMethod.POST) public void testPerson( @RequestBody Person person){ ... } 

Now I need to test it with the help of the rest client. I tried setting up the "request header" section of the Firefox plugin to have "name" = "Content-Type" and "value" = "application / x-www-form-urlencoded", & amp; then add parameters to the body,

 id=1&firstName=aaa&lastName=bbb 

but he gives 404.

+4
source share
1 answer

If you get a 404 response, it means your request URL is incorrect or you are using the GET method instead of POST or vice versa.

Then, with respect to passing Person in the request, if @RequestBody used, you must pass JSON or XML to the request body as playload.

JSON:

 { "id":1, "firstName":"aaa", "lastName":bbb } 

XML

 <person> <id>1<id> <firstName>aaa</firstName> <lastName>bbb</lastName> </person> 
+2
source

All Articles