1. 程式人生 > 其它 >記一次 SpringCloud OpenFeign 服務間呼叫傳參異常

記一次 SpringCloud OpenFeign 服務間呼叫傳參異常

錯誤方式:

    /**
     * 參與方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。