加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webService客户端 (spring MVC实现)

发布时间:2020-12-16 22:47:04 所属栏目:安全 来源:网络整理
导读:获得 即springMVC。 dependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactIdversion4.0.6.RELEASE/version/dependency RestTemplate org.springframework.web.client. RestTemplate springMVC的RestTemplate类简化了对webService

获得

即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,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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读