【问题标题】:An Errors/BindingResult argument is expected to be declared immediately after the model attributeErrors/BindingResult 参数应在模型属性之后立即声明
【发布时间】:2026-02-17 06:20:03
【问题描述】:

我的控制器接受参数

public
void changeAvatar(
        @ApiParam(value = "A new avatar for the user", required = true)
        @RequestPart final MultipartFile avatar,
        BindingResult bindingResult
)

当向控制器发送请求时,他把我扔出去

java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public void com.web.web.controller.SettingsRestController.changeAvatar(org.springframework.web.multipart.MultipartFile,org.springframework.validation.BindingResult) throws java.io.IOException

【问题讨论】:

    标签: java spring spring-mvc spring-boot


    【解决方案1】:

    来自Spring Framework Reference

    绑定结果

    命令/表单对象数据绑定的验证结果;这 参数必须在命令/表单对象之后立即声明 控制器方法签名。

    因此,您可以使用BindingResult 仅为您的命令/表单对象获取特定于绑定的分析。

    【讨论】: