1
2
3
4
5
6
7
8
9
|
@RequestMapping (value= "buildRestUser" ) public FavUser buildRestUser(){ FavUser favUser = new FavUser(); favUser.setUserId( "mm" ); favUser.setUserName( "美眉" ); favUser.setUserAge( 18 ); favUser.setCreateDate( new Date()); return favUser; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package com.favccxx.favsoft.main; import org.springframework.web.client.RestTemplate; import com.favccxx.favsoft.pojo.FavUser; public class ConsumeSpringRestful { public static void main(String[] args) { RestTemplate restTemplate = new RestTemplate(); FavUser favUser = restTemplate.getForObject( "http://localhost:8080/favspringmvcrestful/buildRestUser" , FavUser. class ); System.out.println( "userId: " + favUser.getUserId()); System.out.println( "userName: " + favUser.getUserName()); System.out.println( "userAge: " + favUser.getUserAge()); System.out.println( "createDate: " + favUser.getCreateDate()); } } |
使用Spring RestTemplate解析RESTful服务
原文地址:http://blog.csdn.net/dyllove98/article/details/41284675