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;
}
}