1、对Map做一次封装
/**
*header "Content-Type", "application/json;charset=UTF-8"
* @param object
* @return
*/
public static HttpEntity<?> getHeaderJsonUtf8(Object object)
{
MultiValueMap<String, String> headers=new LinkedMultiValueMap<>();
headers.add("Content-Type", "application/json;charset=UTF-8");
HttpEntity<?> bentity = new HttpEntity<>(object, headers);
return bentity;
}
2、然后直接调用即可
/*
* 注册单个用户信息*/
@RequestMapping("addUserOne")
public String addUserOne( User user){
System.out.println(user.toString());
ServiceInstance client1 = loa.choose("client1");
String url = "http://"+client1.getHost()+":"+client1.getPort()+"/addUserOne";
//将数据放入封装的Map中
String result = template.postForObject(url,getHeaderJsonUtf8(user), String.class);
if (result!=null){
return "addUser";
}
return "index";
}
版权声明:本文为boboTEl原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。