@PostMapping
public ResponseResult add(User user){
HttpHeaders httpHeaders = new HttpHeaders();
MediaType type=MediaType.parseMediaType("application/json;charset=UTF-8");
httpHeaders.setContentType(type);

// MultiValueMap<String, Object> map=new LinkedMultiValueMap<>();

HashMap<String, Object> map = new HashMap<>();
map.put("userName",user.getUserName());
map.put("passWord",user.getPassWord());
HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(map,httpHeaders);
ResponseEntity<ResponseResult> responseResultResponseEntity = restTemplate.postForEntity(GLOBAL_URL, objectHttpEntity, ResponseResult.class);
return responseResultResponseEntity.getBody();


特别注意,当没有请求头信息时,用 MultiValueMap<String, Object> map=new LinkedMultiValueMap<>();
当有请求头信息时,用 HashMap<String, Object> map = new HashMap<>();

相关文章:

  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-03
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
相关资源
相似解决方案