開(kāi)發(fā)環(huán)境: springboot + mybatis plus
場(chǎng)景:在DAO的bean中有byte[]類(lèi)時(shí),寫(xiě)入可以成功,但是讀取不行。從錯(cuò)誤棧中可以看到原因是:sqlite的driver中,JDBC4ResultSet沒(méi)有實(shí)現(xiàn)以下接口:
1
2
3
4
|
public Blob getBlob( int col) throws SQLException { throw unused(); } public Blob getBlob(String col) throws SQLException { throw unused(); } |
讀寫(xiě)byte[]在JDBC規(guī)范中有3種接口:
- InputStream getBinaryStream(int col)
- byte[] getBytes(int col)
- Blob getBlob(int col)
Mybatis Plus默認(rèn)會(huì)選擇第3個(gè)接口。因此,這里只需要將處理方法切換到前兩個(gè)接口即可:方法就是更換一個(gè)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; } |
關(guān)鍵點(diǎn):
-
添加
@TableName(autoResultMap = true)
-
添加
@TableField(typeHandler = ByteArrayTypeHandler.class)
之后就可以正常讀寫(xiě)byte[]了
總結(jié)
到此這篇關(guān)于Mybatis在sqlite中無(wú)法讀寫(xiě)byte[]類(lèi)問(wèn)題的文章就介紹到這了,更多相關(guān)Mybatis在sqlite無(wú)法讀寫(xiě)byte[]類(lèi)內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/icyfox_bupt/article/details/108867782