服务端被调用的方法接收参数如下
/**
* 查询列表
* @return
*/
@PostMapping("brand")
public Object getBrand(@RequestBody Map<String,Object> param){
log.info("查询列表,参数[{}]",param);
PageRsult<Map<String,Object>> data = brandService.findBrand(param);
return data;
}
方法1
public Object getObj(){
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE));
Map<String, Object> param = new HashMap<String, Object>();
hashMap.put("参数1", "值1");
hashMap.put("参数2", "值2");
HttpEntity<Map<String,Object>> httpEntity = new HttpEntity<>(param,httpHeaders);
Object forObject = restTemplate.postForEntity("127.0.0.1/brand",httpEntity,Object.class);
return forObject;
}
方法2
public Object getObj(){
Map<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("参数1", "值1");
hashMap.put("参数2", "值2");
Object result = restTemplate.postForObject("127.0.0.1/brand", hashMap, Object.class);
System.out.println(result);
return result;
}

本文详细介绍了如何使用 RESTful API 进行数据交互,包括两种不同的调用方法,一种是通过构建 HttpEntity 对象并使用 restTemplate 的 postForEntity 方法,另一种则是直接使用 postForObject 方法进行调用。文章还展示了服务端如何接收和处理这些请求。
2219

被折叠的 条评论
为什么被折叠?



