Mybatis在sqlite中無法讀寫byte[]類問題的解決辦法
開發(fā)環(huán)境: springboot + mybatis plus
場景:在DAO的bean中有byte[]類時(shí),寫入可以成功,但是讀取不行。從錯(cuò)誤棧中可以看到原因是:sqlite的driver中,JDBC4ResultSet沒有實(shí)現(xiàn)以下接口:
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默認(rèn)會選擇第3個(gè)接口。因此,這里只需要將處理方法切換到前兩個(gè)接口即可:方法就是更換一個(gè)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;}
關(guān)鍵點(diǎn):
添加@TableName(autoResultMap = true) 添加@TableField(typeHandler = ByteArrayTypeHandler.class)之后就可以正常讀寫byte[]了
總結(jié)
到此這篇關(guān)于Mybatis在sqlite中無法讀寫byte[]類問題的文章就介紹到這了,更多相關(guān)Mybatis在sqlite無法讀寫byte[]類內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 關(guān)于oracle日期函數(shù)的介紹和使用2. Sql Server 壓縮數(shù)據(jù)庫日志文件的方法3. Microsoft Office Access刪除表記錄的方法4. DB2 V9.5工作負(fù)載管理之閾值(THRESHOLD)5. 什么是Access數(shù)據(jù)庫6. 提綱挈領(lǐng)Oracle數(shù)據(jù)庫災(zāi)難防護(hù)技術(shù)7. MySQL的DML語言操作實(shí)例8. Mysql服務(wù)添加 iptables防火墻策略的方案9. SQLSERVER調(diào)用C#的代碼實(shí)現(xiàn)10. Microsoft Office Access凍結(jié)字段的方法

網(wǎng)公網(wǎng)安備