微服务SpringCloud简单的远程调用Demo

1.启动类配置

微服务SpringCloud简单的远程调用Demo_第1张图片

@SpringBootApplication
@EnableDiscoveryClient  //nacos注册
@EnableFeignClients
@ComponentScan(basePackages = {"com.atguigu"})
public class EduApplication {

    public static void main(String[] args) {
        SpringApplication.run(EduApplication.class, args);
    }
}

2.远程接口配置

微服务SpringCloud简单的远程调用Demo_第2张图片

@Component
@FeignClient("service-order")
public interface OrdersClient {

    //根据课程id和用户id查询订单表中订单状态
    @GetMapping("/eduorder/order/isBuyCourse/{courseId}/{memberId}")
    public boolean isBuyCourse(@PathVariable("courseId") String courseId, @PathVariable("memberId") String memberId);
    @PostMapping("/eduorder/order/testCloud")
    public R testCloud() ;
}

3.autoweird自动注入远程接口实现调用

微服务SpringCloud简单的远程调用Demo_第3张图片

@Autowired
private OrdersClient ordersClient;
@Resource
private JdbcTemplate jdbcTemplate;

//课程大纲列表,根据课程id进行查询
@GetMapping("getChapterVideo")
public R getChapterVideo() {
    R r = ordersClient.testCloud();
    return R.ok().data("allChapterVideo",r.getData());
}

微服务SpringCloud简单的远程调用Demo_第4张图片

@PostMapping("testCloud")
public R testCloud() {
    //创建订单,返回订单号

    String importSql1 ="select * from t_test";
    List> COLdataList1 = jdbcTemplate.queryForList(importSql1);
    Map map = COLdataList1.get(0);

    return R.ok().data("orderId",map);
}

4.postman测试结果

微服务SpringCloud简单的远程调用Demo_第5张图片

微服务SpringCloud简单的远程调用Demo_第6张图片

你可能感兴趣的:(spring,cloud,java,spring)