springMVC 文件上传 HTTP Status 400 – Bad Request

时间:2023-01-13 18:33:07

可能原因是:multipartResolver没有配置正确

请看解决方案:

    <!--文件上传 id必须为multipartResolver,不然报错HTTP Status 400 – Bad Request-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="UTF-8"/>
        <!--5M-->
        <property name="maxUploadSizePerFile" value="5242880"/>
        <property name="uploadTempDir" value="file:/tmp"/>
    </bean>