1 2 3 4 5 6 7 8 9 10 | <bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> <property name="messageConverters"> <list> <ref bean="marshallingConverter" /> <ref bean="atomConverter" /> <ref bean="jsonConverter" /> </list> </property> </bean> |
1 2 3 4 5 6 7 8 | HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_XML); HttpEntity<String> entity = new HttpEntity<String>(headers); ResponseEntity<EmployeeList> response = restTemplate.exchange( "http://localhost:8080/rest/service/emps", HttpMethod.GET, entity, EmployeeList.class); EmployeeListingemployees = response.getBody(); // handle the employees |
1 2 3 4 5 6 | Employee newEmp = new Employee(99, "guest", "guest@ibm.com"); HttpEntity<Employee> entity = new HttpEntity<Employee>(newEmp); ResponseEntity<Employee> response = restTemplate.postForEntity( "http://localhost:8080/rest/service/emp", entity, Employee.class); Employee e = response.getBody(); // handle the employee |
1 2 3 4 | Employee newEmp = new Employee(99, "guest99", "guest99@ibm.com"); HttpEntity<Employee> entity = new HttpEntity<Employee>(newEmp); restTemplate.put( "http://localhost:8080/rest/service/emp/{id}", entity, "99"); |
1 2 | restTemplate.delete( "http://localhost:8080/rest/service/emp/{id}", "99"); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |