gpt4 book ai didi

java - Spring MVC Hibernate MySQL - 少1天进入数据库

转载 作者:行者123 更新时间:2023-12-01 09:36:20 26 4
gpt4 key购买 nike

我正在使用 Spring MVC Hibernate 和 MySQL 来存储一些数据。
一切看起来都很好,除了我在数据库中的日期显示少了一天。
您知道为什么会发生这种情况吗?

这是我的代码的一部分:

应用程序属性

database.driverClass=com.mysql.cj.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/clients?useSSL=false&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=true&serverTimezone=UTC
database.username=username
database.password=password

客户端.java

@Column(name ="REG_DATE")
@XmlElement
@DateTimeFormat(pattern="dd-MM-yyyy")
private LocalDate regdate;

JSP JSTL

<fmt:formatDate value="${client.regdate}" type="date" />
<form:input path="regdate" value="${regdate}" />

最佳答案

我必须将 application.properties 中的 mysql 服务器时区修改为实际时区:

database.url=jdbc:mysql://localhost:3306/clients?useSSL=false&&serverTimezone=UTC&useLegacyDatetimeCode=false&serverTimezone=欧洲/马德里

希望这对某人有用

关于java - Spring MVC Hibernate MySQL - 少1天进入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38874878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com