溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發布時間:2020-10-15 16:07:01 來源:腳本之家 閱讀:212 作者:icyfox_bupt 欄目:開發技術

開發環境: 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[]類內容請搜索億速云以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持億速云!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女