Spring学习--Spring JPA实体类如何抽取父类
1、基于 Spring I艘绒庳焰nitializr 创建一个SpringBoot应用,必要的依赖包括 Spring Data JPA, H2 数据库 还有 Lombok。工程生成后,导入到 Eclipse 中,并在 application.properties 添加如下配置:# create the table when application starts, # and drop the tables when application stopsspring.jpa.hibernate.ddl-auto=create-drop# output the formatted sql in the consolespring.jpa.properties.hibernate.show_sql=truespring.jpa.properties.hibernate.format_sql=true

2、创建两个实体类图示,两个实体类分别是 Coffee 和 Computer, 他们包含相同的成员变量有 :id, name, createTime, updateTime, 目前在这两个实体类中都包含了这些相同成员变量的定义。

3、运行SpringBoot启动类,观察控制台的输出从控制台的输出可以看出,Spring JPA 为我们定义的两个实体类均创建了对应的表结构,并且包含了所有的字段。

