The server cannot or will not process the request due to something that is perceived to be a client

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).


Apache Tomcat/9.0.12

 <form action="update" method="post">
        出生日期:<input type="date" name="time">
        <input type="submit" value="提交">
    </form>

错误理由很简单,你传的数据有问题,要么写的约束,要么时间类型格式

解决方案:

    @InitBinder
    public void init(WebDataBinder binder){
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class,new CustomDateEditor(dateFormat,true));
    }

还有一种注解方法,简单推荐。

参数pattern中写时间格式

@DateTimeFormat(pattern = "yyyy-MM-dd")

在控制器中还要写

@Valid

不管在bean中localdate,date都可以处理错误。

猜你喜欢

转载自blog.csdn.net/qq_41520636/article/details/84592227