FeignClient【Feign】

发布时间 2023-06-23 20:41:24作者: Rover20230226

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

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

 

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