获得
即springMVC。
<dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>4.0.6.RELEASE</version></dependency>
RestTemplate
org.springframework.web.client.RestTemplate
springMVC的RestTemplate类简化了对webService的调用过程,使用起来非常简便。
<T> T org.springframework.web.client.RestTemplate.getForObject(String url, Class<T> responseType, Object… urlVariables) throws RestClientException根据指定的url,,以get请求获取数据并转换为指定类型的对象。<T> T org.springframework.web.client.RestTemplate.postForObject(String url, Object request, Class<T> responseType, Object… uriVariables) throws RestClientException根据指定的url,以post请求获取数据并转换为指定类型的对象。
示例
package com.likeyichu.webservice.client;import org.springframework.web.client.RestTemplate;import com.likeyichu.webservice.resource.Student;public class MyClient {public static void main(String[] args) {RestTemplate client=new RestTemplate();String url=":8080/WebService/student";Student student=client.getForObject(url, Student.class);System.out.println(student.getName());}}//xiaoMing
旁观者的姓名永远爬不到比赛的计分板上。