实践
@Resource
private RestTemplate template;
@PostMapping("/v1/third/add/person")
public void postAddPerson(@RequestBody Person person){
String url = "http://localhost:8081/post/string";
//final Map<String, Object> map = beanToMap(person);
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
paramMap.set("name","tom");
String respnose = template.postForObject(url, paramMap, String.class);
System.out.println(JSON.toJSONString(respnose));
}
案例
bug
如何解决component required a bean of type ‘org.springframework.web.client.RestTempla
传递类型不能强转
https://blog.csdn.net/axiang_/article/details/107513535
long time = System.currentTimeMillis();
map.put("ts", String.valueOf(time));
赋值的时间直接把 map.put("ts", System.currentTimeMillis();); 该参数就无法传递 最好的方式就是直接设value 为String 类型