Java 使用xml文件配置更新数据库数据发生java.lang.Integer cannot be cast to java.util.Collection错误

Java 使用xml文件配置更新数据库数据发生java.lang.Integer cannot be cast to java.util.Collection错误

xml的配置(采用的是注解类型注入参数,所以没加parameterType)

<update id="updateAccountCollection" >
        update app_account AS ac
        <set>
            <if test="display != null">
                ac.display = #{display},
            if>
            ac.collection = #{collection}
        set>
        where ac.id = #{id}
update>

其中display、collection两个字段在数据库的类型为tinyint(2),在实体类中两个字段的类型为Integer

mapper代码


//更新收藏、是否显示
    void updateAccountCollection(@Param("display")int display,@Param("collection")int collection,@Param("id")Long id);

报错日志

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.Collection
### The error may exist in class path resource [mapper/ResourceMapper.xml]
### The error may involve com.selfcare.mapper.ResourceMapper.updateAccountCollection
### The error occurred while executing an update
### Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.Collection


请问,这种报错该怎么解决啊?

知道是数据类型无法强制转换,但是我反找了一遍,也没找到是哪里用到了java.util.Collection这个类型

Collection换个名字吧,可能关键字冲突了

在xml第一行,增加一个返回值类型,resultType=java.lang.Integer,然后你的更新方法,也加上int类型的返回值,不要用void