Mybatis在sqlite中无法读写byte[]类问题的解决办法

2025-05-29 0 100

开发环境: springboot + mybatis plus

场景:在DAO的bean中有byte[]类时,写入可以成功,但是读取不行。从错误栈中可以看到原因是:sqlite的driver中,JDBC4ResultSet没有实现以下接口:

?

1

2

3

4
public Blob getBlob(int col)

throws SQLException { throw unused(); }

public Blob getBlob(String col)

throws SQLException { throw unused(); }

读写byte[]在JDBC规范中有3种接口:

  • InputStream getBinaryStream(int col)
  • byte[] getBytes(int col)
  • Blob getBlob(int col)

Mybatis Plus默认会选择第3个接口。因此,这里只需要将处理方法切换到前两个接口即可:方法就是更换一个TypeHandler

直接上代码:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14
@Data

@TableName(autoResultMap = true)

public class Member {

@TableId

private String personId;

private String name;

private String telephone;

@TableField(typeHandler = ByteArrayTypeHandler.class)

private byte[] img;

private String ext;

private Integer type;

private Integer ts;

}

关键点:

  • 添加@TableName(autoResultMap = true)
  • 添加@TableField(typeHandler = ByteArrayTypeHandler.class)

之后就可以正常读写byte[]了

总结

到此这篇关于Mybatis在sqlite中无法读写byte[]类问题的文章就介绍到这了,更多相关Mybatis在sqlite无法读写byte[]类内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!

原文链接:https://blog.csdn.net/icyfox_bupt/article/details/108867782

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 Mybatis在sqlite中无法读写byte[]类问题的解决办法 https://www.kuaiidc.com/116795.html

相关文章

发表评论
暂无评论