本文介绍了如何使用MyBatis从BYtea列中获取byte []?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下方法.

这是查询映射:

<select id="getTypicalTaskMeasurementParameterValue"
            parameterType="Integer"
            resultType="byte[]">
    SELECT value
    FROM typical_task_measurements_parameter_values
    WHERE id_typical_task_measurement = #{typicalTaskMeasurementId}
</select>

这是方法:

public byte[] getTypicalTaskMeasurementParameterValue(
    Integer typicalTaskMeasurementId);

这是我尝试对它运行单元测试时遇到的错误:

And here is the error I got, trying to run the unit test against it:

nested exception is org.apache.ibatis.reflection.ReflectionException:
Error instantiating class [Ljava.lang.Byte; with invalid types () or values ().
Cause: java.lang.NoSuchMethodException: [Ljava.lang.Byte;.<init>()
at ...

此外,此bytea员工的设置方法还可以.

Moreover, setter method for this bytea staff is ok.

推荐答案

该错误消息很好地说明了问题. java.lang.Byte上没有默认构造函数.

The error message says the problem pretty well. There is no default constructor on java.lang.Byte.

您需要一个结果图,该结果图将选择要使用的构造函数,或实现自己的TypeHandler.

You need a result map that will choose which constructor to use, or implement your own TypeHandler.

这篇关于如何使用MyBatis从BYtea列中获取byte []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 09:25