Mybatis對MySQL中BLOB字段的讀取


1、在sqlMapConfig中,定義一個typeHandlers

<typeHandlers>
<typeHandler jdbcType="BLOB" javaType="byte[]" handler="org.apache.ibatis.type.BlobTypeHandler"/>
</typeHandlers>

2、在mapper里面定義resultmap的result column

<result column="token" property="token" jdbcType="BLOB"  typeHandler="org.apache.ibatis.type.BlobTypeHandler" />

3、在對應的entity中,將這個字段定義成byte[]類型的就行。

在使用的時候將byte[]轉為String就OK了

String correcttoken = new String(userToken.getToken(),"ISO-8859-1");

總結,在Mybatis的官方文檔中說明了,框架內置的TypeHandler類型。請參見http://mybatis.github.io/mybatis-3/zh/configuration.html#typeHandlers。同時Mybatis支持自定義typeHandler。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM