SpringMVC字段验证返回400错误码

错误信息

HTTP Status 400 – Bad Request

Type Status Report

Description 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>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值