From 9a6c6cd662c16b2bc108e1c5f1c7b26e332606f0 Mon Sep 17 00:00:00 2001 From: minglipro Date: Mon, 15 Sep 2025 13:55:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(mybatis):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=A4=84=E7=90=86=E5=99=A8=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20JDBC=20=E7=B1=BB=E5=9E=8B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=B8=BA=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 DateTimeTypeHandler、MysqlUUIDBinaryTypeHandler 和 UUIDTypeHandler - 将 setNonNullParameter 方法的 jdbcType 参数变更为可空类型 - 更新方法实现以适应新的可空参数 - 提升代码的健壮性和灵活性,允许在某些情况下不指定 JDBC 类型 --- gradle.properties | 4 ++-- .../mybatis/typehandler/datetime/DateTimeTypeHandler.kt | 6 +++--- .../utils/mybatis/typehandler/uuid/UUIDTypeHandler.kt | 8 ++++---- .../typehandler/uuid/mysql/MysqlUUIDBinaryTypeHandler.kt | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5d5b3f9..3321fcf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,10 +16,10 @@ # ProjectName mingli-utils # ModuleName mingli-utils # CurrentFile gradle.properties -# LastUpdate 2025-09-15 12:45:46 +# LastUpdate 2025-09-15 13:54:50 # UpdateUser MingLiPro # JDKVERSIONS=1.8 GROUPSID=com.mingliqiye.utils ARTIFACTID=mingli-utils -VERSIONS=4.0.3 +VERSIONS=4.0.4 diff --git a/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/datetime/DateTimeTypeHandler.kt b/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/datetime/DateTimeTypeHandler.kt index 1a35a28..7790be7 100644 --- a/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/datetime/DateTimeTypeHandler.kt +++ b/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/datetime/DateTimeTypeHandler.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile DateTimeTypeHandler.kt - * LastUpdate 2025-09-14 18:19:29 + * LastUpdate 2025-09-15 13:53:53 * UpdateUser MingLiPro */ @file:JvmName("DateTimeConvertor") @@ -65,8 +65,8 @@ class DateTimeTypeHandler : BaseTypeHandler() { override fun setNonNullParameter( ps: PreparedStatement, i: Int, - parameter: DateTime, // 移除了 ?,因为这是 non-null 方法 - jdbcType: JdbcType + parameter: DateTime, + jdbcType: JdbcType? ) { // 使用 setObject 允许传入 null,由数据库处理 ps.setObject(i, toLocalDateTime(parameter)) diff --git a/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/uuid/UUIDTypeHandler.kt b/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/uuid/UUIDTypeHandler.kt index 9b369ab..d65a758 100644 --- a/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/uuid/UUIDTypeHandler.kt +++ b/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/uuid/UUIDTypeHandler.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile UUIDTypeHandler.kt - * LastUpdate 2025-09-14 18:19:29 + * LastUpdate 2025-09-15 13:54:18 * UpdateUser MingLiPro */ @file:JvmName("UUIDConvertor") @@ -112,7 +112,7 @@ class UUIDBinaryTypeHandler : BaseTypeHandler() { * @param jdbcType JDBC类型 */ override fun setNonNullParameter( - ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType + ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType? ) { ps.setBytes(i, uuidToByteArray(parameter)) } @@ -172,7 +172,7 @@ class UUIDStringTypeHandler : BaseTypeHandler() { * @param jdbcType JDBC类型 */ override fun setNonNullParameter( - ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType + ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType? ) { ps.setString(i, uuidToString(parameter)) } @@ -234,7 +234,7 @@ class UUIDTypeHandler : BaseTypeHandler() { * @param jdbcType JDBC类型 */ override fun setNonNullParameter( - ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType + ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType? ) { ps.setObject(i, parameter.getUuid()) } diff --git a/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/uuid/mysql/MysqlUUIDBinaryTypeHandler.kt b/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/uuid/mysql/MysqlUUIDBinaryTypeHandler.kt index 7270599..c74d44f 100644 --- a/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/uuid/mysql/MysqlUUIDBinaryTypeHandler.kt +++ b/src/main/kotlin/com/mingliqiye/utils/mybatis/typehandler/uuid/mysql/MysqlUUIDBinaryTypeHandler.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile MysqlUUIDBinaryTypeHandler.kt - * LastUpdate 2025-09-14 18:19:29 + * LastUpdate 2025-09-15 13:54:29 * UpdateUser MingLiPro */ @@ -72,7 +72,7 @@ class MysqlUUIDBinaryTypeHandler : BaseTypeHandler() { ps: PreparedStatement, i: Int, parameter: UUID, - jdbcType: JdbcType + jdbcType: JdbcType? ) { ps.setBytes(i, toByteArray(parameter)) }