当前位置:Gxlcms >
数据库问题 >
spring-data-jpa实体类继承抽象类如何映射父类的属性到数据库
spring-data-jpa实体类继承抽象类如何映射父类的属性到数据库
时间:2021-07-01 10:21:17
帮助过:119人阅读
public class Pet {
private Integer id;
private String name;
private String variety;
private double weight;
private Integer age;
private char vaccine;
private Integer ownerId;
private char LookingForOwner;
private String pic;
@Id
@GeneratedValue
public String getPic() {
return pic;
}
/剩下的get set方法省略
子类直接继承抽象父类并加上@Entity注解
并用@Table(name = "t_dog")指明映射的表
@Entity
@Table(name = "t_dog")
public class Dog extends Pet{
public Dog() {
}
}
此时运行项目生成的表中有父类中的属性,并且id作为自增主键