From 3aefd94bde5c9749c307fa2e49c8318cd0bcb1fa Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Mon, 9 Dec 2024 16:10:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0mybatis=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BD=AC=E6=8D=A2=20=E8=A7=A3=E5=86=B3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=8F=9C=E5=8D=95=E5=9B=A0=E4=B8=BABoolean=E8=BD=ACin?= =?UTF-8?q?t=20sql=E6=89=A7=E8=A1=8C=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/handler/MybatisTypeHandler.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/handler/MybatisTypeHandler.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/handler/MybatisTypeHandler.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/handler/MybatisTypeHandler.java new file mode 100644 index 00000000..1d6b2d5a --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/handler/MybatisTypeHandler.java @@ -0,0 +1,48 @@ +package org.jeecg.common.handler; + +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 MybatisTypeHandler extends BaseTypeHandler { + /** + * 功能描述:
+ * <> + * @param: [ps, i, parameter, jdbcType] + * i:Jdbc预编译时设置参数的索引值 + * parameter:要插入的参数值 true 或者false + * jdbcType:要插入JDBC的类型 + * 里面的业务逻辑要根据实际开发场景来写 我这里就写的简单一点比较好理解一下 + * @return: + * @author: wlt + * @date: 2022/3/22 21:25 + **/ + @Override + public void setNonNullParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException { + if (parameter){ + ps.setInt(i,1); + }else ps.setInt(i,0); + } + + @Override + public Boolean getNullableResult(ResultSet rs, String columnName) throws SQLException { + int man = rs.getInt(columnName); + return man == 1 ? true : false; + } + + @Override + public Boolean getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + int man = rs.getInt(columnIndex); + return man == 1 ? true : false; + } + + @Override + public Boolean getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + int man = cs.getInt(columnIndex); + return man == 1 ? true : false; + } +}