我用RestTemplate想两个参数,一个是自己写的Java类,一个是基本类型请求的Controller @RequestMapping("/buy")
public int buy(@RequestBody GoodsDetail goodsDetail,Integer buyCount){
goodsDetail.setRemaining(goodsDetail.getRemaining() - buyCount);
int num = goodsDetailMapper.updateByPrimaryKey(goodsDetail);
return num;
}用getForObject: Map<String,Object> map = new HashMap<>();
map.put("goodsDetail",goodsDetail);
map.put("buyCount",buyCount);
int num = restTemplate.getForObject("http://localhost:8088/shop-buy/buy?goodsDetail={goodsDetail}&buyCount={buyCount}", int.class, map);报400 null用postForObject: MultiValueMap<String,Object> multiValueMap = new LinkedMultiValueMap<>();
multiValueMap.add("goodsDetail",goodsDetail);
multiValueMap.add("buyCount",buyCount);
int num = restTemplate.postForObject("http://localhost:8088/shop-buy/buy", multiValueMap, int.class);报415 null 求救,要疯掉了!
3 回答
Qyouu
TA贡献1786条经验 获得超11个赞
@RequestMapping("/buy/{buyCount}") public int buy(@RequestBody GoodsDetail goodsDetail,@PathParam ("buyCount") Integer buyCount){ goodsDetail.setRemaining(goodsDetail.getRemaining() - buyCount); int num = goodsDetailMapper.updateByPrimaryKey(goodsDetail); return num; }
添加回答
举报
0/150
提交
取消