記一次 SpringCloud OpenFeign 服務間呼叫傳參異常
阿新 • • 發佈:2022-03-30
錯誤方式:
/** * 參與方Controller中:更新角色快取 */ @PostMapping(value = "/cacheSysUserRole") public Result<?> cacheSysUserRole(@RequestParam("userRoleList") List<SysUserRole> userRoleList) { cacheService.cacheSysUserRole(userRoleList); return success(); }
/*** 呼叫方Feign介面中:更新角色快取 * * @param userRoleList List<SysUserRole> * @return Result<?> */ @PostMapping(value = "/gateway/gateway-cache/cacheSysUserRole") Result<?> cacheSysUserRole(@RequestParam("userRoleList") List<SysUserRole> userRoleList);
正確方式:
/** * 參與方Controller中:更新角色快取 */ @PostMapping(value = "/cacheSysUserRole") public Result<?> cacheSysUserRole(@RequestBody List<SysUserRole> userRoleList) { cacheService.cacheSysUserRole(userRoleList); return success(); }
/** * 發起方Feign介面中:更新角色快取 * *@param userRoleList List<SysUserRole> * @return Result<?> */ @PostMapping(value = "/gateway/gateway-cache/cacheSysUserRole") Result<?> cacheSysUserRole(@RequestBody List<SysUserRole> userRoleList);
總結:方法使用@PostMapping,引數使用@RequestBody。