Mybatis 处理clob类型数据

2022-08-18 09:28:44

当执行sql语句,返回的是map类型时, 比如

publicList<Map<String, Object>> query(@Param("sql")String sql)

得到的数据是List<Map>类型数据,此时,如果有返回的有clob字段时,数据是这样的oracle.sql.CLOB@63636de0 ,显然,这不是我想要的,我需要的是字符串数据
那么怎么来处理clob字段呢,很简单
就是定义类型处理器,来专门处理Clob字段,将Clob数据转换为字符串数据返回

@MappedJdbcTypes(JdbcType.CLOB)publicclassClobTypeHandleextendsBaseTypeHandler<Object> {
    @Overridepublicvoid setNonNullParameter(PreparedStatement ps,int i, Object parameter, JdbcType jdbcType)
            throws SQLException {
        ps.setObject(i, parameter);
    }

    @Overridepublic Object getNullableResult(ResultSet rs, String columnName) throws SQLException {return rs.getString(columnName);
    }

    @Overridepublic Object getNullableResult(ResultSet rs,int columnIndex) throws SQLException {return rs.getString(columnIndex);
    }

    @Overridepublic Object getNullableResult(CallableStatement cs,int columnIndex) throws SQLException {return cs.getString(columnIndex);
    }

}
  • 作者:houjinimei
  • 原文链接:https://blog.csdn.net/houjinimei/article/details/76599217
    更新时间:2022-08-18 09:28:44