解决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换一个其它不冲突的名字,问题就解决了。


版权声明:本文为qq_42744046原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。