@GetMapping("test101")
public void test101(){
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HashMap <Object,Object>map=new HashMap();
map.put("name","dasdad");
//用HttpEntity封装整个请求报文
HttpEntity<HashMap<String, Object>> request = new HttpEntity(null, headers);
Map map1 = restTemplate.postForObject("http://localhost:8083/sys/used", request, Map.class);
System.out.println(map1.get("name"));
System.out.println(map1.get("password"));
}
@PostMapping("/used")
public Admin used(){
Admin admin=new Admin();
admin.setName("admin");
admin.setPassword("a123");
admin.setCreateTime(new Date());
admin.setStatus("0");
admin.setIsDeleted("0");
return admin;
}
restTemplate通信通过Map.class接收json格式数据
最新推荐文章于 2024-05-06 11:03:11 发布