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接口:CommentRepositorypublic interface CommentRepository extends JpaRepository<Comment,Integer> { } -
测试
最后
以上就是要减肥小懒虫最近收集整理的关于springboot框架学习积累---SpringBoot数据访问-整合JPA的全部内容,更多相关springboot框架学习积累---SpringBoot数据访问-整合JPA内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复