获取商品列表(Feign)

localhost:8010/productList

localhost:7900/product/list

localhost:7901/product/list

商品服务和数据库打交道,你看这边SQL语句已经打印出来了,而订单服务是要去调用它的,我们这里专门打印一个日志

出来
package com.learn.cloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.learn.cloud.bean.ProductInfo;
import com.learn.cloud.client.ProductFeignClient;

@RestController
public class FeignClientController {
	

	  @Autowired
	  private ProductFeignClient productFeignClient;

	  @GetMapping("/getProductMsg")
	  public String findById() {
		  String productMsg = this.productFeignClient.productMsg();
		  System.out.println(productMsg);
	    return productMsg;
	  }
	  
	  @GetMapping("/productList")
	  public List<ProductInfo> productList() {
		  List<ProductInfo> productInfoList = this.productFeignClient.productList();
		  System.out.println(productInfoList);
	    return productInfoList;
	  }
}
package com.learn.cloud.client;

import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.learn.cloud.bean.ProductInfo;

@FeignClient(name = "product")
public interface ProductFeignClient {
	  @RequestMapping(value = "/msg", method = RequestMethod.GET)
	  public String productMsg();
	  
	  @RequestMapping(value = "/product/list", method = RequestMethod.GET)
	  public List<ProductInfo> productList();
}
package com.learn.cloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.learn.cloud.entity.ProductInfo;
import com.learn.cloud.service.ProductService;

@RestController
@RequestMapping("/product")
public class ProductController {
	
    @Autowired
    private ProductService productService;

    /**
     * 1. 查询所有在架的商品
     */
    @GetMapping("/list")
    public List<ProductInfo> list() {
        //1. 查询所有在架的商品
        List<ProductInfo> productInfoList = productService.findUpAll();
        return productInfoList;
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值