我正在使用 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
当我使用休息客户端访问配置文件时;我能够获得带有 id、name 字段的 json 格式,但 ManyToOne 字段不是以 json 形式出现,而在控制器中进行调试时,配置文件列表具有类别值。但它不是以 json 形式出现的。
有什么想法吗?
您可以使用@RestResource(exported = false)
in you ManyToOne
field.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)