SpringMVC字段验证返回400错误码

来源:互联网 发布:软件项目验收确认书 编辑:程序博客网 时间:2024/05/29 18:01

错误信息

HTTP Status 400 – Bad RequestType Status ReportDescription The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

错误原因

如果一个方法中有参数被 @Valid 标注了,但该参数后面没有紧跟一个 BindingResult 类型的参数,那么提交到该方法时,将返回 400 错误。

解决方法

//@Valid后跟个JavaBean,紧跟其后的参数必定是BindingResult@RequestMapping("doLogin")private String doLogin(@Valid LoginBean loginBean, BindingResult bindingResult, Model model) {    return null;}

SpringMVC整合Fastjson

    <mvc:annotation-driven>        <mvc:message-converters register-defaults="true">            <!-- 配置Fastjson 替换原来的jackson支持 -->            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">                <property name="supportedMediaTypes">                    <list>                        <value>text/html;charset=UTF-8</value>                        <value>application/json</value>                    </list>                </property>            </bean>        </mvc:message-converters>    </mvc:annotation-driven>
阅读全文
0 0