1
测试取值
@PostMapping(value = “test1”)
public MapiResult test1(HttpServletRequest request){
//可以用实体去接收 UserVo new HttpEntity<>(userVo,httpHeaders) 不可以获取到值
//new HttpEntity<>(map,httpHeaders); 提交可以获取到值
String ss= request.getParameter(“code”);
System.out.println(ss);
return null;
}
@PostMapping(value = “test2”)
public MapiResult test2(@RequestBody UserVo userVo){
// new HttpEntity<>(userVo,httpHeaders) 提交方式 可以获取到值
// new HttpEntity<>(map,httpHeaders); 报错 报错 Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported
System.out.println(userVo.getCode());
return null;
}
调用代码
@Override
@BackendApi(“绑定手机号”)
public String bindMobile(UserVo userVo) {
String destUrl=mps+ RestfulUrlConst.USER_ACCOUNT_BINDMOBILE;
String resp;
HttpHeaders httpHeaders =new HttpHeaders();
httpHeaders.set(“Login-Ticket”, userVo.getLoginTicket());
MultiValueMap<String, Object> map= RestTemplateUtil.proMultiValueMap(JSONObject.parseObject(JSONObject.toJSONString(userVo)));
HttpEntity<MultiValueMap<String,Object>> httpEntity = new HttpEntity<>(map,httpHeaders);
HttpEntity httpEntity22 = new HttpEntity<>(userVo,httpHeaders);
resp= restTemplate.exchange(“http://localhost:9000/api/v1/user/test”, HttpMethod.POST, new HttpEntity<>(userVo,httpHeaders), String.class).getBody();
resp= restTemplate.exchange(“http://localhost:9000/api/v1/user/test”, HttpMethod.POST, httpEntity, String.class).getBody();
LoggerUtil.logger().info(“绑定手机号,调用后台接口返回对象{}”,resp);
return resp;
}
总结:
resp= restTemplate.exchange(“http://localhost:9000/api/v1/user/test”, HttpMethod.POST, new HttpEntity<>(userVo,httpHeaders), String.class).getBody();
对应前端 接收 test2(@RequestBody UserVo userVo) 比较常用 写法简单 不用转map