Fetching a LONGBLOB as a byte array using MyBatis

懵懂的女人 提交于 2019-11-30 23:39:52

in my project we use blobs this way:

we define a result map for our used class:

<resultMap class="SomeClass" id="SomeClassResultMap">
    <result property="classByteAttribute" column="blobData" />
    <result property="classIdAttribute" column="id" />
</resultMap>

and in the select statement we use this result map

<select id="selectStatement" resultMap="SomeClassResultMap" parameterClass="Integer">
    SELECT * FROM EXAMPLETABLE where id=#id#
</select>

after the execution the blob is in the byte array.

As suggested by duffy the only way to get the result as a byte array is:

Mybatis Version 3.1.+

define a resultMap

<resultMap class="MyClass" id="MyClassMap">
    <result property="myByteArray" column="MYBINARY " />
</resultMap>

<select id="selectStatement"  resultMap="MyClassMap">
        SELECT MYBINARY FROM EXAMPLETABLE
</select>

but,

Mybatis Version 3.0.5

<select id="selectStatement"  resultType="_byte[]">
    SELECT MYBINARY FROM EXAMPLETABLE
</select>

it is a strange regression since mybatis is not able to apply the correct (BlobTypeHandler) TypeHandler, and is not possible to specify the TypeHandler on select tag.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!