当前位置:网站首页>Precautions for using feign to make remote calls
Precautions for using feign to make remote calls
2022-04-22 07:21:00 【James killed you】
In the use of feign There are some problems in the process , So here's a summary
1. Defined to make remote calls api The parameters in the method parameter list in the interface are must All have to be marked @RequestParam(“value”) annotation **, Otherwise, the call will report 405 abnormal , This is with controller Different in ,controller The method in can automatically bind parameters as long as the parameter name corresponds to the parameter key name passed in from the foreground
Complex types must be marked with @RequestBody annotation
2.service In microservices Controller Parameter binding of :
If there are complex types in the parameter list , Please use Post request , Use Get Request meeting report Bad Request error , And it needs to be marked @RequestBody annotation , The common basic type can not be marked with @RequestParam Annotation can automatically bind parameters
If there are other questions , You are also welcome to add , Put in the code :
api:
@FeignClient("MS-ADMIN-SERVICE")
public interface FixFeignService {
@GetMapping("/fix")
public List<FixInfo> findAll();
@PostMapping("/fix/add")
public int insert(@RequestBody FixInfo fixInfo);
@PostMapping("/fix/limitByParam")
public LayUIPageBean limitByParam(@RequestBody FixInfo fixInfo, @RequestParam("page") Integer page, @RequestParam("limit") Integer limit);
@PostMapping("/fix/delByIds")
public boolean delByIds(@RequestParam("ids[]") Long[] ids);
@GetMapping("/fix/findById")
public FixInfo findById(@RequestParam("id") Long id);
@PostMapping("/fix/update")
boolean update(@RequestBody FixInfo fixInfo);
}
service Microservices
@RestController
@RequestMapping("/fix")
@Slf4j
public class FixInfoController {
@Autowired
private FixInfoService fixInfoService;
@GetMapping("")
public List<FixInfo> findAll(){
List<FixInfo> all = fixInfoService.findAll();
return all;
}
@PostMapping("/add")
public int insert(@RequestBody FixInfo fixInfo){
return fixInfoService.insert(fixInfo);
}
@PostMapping("/limitByParam")
public LayUIPageBean limitByParam(@RequestBody FixInfo fixInfo,Integer page,Integer limit){
LayUIPageBean layUIPageBean = new LayUIPageBean();
PageHelper.startPage(page,limit);
List<FixInfo> all = fixInfoService.findByParam(fixInfo);
PageInfo<FixInfo> pageInfo = new PageInfo<>(all);
return layUIPageBean.setCount((int)pageInfo.getTotal()).setData(pageInfo.getList());
}
@PostMapping("/delByIds")
public boolean delByIds(@RequestParam("ids[]") Long[] ids){
//log.info("id"+ids[0]);
boolean flag= fixInfoService.delByIds(ids);
return flag;
}
@GetMapping("/findById")
public FixInfo findById(Long id){
return fixInfoService.findById(id);
}
@PostMapping("/update")
public boolean update(@RequestBody FixInfo fixInfo){
return fixInfoService.update(fixInfo);
}
}
版权声明
本文为[James killed you]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220611235202.html
边栏推荐
- 机械设计知识点规划
- [number theory] congruence (I): basic concepts and properties of congruence
- modelsim仿真加速注意点
- C语言 | 预处理
- Wechat third party web page authorization
- 【数论】同余(三):一元线性同余方程
- 14 lines of code to complete arbitrary selection of image crawling
- JVM中唯一一个不会发生GC和OOM的存储区域
- 1、编写学生信息管理系统以下三个模块:并检测执行。 1、添加学生信息 4、查询学生信息 5、查询全部学生信息
- 二叉树链式结构操作LeetCode+牛客(详解)
猜你喜欢

ASP. Net daily development notes ----- IIS server supports downloading APK

Raspberry Pi 4b

双向循环链表(详)

synchronized锁优化的一些机制(锁升级)

What is socket programming?

Jeecg project deployment notes

. net learning notes (2) -- ubiquitous reflection (including the method of reading JSON)

Pycharm only needs five steps to improve the download speed by using Tsinghua image source

Review of the sixth edition of introduction to software engineering (notes)

我们常说的栈帧的内部结构是什么样的呢?
随机推荐
[number theory] congruence (2): inverse element
MacOS installs redis and sets the service self start
[bug notes] input: - WebKit autofill: the input box automatically fills in the background problem
Pixhawk4+Up Board / NUC Implement VIO By Deploying T265
idea 不显示Run Dashboard视图窗口的问题
Format control of format() method
Vscode, this is enough
[bug notes] antd table height adaptive window height
ASP. Net daily development notes ---- export to excel
Flutter环境搭建踩坑过程
Robomaster Dajiang flying hand assessment
面试官常问的,对象分配的一般过程及特殊情况
MySQL学习笔记
macOS安装redis并设置服务自启动
【数论】同余(一):同余的基本概念与性质
[number theory] prime number (2): prime number sieve method (Egyptian sieve, Euler sieve, interval sieve)
【数论】同余(二):逆元
Change the class with parameters in the first part of the last operation to be presented in the way without parameters, and the function remains unchanged.
小题记录——
二叉树链式结构操作LeetCode+牛客(详解)