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 { @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); } }