我正在使用 Spring Boot、Spring Data JPA 和 Spring Data Rest 技术开发一个 Web 项目。我能够成功设置所有内容并能够获取简单 POJO 的 JSON。我自定义了两个类以具有 OneToMany 和 ManyToOne 关系,如下所示:-
@Entity
@Table(name="t_profile")
public class Profile {
@Id
@column(name="profile_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
@JoinColumn(name = "cat_id", referencedColumnName = "category_id")
@ManyToOne(optional=false)
private Category category;
// getters and setters
}
@Entity
@Table(name="t_category")
public class Category {
@Id
@column(name="category_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
@OneToMany(mappedBy="category")
private List<Profile> profile;
// getters and setters
}
http://localhost:8080/project/profiles
Run Code Online (Sandbox Code Playgroud)
当我使用休息客户端访问配置文件时;我能够获得带有 id、name …