Server端
pom配置
定义接口与实现
public interface CountryFeign {
@GetMapping(value = "/api/studying/feign/getCountrys")
ResponsePageBean<GetCountryResp> getCountryPage(@RequestParam("pageNo") int pageNo,@RequestParam("pageSize") int pageSize);
}
@RestController
public class CountryFeignController implements CountryFeign {
private static final Logger LOGGER = LoggerFactory.getLogger(CountryFeignController.class);
@Autowired
private CountryService countryService;
@Override
public ResponsePageBean<GetCountryResp> getCountryPage(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize){
//代码实现
}
}
增加注解
@EnableFeignClients
public class StudyingApplication {
public static void main(String[] args){
SpringApplication.run(StudyingApplication.class,args);
}
}
Client端
代码实现
@FeignClient(name = "studying")
public interface CountryFeignService extends CountryFeign {
}
@Controller
@RequestMapping("/country")
public class AdminCountryController extends BaseController {
private static final Logger LOGGER = LoggerFactory.getLogger(AdminCountryController.class);
@Autowired
private CountryFeignService countryService;
}