(关键处)将商品微服务中的分页查询商品接口定义为一个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); } }
标签:FeignClient,Feign,hmall,springframework,item,import,com From: https://www.cnblogs.com/Rover20230226/p/17500154.html