ssh框架搭建出现的异常: class com.my.entity.user not found while looking for property: id

在处理用户注册的时候,user实体的bean创建不出来,原代码如下:

<class name="com.my.entity.User" table="user">
           <!-- name:指定Product类中的属性名
                column:指定为id的字段名 
                generator:生成策略为本地(默认自动增长)
           -->
        <id name="id" column="id">
            <generator class="native"/><!-- 主键生成机制,自动根据本地的情况生成 -->
        </id>
        <property name="username" column="username" length="20"/>
        <property name="password" column="password"/>
    </class>

在网上查找前辈的经验,有一个例子说要加上属性的类型:

<class name="com.my.entity.User" table="user">
           <!-- name:指定Product类中的属性名
                column:指定为id的字段名 
                generator:生成策略为本地(默认自动增长)
           -->
        <id name="id" column="id"  type="java.lang.Integer">
            <generator class="native"/><!-- 主键生成机制,自动根据本地的情况生成 -->
        </id>
        <property name="username" column="username" length="20" type="java.lang.String"/>
        <property name="password" column="password" length="20" type="java.lang.String"/>
    </class>

结果还是报错:然后又查到一个可能的原因是我改过实体类的id的类型,将int改为了Integer,但是下面的set方法可能没改对,然后就重写了一遍get,set方法,然后就可以正常运行了,下次写数据类型的时候,一定要谨慎,避免这种中途更换带来的不必要的bug;

    

学如逆水行舟,不进则退
原文地址:https://www.cnblogs.com/anningkang/p/8442870.html