2

Here is my spring controller code..

@RequestMapping(value= "/save_item",
method = RequestMethod.POST,produces="application/json")

public @ResponseBody ModelMap saveItem(ModelMap model,
@RequestParam("id") String itemId,
@RequestParam("name") String itemName) {

model.addAttribute("itemId",itemId);
return model;
}

How can i make a rest client using spring rest tempalte?.

I need to send two parameters from my rest client(id,name). Anyone Please help me.

Thanks.

rplg
  • 232
  • 3
  • 12
  • possible duplicate of [RestTemplate post for entity](http://stackoverflow.com/questions/12728006/resttemplate-post-for-entity) – nobeh Nov 05 '13 at 10:10
  • in that example they only send a request using restTemplate.postForObject.i also need to specify accept header in my request.how can i possible that – rplg Nov 05 '13 at 11:30
  • refer to this question for post with accept headers http://stackoverflow.com/questions/19238715/set-accept-header-for-spring-rest-template. – coder Nov 05 '13 at 12:25
  • it does not wok for me..can u give an example for it? – rplg Nov 05 '13 at 12:33
  • Anyone please tell me how can i do this? – rplg Nov 13 '13 at 06:30

1 Answers1

0

You can create a RestTemplate object and execute as this

ResponseEntity<List<City>> result = restTemplate.exchange(
                new StringBuilder(URL).append(city).toString(),
                HttpMethod.GET, null, responseType);

In this project you can find a maven project with spring-boot and sptring-web that uses this restTemplate snippet and jackson for the json response

https://github.com/voliveirajr/dev-test