目前我有一个使用Spring Data REST的Spring Boot应用程序.我有一个与另一个域实体Post有@OneToMany关系的域实体Comment.这些类的结构如下:
Post.java:
@Entity
public class Post {
@Id
@GeneratedValue
private long id;
private String author;
private String content;
private String title;
@OneToMany
private List<Comment> comments;
// Standard getters and setters...
}
Run Code Online (Sandbox Code Playgroud)
Comment.java:
@Entity
public class Comment {
@Id
@GeneratedValue
private long id;
private String author;
private String content;
@ManyToOne
private Post post;
// Standard getters and setters...
}
Run Code Online (Sandbox Code Playgroud)
他们的Spring Data REST JPA存储库是以下基本实现CrudRepository:
PostRepository.java:
public interface PostRepository extends CrudRepository<Post, Long> …Run Code Online (Sandbox Code Playgroud)