(1)feign接口
@FeignClient(value = "microservice-product",fallback = ProductClientServiceFallBack.class)
public interface ProductClientService {
@RequestMapping(value = "/product/add", method = RequestMethod.POST)
boolean add(@RequestBody Product product);
@RequestMapping(value = "/product/get/{id}", method = RequestMethod.GET)
Product get(@PathVariable("id") Long id);
@RequestMapping(value = "/product/list", method = RequestMethod.GET)
List<Product> list();
}
(2)controller
@RestController
public class ProductController_Fegin {
@Autowired
ProductClientService service;
@RequestMapping("/consumer/product/add")
public boolean add(Product product){
return service.add(product);
}
@RequestMapping("/consumer/product/get/{id}")
public Product get(@PathVariable("id")Long id){
return service.get(id);
}
@RequestMapping("/consumer/product/list")
public List<Product> list(){
return service.list();
}
}