webService客户端 (spring MVC实现)
获得即springMVC。 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.0.6.RELEASE</version> </dependency> RestTemplateorg.springframework.web.client.RestTemplate springMVC的RestTemplate类简化了对webService的调用过程,使用起来非常简便。 <T> T org.springframework.web.client.RestTemplate.getForObject(String url,Class<T> responseType,Object... urlVariables) throws RestClientException 示例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="http://localhost:8080/WebService/student"; Student student=client.getForObject(url,Student.class); System.out.println(student.getName()); } } //xiaoMing (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |