fix: 增加mybatis类型转换 解决修改菜单因为Boolean转int sql执行失败问题

This commit is contained in:
xiaoguangbin 2024-12-09 16:10:44 +08:00
parent db9d27d30d
commit 3aefd94bde

View File

@ -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<Boolean> {
/**
* 功能描述: <br>
* <>
* @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;
}
}