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).
问题描述:访问400
原因:参数不能被识别或者参数有错误,检查form表单,还有就是表单中含有日期类型的数据也会有问题
解决:1.使用Spring的@DateTimeFormat注解
使用方法: 在对应的属性上或者其set方法上加上@DateTimeFormat注解, 这个注解有一个pattern属性, 可以指定要日期的格式.
就像这样:
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birth;
还需要在配置文件中添加"mvc:annotation-driven"这个标签, 否则不生效.
这种方法最简单,只需添加两处配置即可. 但只是局部生效, 若需要转换的属性比较多, 就造成了注解编写的冗余.
————————————————
版权声明:本文为CSDN博主「forJL」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wn084/article/details/80171687