Announcement Announcement Module
Collapse
No announcement yet.
Using Spring RESTTeample how do I pass hashmap values for url on post? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Spring RESTTeample how do I pass hashmap values for url on post?

    Using Spring RESTTeample how do I pass hashmap values for url on post?

    I am trying to use Spring RESTTeample to post a User Object to a web service but the issue I am having is that I am putting my id into a hashMap and I dont know how to pass the hashmap into RESTTemplate to use. Can you please look at the following code and let me know.. I dont want to hard code the ID on the URL


    Code:
        Map<String, String> vars = new HashMap<String, String>();
        vars.put("id", "MMS");
        
        RestTemplate rt = new RestTemplate();
        rt.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
        rt.getMessageConverters().add(new StringHttpMessageConverter());
        
        URI uri = new URI("http://" + mRESTServer.getHost() + ":8080/springmvc-resttemplate-test/api/{id}");
        
        User u = new User();
        u.setName("Mickey Mouse");
        u.setUser("MMS");
        User returns = rt.postForObject(uri, u, User.class);
Working...
X