SpringBoot整合JPA的步骤
1.添加Jpa依赖
<!-- springboot-jpa组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
2.创建映射数据库的Entity
实体类实现Serializable 接口
关联主键: 主键get方法上添加注解 @Id 和 @GenerateValue
3.Dao层创建接口类并继承JpaRepository,并添加相应的泛型
4.Service层调用Dao层的接口,Controller层调用Service层的接口
5.启动类添加JPA扫描注解
@EnableJpaRepository(“dao层的包名”)
@EntityScan(“实体类包名”)