Mybatis在sqlite中無法讀寫byte[]類問題的解決辦法
開發(fā)環(huán)境: 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規(guī)范中有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[]了
總結
到此這篇關于Mybatis在sqlite中無法讀寫byte[]類問題的文章就介紹到這了,更多相關Mybatis在sqlite無法讀寫byte[]類內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
SpringBoot?Aop實現接口請求次數統(tǒng)計
我們通過Spring AOP在每次執(zhí)行方法前或執(zhí)行方法后進行切面的處理,進而統(tǒng)計方法訪問的次數等功能,本文主要介紹了SpringBoot?Aop實現接口請求次數統(tǒng)計2024-02-02Spring Boot RestTemplate提交表單數據的三種方法
本篇文章主要介紹了Spring Boot RestTemplate提交表單數據的三種方法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03