liurunyu
2024-08-03 3e4fb6b20cdb85b1bf290a88f68a4646915da78d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.dy.common.mybatis;
 
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 BooleanTypeHandler extends BaseTypeHandler<Boolean> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException {
        ps.setByte(i , parameter==null?(byte)0:(parameter.booleanValue()?(byte)1:(byte)0));
    }
 
    @Override
    public Boolean getNullableResult(ResultSet rs, String columnName) throws SQLException {
        Byte colV = rs.getByte(columnName) ;
        return colV==null?false:(colV.byteValue()==1?true:false);
    }
 
    @Override
    public Boolean getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        Byte colV = rs.getByte(columnIndex) ;
        return colV==null?false:(colV.byteValue()==1?true:false);
    }
 
    @Override
    public Boolean getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        Byte colV = cs.getByte(columnIndex) ;
        return colV==null?false:(colV.byteValue()==1?true:false);
    }
}