情怀。721 2022-09-02 23:58 采纳率: 100%
浏览 21
已结题

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这个类型

  • 写回答

2条回答 默认 最新

  • nssnail 2022-09-03 00:50
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月11日
  • 已采纳回答 9月3日
  • 创建了问题 9月2日

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装