From 051ca5e9f53897fa6b88aa469d360656268542eb Mon Sep 17 00:00:00 2001
From: linbangquan <1437892690@qq.com>
Date: Mon, 27 Nov 2023 09:40:11 +0800
Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E9=85=8D=E7=BD=AE?=
=?UTF-8?q?=E9=A1=B9=E5=88=97=E8=A1=A8-=E7=BC=96=E8=BE=91=E9=85=8D?=
=?UTF-8?q?=E7=BD=AE=E9=A1=B9=EF=BC=8C=E6=97=A5=E6=9C=9F=E6=97=B6=E9=97=B4?=
=?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=BF=9D=E5=AD=98=E5=BC=82=E5=B8=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
关联 #[1025891654664192]配置项列表-编辑配置项,日期时间属性保存异常 http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1025891654664192
---
.../framework/dao/config/mybatis-config.xml | 1 +
.../dao/plugin/LocalDateTimeTypeHandler.java | 42 +++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100644 src/main/java/neatlogic/framework/dao/plugin/LocalDateTimeTypeHandler.java
diff --git a/src/main/java/neatlogic/framework/dao/config/mybatis-config.xml b/src/main/java/neatlogic/framework/dao/config/mybatis-config.xml
index 974bd5976..5d94ad024 100644
--- a/src/main/java/neatlogic/framework/dao/config/mybatis-config.xml
+++ b/src/main/java/neatlogic/framework/dao/config/mybatis-config.xml
@@ -26,6 +26,7 @@ limitations under the License.
+
diff --git a/src/main/java/neatlogic/framework/dao/plugin/LocalDateTimeTypeHandler.java b/src/main/java/neatlogic/framework/dao/plugin/LocalDateTimeTypeHandler.java
new file mode 100644
index 000000000..b7467d85b
--- /dev/null
+++ b/src/main/java/neatlogic/framework/dao/plugin/LocalDateTimeTypeHandler.java
@@ -0,0 +1,42 @@
+package neatlogic.framework.dao.plugin;
+
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedTypes;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+@MappedTypes(LocalDateTime.class)
+public class LocalDateTimeTypeHandler extends BaseTypeHandler {
+
+ private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+ @Override
+ public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
+ ps.setObject(i, LocalDateTime.parse(parameter, formatter));
+ }
+
+ @Override
+ public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
+ LocalDateTime localDateTime = rs.getObject(columnName, LocalDateTime.class);
+ return localDateTime != null ? localDateTime.format(formatter) : null;
+ }
+
+ @Override
+ public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+ LocalDateTime localDateTime = rs.getObject(columnIndex, LocalDateTime.class);
+ return localDateTime != null ? localDateTime.format(formatter) : null;
+ }
+
+ @Override
+ public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+ LocalDateTime localDateTime = cs.getObject(columnIndex, LocalDateTime.class);
+ return localDateTime != null ? localDateTime.format(formatter) : null;
+ }
+
+}
--
Gitee