【发布时间】:2014-11-02 10:54:18
【问题描述】:
我正在使用 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
当我使用 rest 客户端访问配置文件时;我能够获得带有 id 字段的 json 格式,名称但 ManyToOne 字段没有出现在 json 中,而在控制器中调试时,配置文件列表具有类别值。但它不是以 json 格式出现的。
有什么想法吗?
【问题讨论】:
标签: json spring-boot spring-data-jpa spring-data-rest