我用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);
用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);
求救,要疯掉了!
Qyouu
人到中年有点甜
慕运维8079593
相关分类