@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<>();