服务端方法如下:
@RequestMapping(value = "/getUserPage",method = RequestMethod.POST)
@ResponseBody
public User getUserPage(@RequestBody Map<String, Object> searchParams) {
// 调用JSR303 Bean Validator进行校验, 异常将由RestExceptionHandler统一处理.
List<User> list=new ArrayList<User>();
// URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
// HttpHeaders headers = new HttpHeaders();
// headers.setLocation(uri);
User user=new User();
user.setLoginName("admin");
user.setName("管理员");
list.add(user);
return user;
}
客户端如下:
public static void main(String[] args) {
RestTemplate restTemplate = new RestTemplate();
baseUrl="http://localhost:8080/JUP";
String resoureUrl = baseUrl + "/rest/getUserPage";
System.out.println(resoureUrl);
Map<String, Object> searchParams =new HashMap<String,Object>();
searchParams.put("id", "12456");
//URI userUri = restTemplate.postForLocation(resoureUrl, searchParams);
User user=restTemplate.postForObject(resoureUrl, searchParams, User.class);
System.out.println("----------------------------");
}