首页 > 编程语言 > 详细

webService客户端 (spring MVC实现)

时间:2015-06-15 16:35:13      阅读:254      评论:0      收藏:0      [点我收藏+]

获得

即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="http://localhost:8080/WebService/student";
		Student student=client.getForObject(url, Student.class);
		System.out.println(student.getName());
	}

}
//xiaoMing


webService客户端 (spring MVC实现)

原文:http://blog.csdn.net/chuchus/article/details/46503505

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!