解决MyBatis中 Could not set property ~ o f ~异常

解决MyBatis中 Could not set property ~ of ~

public class Role {
    private Integer id;   //id
    private String roleCode; //角色编码
    private String roleName; //角色名称
    private Integer createdBy; //创建者
    private Date creationDate; //创建时间
    private Integer modifyBy; //更新者
    private Date modifyDate;//更新时间
    private List<User> userList;//用户列表
}

这个是我的pojo类,对应的Dao.xml如下:

 <resultMap type="User" id="userRoleResult">
        <id property="id" column="id"/>
        <result property="userCode" column="userCode" />
        <result property="userName" column="userName" />
        <result property="userRole" column="userRole" />
        <association property="role" javaType="Role" >
            <id property="id" column="r_id"/>
            <result property="roleCode" column="roleCode"/>
            <result property="roleName" column="roleName"/>
        </association>
</resultMap>

    

大家可以忽略代码的功能,这里是错误的代码示范。我报的问题原因是不能设置Role属性,换句话说,就是不能初始化Role对象。

我的解决方案,由于Role和包中的一个类冲突,造成不能赋值,发生错误。所以可以将Role换一个其它不冲突的名字,问题就解决了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"nested exception is org.apache.ibatis.reflection.ReflectionException: Could not set property"这个异常MyBatis在设置属性时发生的反射异常。这个异常通常发生在设置属性值时传入的参数类型与属性类型不匹配的情况下。根据引用的错误信息,异常是由于无法将值'1539102131662880769'赋给属性'id',导致反射异常。 为了解决这个问题,你可以检查变量类型是否正确。确保传入的参数类型与属性类型一致。另外,还可以检查是否在配置文件正确设置了主键自增的方式,以确保在插入数据时能够正确生成主键值。引用提到的配置可以尝试添加到MyBatis的配置文件,确保使用数据库的主键自增方式。 如果仍然无法解决该问题,你可以查看其他相关资料,了解更多关于这个异常的处理方法,引用提供的文章可能会对你有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [nested exception is org.apache.ibatis.reflection.ReflectionException: Could not set property ‘id‘ ...](https://blog.csdn.net/m0_45877477/article/details/125388756)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法](https://download.csdn.net/download/weixin_38524871/12828533)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值