如何处理 Spring 批处理中的 blob 字段?

How to handle blob field in Spring Batch?

我需要从数据库中读取一个 blob 列并将其放入文件中,反之亦然 Spring Batch。 我该怎么做? 我正在使用 spring 批处理从数据库中读取数据并将其放入 CSV 文件中,反之亦然,但现在我还必须管理 blob 数据类型,当有它时,我需要用这些数据创建一个文件。

一般可以使用byte[]类型字段来呈现blob。它可以依赖于使用什么数据库。

一种方法是使用 LobHandler。您可以将 blob 作为字节获取并使用 (getBlobAsBytes) 将其转换为字符串,或者使用 (getBlobAsBinaryStream)[=11= 作为 BinaryStream ]

public class YourRowMapper implements RowMapper<YourObjectType> {
        @Override
        public YourObjectType mapRow(ResultSet resultSet, int i) throws SQLException {

            LobHandler lobHandler = new DefaultLobHandler();
            String value = new String(lobHandler.getBlobAsBytes(resultSet, "COLUMN_NAME"));

            return null;
        }
    }

希望对您有所帮助