input、springmvc、mybatis、数据库的 存储时间【yyyy-MM-dd HH:mm:ss】问题

新手上路,请多包涵
  1. 在input中用datetime-local类型
  2. 在实体类属性使用了

@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date starttime;

  1. 在mybatis中 映射

<result property="starttime" column="starttime" jdbcType="TIMESTAMP"/>

  1. 数据库字段设计是用datetime

5.问题来了: 在实体类属性使用
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
会报:
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).

换成:
@DateTimeFormat(pattern="yyyy-MM-dd")
存入数据库的数据只有:2021-02-07 00:00:00【例子】

想知道这要如何处理,试了很多方式都不行

阅读 2.1k
1 个回答

主要看你的数据绑定的方式;
非json请求的话,自己去实现Converter接口应该是最舒服的;
jsonformat,看名字就知道不能处理表单了吧

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题