No identifier specified for entity: main.java.com.sy.entity.User

自己沒怎麼搭建過框架,更何況還是spring mvc的,最近在帶兩個實習生,正好教他們怎麼搭建一個spring mvc的框架,然而我在映射表的時候,提示報錯了。


實體基類:

public class BaseEntity implements Serializable{
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;
    
    @Column(updatable=false)
    protected Date creatTime=new Date();
    
    @Column(updatable=false)
    protected String creatUser;
    
    @Column(insertable=false)
    protected Date updateTime=new Date();
    
    @Column(insertable=false)
    protected String updateUser;

    //get,set方法
}

User類:

@Entity
@Table(name="sys_user")
public class User extends BaseEntity {
    
    private String loginName;
    
    private String userName;
    
    private String password;
    
    //get、set方法
    
}

查閱國外的論壇之後得出一個結論,自己好菜啊!解決辦法特別簡單!!!在實體基類上加一個@MappedSuperclass

<span style="color:#ff0000;">@MappedSuperclass</span>
public class BaseEntity implements Serializable{
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;
    
    @Column(updatable=false)
    protected Date creatTime=new Date();
    
    @Column(updatable=false)
    protected String creatUser;
    
    @Column(insertable=false)
    protected Date updateTime=new Date();
    
    @Column(insertable=false)
    protected String updateUser;

    //get,set方法

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章