配置Mybatis处理oracle数据库number类型类
1.自定义一个TypeHander继承原来的TypeHandler
@MappedJdbcTypes(JdbcType.NUMERIC)
public class MyBigDecimalTypeHandler extends BigDecimalTypeHandler {
@Override
public BigDecimal getNullableResult(ResultSet rs, String columnName) throws SQLException {
BigDecimal result =super.getNullableResult(rs, columnName)==null?BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP):super.getNullableResult(rs, columnName).setScale(2, BigDecimal.ROUND_HALF_UP);
return result;
}
@Override
public BigDecimal getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
BigDecimal result =super.getNullableResult(rs, columnIndex)==null?BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP):super.getNullableResult(rs, columnIndex).setScale(2, BigDecimal.ROUND_HALF_UP);
return result;
}
@Override
public BigDecimal getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
BigDecimal result = super.getNullableResult(cs, columnIndex)==null?BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP):super.getNullableResult(cs, columnIndex).setScale(2, BigDecimal.ROUND_HALF_UP);
return result;
}
}
2.注册
在mybatis config.xml文件配置
<typeHandlers>
<typeHandler handler="你所继承的TypeHandler路径"
javaType="java.math.BigDecimal" />
</typeHandlers>
这里具体可以查看https://blog.csdn.net/qq_36761831/article/details/88375481