springboot框架学习积累—SpringBoot数据访问-整合JPA
1. SpringBoot整合JPA
-
引入依赖启动器
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
-
编写ORM实体类
@Entity @Table(name = "t_comment") public class Comment { @Id //表明映射主键id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; //评论id private String content; //评论内容 private String author; //评论作者 @Column(name = "a_id") private Integer aId; //外键:表示当前这条评论是属于那篇文章
-
编写Repository接口:CommentRepository
public interface CommentRepository extends JpaRepository<Comment,Integer> { }
-
测试