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); } }
标签:
I2 - 实例代码
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通