'example'에 해당되는 글 1건

  1. 2012.04.05 [IT] Spring RestTemplate example
2012. 4. 5. 07:40 IT

Rest Client example

- reference

http://blog.springsource.org/2009/03/27/rest-in-spring-3-resttemplate/
http://dlinsin.blogspot.com/2009/11/playing-with-spring-resttemplate.html http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/client/RestTemplate.html


import org.springframework.web.client.*;

...

@RequestMapping(value="/rest", method=RequestMethod.GET)

public String rest( Model model) throws Exception{

String url = "http://localhost/sample?email={mail}"; 

RestOperations restTemplate = new RestTemplate();

String result = restTemplate.getForObject(url, String.class, "tistory@tistory.com"); // url, responseType, urlVariable

//DELETE delete(String, String...)

//GET getForObject(String, Class, String...)

//POST postForLocation(String, Object, String...)

//PUT put(String, Object, String...)  

model.addAttribute("result",result);

// json방식으로 처리할 경우 바로 result를 return 하면 될듯..  

return "sample/RestResult";

}


posted by smplnote