Mybatis在sqlite中无法读写byte[]类问题的解决办法
作者:icyfox_bupt 时间:2021-08-06 21:06:07
开发环境: springboot + mybatis plus
场景:在DAO的bean中有byte[]类时,写入可以成功,但是读取不行。从错误栈中可以看到原因是:sqlite的driver中,JDBC4ResultSet没有实现以下接口:
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
直接上代码:
@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[]了
来源:https://blog.csdn.net/icyfox_bupt/article/details/108867782
标签:sqlite,读写,byte[]
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
剑指Offer之Java算法习题精讲链表与字符串及数组
2022-10-03 19:10:17
![](https://img.aspxhome.com/file/2023/2/62732_0s.png)
基于Tomcat7、Java、WebSocket的服务器推送聊天室实例
2023-11-25 23:35:34
![](https://img.aspxhome.com/file/2023/0/60390_0s.jpg)
IDEA+JRebel实现全自动热部署的方法步骤
2023-11-29 13:53:30
![](https://img.aspxhome.com/file/2023/4/60454_0s.jpg)
Java String源码分析并介绍Sting 为什么不可变
2021-09-23 06:10:42
![](https://img.aspxhome.com/file/2023/9/62649_0s.png)
深入理解Spring中bean的生命周期介绍
2023-02-08 17:21:37
![](https://img.aspxhome.com/file/2023/8/61318_0s.png)
Java编程实现对十六进制字符串异或运算代码示例
2023-11-06 15:58:15
![](https://img.aspxhome.com/file/2023/2/58892_0s.png)
Java深入了解数据结构之栈与队列的详解
2022-03-24 08:12:27
![](https://img.aspxhome.com/file/2023/0/61590_0s.png)
springboot整合shiro多验证登录功能的实现(账号密码登录和使用手机验证码登录)
2023-05-25 18:53:29
解决SpringBoot web项目启动后立即关闭的问题
2023-07-26 02:33:37
![](https://img.aspxhome.com/file/2023/9/64909_0s.png)
Java项目开发中实现分页的三种方式总结
2021-08-25 21:36:36
IDEA 2019.1.3 激活码大全
2023-05-09 05:20:37
详解Java并发包中线程池ThreadPoolExecutor
2022-03-23 19:57:20
![](https://img.aspxhome.com/file/2023/9/64389_0s.png)
c# 使用Task实现非阻塞式的I/O操作
2023-07-21 23:27:39
Java Online Exam在线考试系统的实现
2022-01-30 13:49:35
![](https://img.aspxhome.com/file/2023/3/61783_0s.png)
详解JAVA 线程-线程的状态有哪些?它是如何工作的?
2023-11-27 03:33:09
![](https://img.aspxhome.com/file/2023/1/65181_0s.png)
java如何实现自动生成数据库设计文档
2023-08-07 19:01:28
![](https://img.aspxhome.com/file/2023/3/61323_0s.jpg)
springMvc注解之@ResponseBody和@RequestBody详解
2022-10-09 17:57:19
![](https://img.aspxhome.com/file/2023/2/62762_0s.png)
Netty分布式pipeline管道异常传播事件源码解析
2021-08-15 16:12:02
Java的类型擦除式泛型详解
2022-01-02 11:59:00
![](https://img.aspxhome.com/file/2023/8/61608_0s.jpg)
详解java中BigDecimal精度问题
2021-08-17 10:24:59
![](https://img.aspxhome.com/file/2023/9/64039_0s.jpg)