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 d8127410ff870420393a5056fe83ad87034afad1..ab4479288113786f6cc37ef43cd0452894bf33f4 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 0000000000000000000000000000000000000000..58de8b188441829903d579943c42ae0ffab929c0 --- /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; + } +}