webService客户端 (spring MVC实现)

简介: 获得 即springMVC。 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.0.6.RELEASE</version></depe

获得

即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


目录
相关文章
|
28天前
|
缓存 前端开发 Java
Spring MVC 面试题及答案整理,最新面试题
Spring MVC 面试题及答案整理,最新面试题
85 0
|
28天前
ssm(Spring+Spring mvc+mybatis)——updateDept.jsp
ssm(Spring+Spring mvc+mybatis)——updateDept.jsp
10 0
|
28天前
ssm(Spring+Spring mvc+mybatis)——showDept.jsp
ssm(Spring+Spring mvc+mybatis)——showDept.jsp
9 0
|
27天前
|
SQL JavaScript Java
springboot+springm vc+mybatis实现增删改查案例!
springboot+springm vc+mybatis实现增删改查案例!
22 0
|
27天前
|
SQL Java 数据库连接
挺详细的spring+springmvc+mybatis配置整合|含源代码
挺详细的spring+springmvc+mybatis配置整合|含源代码
34 1
|
5天前
|
数据采集 前端开发 Java
数据塑造:Spring MVC中@ModelAttribute的高级数据预处理技巧
数据塑造:Spring MVC中@ModelAttribute的高级数据预处理技巧
19 3
|
5天前
|
存储 前端开发 Java
会话锦囊:揭示Spring MVC如何巧妙使用@SessionAttributes
会话锦囊:揭示Spring MVC如何巧妙使用@SessionAttributes
12 1
|
5天前
|
前端开发 Java Spring
数据之桥:深入Spring MVC中传递数据给视图的实用指南
数据之桥:深入Spring MVC中传递数据给视图的实用指南
20 3
|
15天前
|
前端开发 安全 Java
使用Java Web框架:Spring MVC的全面指南
【4月更文挑战第3天】Spring MVC是Spring框架的一部分,用于构建高效、模块化的Web应用。它基于MVC模式,支持多种视图技术。核心概念包括DispatcherServlet(前端控制器)、HandlerMapping(请求映射)、Controller(处理请求)、ViewResolver(视图解析)和ModelAndView(模型和视图容器)。开发流程涉及配置DispatcherServlet、定义Controller、创建View、处理数据、绑定模型和异常处理。
使用Java Web框架:Spring MVC的全面指南
|
21天前
|
敏捷开发 监控 前端开发
Spring+SpringMVC+Mybatis的分布式敏捷开发系统架构
Spring+SpringMVC+Mybatis的分布式敏捷开发系统架构
50 0