国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Mybatis在sqlite中無法讀寫byte[]類問題的解決辦法

瀏覽:5日期:2023-10-22 12:36:01

開發環境: 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[]了

總結

到此這篇關于Mybatis在sqlite中無法讀寫byte[]類問題的文章就介紹到這了,更多相關Mybatis在sqlite無法讀寫byte[]類內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 江北区| 谢通门县| 睢宁县| 武宁县| 思茅市| 栖霞市| 怀集县| 东乌| 齐齐哈尔市| 弋阳县| 泽普县| 山西省| 潼南县| 信宜市| 沭阳县| 乌苏市| 景宁| 肥东县| 息烽县| 万州区| 慈利县| 马边| 鄢陵县| 游戏| 江油市| 江达县| 富裕县| 塔城市| 临洮县| 嫩江县| 筠连县| 江川县| 红原县| 杭锦旗| 富源县| 扎赉特旗| 来安县| 胶州市| 清苑县| 阳西县| 平度市|