jvm时区:亚洲/首尔
我的测试查询
选择#{from},#{to}
输入
YearMonth input = YearMonth.of(year, month)
LocalDateTime from = input.atDay(1).atStartOfDay()
LocalDateTime to = input.atEndOfMonth().atTime(LocalTime.MAX)
案例1。将serverTimezone=UTC
添加到jdbc url
案例1。将serverTimezone=Asia/Seoul
添加到jdbc url
[11:03:54] [main] [DEBUG] BaseJdbcLogger.debug(143)| ==> Preparing: SELECT ?, ?
[11:03:54] [main] [DEBUG] BaseJdbcLogger.debug(143)| ==> Parameters: 2020-01-01T00:00(LocalDateTime), 2020-01-31T23:59:59.999999999(LocalDateTime)
[11:03:54] [main] [DEBUG] Slf4jSpyLogDelegator.sqlTimingOccurred(368)| com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
1. SELECT 2020-01-01T00:00, 2020-01-31T23:59:59.999999999
{executed in 3 msec}
[11:03:54] [main] [INFO ] Slf4jSpyLogDelegator.resultSetCollected(610)|
|----------------------|----------------------|
|2019-12-31 15:00:00.0 |2020-01-31 15:00:00.0 |
|----------------------|----------------------|
|----------------------|----------------------|
[14:27:16] [main] [DEBUG] BaseJdbcLogger.debug(143)| ==> Preparing: SELECT ?, ?
[14:27:16] [main] [DEBUG] BaseJdbcLogger.debug(143)| ==> Parameters: 2020-01-01T00:00(LocalDateTime), 2020-01-31T23:59:59.999999999(LocalDateTime)
[14:27:16] [main] [DEBUG] Slf4jSpyLogDelegator.sqlTimingOccurred(368)| com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
1. SELECT 2020-01-01T00:00, 2020-01-31T23:59:59.999999999
{executed in 4 msec}
[14:27:16] [main] [INFO ] Slf4jSpyLogDelegator.resultSetCollected(610)|
|----------------------|----------------------|
|2020-01-01 00:00:00.0 |2020-02-01 00:00:00.0 |
|----------------------|----------------------|
|----------------------|----------------------|
Q1。 Java LocalDateTime是否通过mybatis LocalDateTimeTypeHandler转换为jdbc TIMESTAMP?
Q2。 mybatis LocalDateTimeTypeHandler是否根据jdbc servertimezone设置转换值?
Q3。为什么我的2020-01-31T23:59:59.999999999
值转换为2020-02-01 00:00:00.0
?
LocalDateTime
转换为java.sql.Timestamp
(尽管在较早的版本中已完成)。LocalDateTime
的精度为纳秒(9位数),而MySQL的TIME
,DATETIME
和TIMESTAMP
的精度仅为微秒(6位数)。您观察到的行为将在MySQL documentation中进行说明。将具有小数秒部分的TIME,DATE或TIMESTAMP值插入相同类型但小数位数较少的列中会导致舍入。