FeignClient【Feign】

(关键处)将商品微服务中的分页查询商品接口定义为一个FeignClient,放到feign-api模块中

1、@FeignClient 的名字为 application.yml 文件中的 application.name

2、@GetMapping 的路径为 ItemController 文件中的 @RequestMapping 路径 + 请求方式路径

复制代码
package com.hmall.common.feign;

import com.hmall.common.dto.PageDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient("itemservice")
public interface ItemFeign {

    @GetMapping("/item/list")
    public PageDTO list(Integer page, Integer size);
}
复制代码

 

item-service的application.yml

复制代码
server:
  port: 8081
spring:
  application:
    name: itemservice
  datasource:
    url: jdbc:mysql://localhost:3306/hmall?useSSL=false
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
  cloud:
    nacos:
      server-addr: localhost:8848 # nacos地址
mybatis-plus:
  type-aliases-package: com.hmall.item.pojo
  configuration:
    map-underscore-to-camel-case: true
  global-config:
    db-config:
      update-strategy: not_null
      id-type: auto
logging:
  level:
    com.hmall: debug
  pattern:
    dateformat: HH:mm:ss:SSS
复制代码

 

ItemController

复制代码
package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.item.service.IItemService;
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;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    /**
     * 分页查询接口
     */
    @GetMapping("/list")
    public PageDTO list(Integer page, Integer size) {
        return itemService.pageInfo(page, size);
    }
}
复制代码

 

posted @   青核桃啊  阅读(176)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示