ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 如何使用 1、添加依赖 ~~~ <!-- spring cloud openfeign --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> ~~~ 2、新建`MarketApi.java`服务接口 ~~~ /** * 功能说明:【营销服务功能】 * 作 者:lihaijun * 创建日期:2019-11-09 */ @FeignClient(name = "hmall-market",configuration = FeignConfiguration.class) //调用的服务名 public interface MarketApi extends BaseApi { //使用优惠券 @GetMapping("/coupon/couponUse") BaseResp couponUse(@RequestBody Long couponSelectRecordId ) ; } ~~~ 3、新建CouponController.java实现 ~~~ /** * 功能说明:【优惠券操作】 * 作 者:lihaijun * 创建日期:2018-04-04 */ @RestController @Slf4j @RequestMapping("/coupon") @Api(value= "系统营销" ,tags = "系统优惠券接口") public class CouponController extends BaseController { @Resource CouponService couponService; /** * 【使用优惠券】 */ @ApiOperation(value = "使用优惠券", notes="使用优惠券") @PostMapping(value = "couponUse") public void couponUse(@RequestBody Long selectRecordId ) { r=couponService.couponUse(selectRecordId); respMsgObj(r); } } ~~~ 4、消费者引入MarketApi 消费 couponUse方法 ~~~ @Resource MarketApi marketApi; marketApi.couponUse(omi.getCouponSelectRecordId()); ~~~ ## 请求传参 `Get`方式传参,使用`@PathVariable`、`@RequestParam`注解接收请求参数 ~~~ @GetMapping(value = "/user/info/{username}") public BaseResp <LoginUser> getUserInfo(@PathVariable("username") String username); ~~~ `Post`方式传参,使用`@RequestBody`注解接收请求参数。 ~~~ @PostMapping("/operlog") public BaseResp <Boolean> saveLog(@RequestBody SysOperLog sysOperLog); ~~~