MyBatis:尝试从具有原始 return 类型的方法中 return null

MyBatis: Attempted to return null from a method with a primitive return type

我的数据库连接是mybatis, 我有具有此功能的 DAO:

public int getUpdateTaskStateStart(Task task);

实现位于 XML 文件中:

<select id="getUpdateTaskStateStart" resultType="Integer" parameterType="com.ladpc.mobile.entities.Task">

        SELECT START_UPDATE
        FROM UPDATE_TASK_STATE
            WHERE 
        TASK_ID = #{taskId} AND RASHUT_ID=#{rashutId} 

    </select>

在数据库中,我有 table UPDATE_TASK_STATE,其中包括 START_UPDATE 字段。

我的问题是,当我 运行 getUpdateTaskStateStart(Task)(并发送包含 rashutId="248" 和 taskId="2449" 的任务参数时),我得到错误:

org.apache.ibatis.binding.BindingException: Mapper method 'com.ladpc.mobile.dao.AssesmentTasksDao.getUpdateTaskStateStart attempted to return null from a method with a primitive return type (int).

我的功能有什么问题? 谢谢!

您的映射器 XML 指定 resultType="Integer",但 getUpdateTaskStateTask() 想要 return 原始 int,而不是整数包装器 class。

改为resultType="int"

堆栈跟踪指出,您的方法是 returning "NULL",但该方法具有 "int" return 类型,这是 Java,因此不能 return "NULL" 值。

将方法的 return 类型更改为其包装器 class、"Integer",那么至少异常会消失。

<Select> -> Null, <Update> -> int

org.apache.ibatis.annotations.Select; org.apache.ibatis.annotations.Update;