From 381134049b6306dbad2dcdb411420ffcdecff01f Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 21 Aug 2025 11:56:13 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=E7=AB=AF=E5=8F=A3=E4=B8=BA=E7=A9=BA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E6=97=B6=EF=BC=8C=E8=B5=84=E4=BA=A7=E6=B8=85=E5=8D=95?= =?UTF-8?q?=E4=B8=AD=E7=AB=AF=E5=8F=A3=E6=98=BE=E7=A4=BA=E4=B8=BA0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1492666829733888]配置项端口为空字符串时,资产清单中端口显示为0 http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1492666829733888 --- .../framework/dao/config/mybatis-config.xml | 4 ++ .../EmptyStringToNullIntegerTypeHandler.java | 65 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/main/java/neatlogic/framework/dao/plugin/EmptyStringToNullIntegerTypeHandler.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 d8127410f..ab4479288 100644 --- a/src/main/java/neatlogic/framework/dao/config/mybatis-config.xml +++ b/src/main/java/neatlogic/framework/dao/config/mybatis-config.xml @@ -29,6 +29,10 @@ along with this program. If not, see .--> + + diff --git a/src/main/java/neatlogic/framework/dao/plugin/EmptyStringToNullIntegerTypeHandler.java b/src/main/java/neatlogic/framework/dao/plugin/EmptyStringToNullIntegerTypeHandler.java new file mode 100644 index 000000000..58de8b188 --- /dev/null +++ b/src/main/java/neatlogic/framework/dao/plugin/EmptyStringToNullIntegerTypeHandler.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.framework.dao.plugin; + +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class EmptyStringToNullIntegerTypeHandler extends BaseTypeHandler { + @Override + public void setNonNullParameter(PreparedStatement ps, int i, Integer parameter, JdbcType jdbcType) throws SQLException { + ps.setInt(i, parameter); + } + + @Override + public Integer getNullableResult(ResultSet rs, String columnName) throws SQLException { + int result = rs.getInt(columnName); + if (result == 0) { + String value = rs.getString(columnName); + return StringUtils.isBlank(value) ? null : result; + } + return result; + + } + + @Override + public Integer getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + int result = rs.getInt(columnIndex); + if (result == 0) { + String value = rs.getString(columnIndex); + return StringUtils.isBlank(value) ? null : result; + } + return result; + } + + @Override + public Integer getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + int result = cs.getInt(columnIndex); + if (result == 0) { + String value = cs.getString(columnIndex); + return StringUtils.isBlank(value) ? null : result; + } + return result; + } +} -- Gitee