Spring Cloud与微服务之订单微服务

订单微服务

  订单微服务的主要作用是从商品微服务中获取与订单相关的商品条目信息,进而完成对于订单数据的请求操作。

  由于这里采用的是分布式的微服务架构,因而订单微服务中的商品条目信息是从两个商品微服务中以某种规则进行访问的,而这里,我们采用的是使用订单微服务以随机的方式访问不同的商品微服务。

springcloud-goods-order

springcloud-goods-order项目结构

在这里插入图片描述

springcloud-goods-order源码

  OrderController源码:


package com.lyc.controller;

import com.lyc.order.entity.Order;
import com.lyc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {
   

    @Autowired
    private OrderService orderService;

    @GetMapping("order/{orderId}")
    public Order queryOrderById(@PathVariable("orderId") String orderId){
   
        return this.orderService.queryOrderById(orderId);
    }

}

  ItemFeignClient源码:


package com.lyc.feign;

import com.lyc.item.entity.Item;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(value = "springcloud-goods-item")    //声明这是一个Feign的客户端
public interface ItemFeignClient {
   

    @GetMapping("/item/{id}")
    public Item queryItemById(@PathVariable("id") Long id);

}

  OrderProperties源码:


package com.lyc.properties;

import com.lyc.order.entity.ItemProperties;
import lombok.*;
import org.springframework.boot.context
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值