BLOB 类型 With Spring-Data-JPA

BLOB type With Spring-Data-JPA

我在 JpaRepository 中定义了一个 JPA 查询:

List<Object[]> getDoc ();

其中一列如果 BLOB type

但当我这样做时:

System.out.println("Content Type -> " + obj[1].getClass());
System.out.println("Content  -> " + obj[1]);

我得到了:

Content Type -> class [B
Content  -> [B@73e73b8e

而且我不知道如何将其转换为字符串

这意味着您的 obj[1] 是一个字节数组,对于 blob 来说正是这样。

要转换成字符串,需要指定编码。假设数据是根据UTF-8编码的,那就是

String s = new String((byte[]) obj[1], StandardCharsets.UTF_8)