embed - 获取一侧时,我可以将 Spring Data Rest/JPA 双向 OneToMany 的多侧嵌入为数组吗
问题描述
我正在使用双向映射探索 Spring Data Rest。我有两张桌子为了清楚起见一张和很多 一张桌子
@OneToMany( mappedBy = "one")
@JsonBackReference
List<Many> many;
许多表
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JsonManagedReference
@RestResource(exported = false)
@JoinColumn(name = "one_id")
One one;
正如预期的那样,当我使用 localhost:8080/manies 时,嵌入了 One 引用
"manies": [
{
"rack": "GF",
"shelf": "2",
"one": {
"producer": "Escarpment",
"name": "Kupe"
},
"_links": {
"self": {
"href": "http://localhost:8080/manies/1"
},
"many": {
"href": "http://localhost:8080/manies/1"
}
}
},
我想知道是否有任何方法可以对 localhost:8080/ones 执行相同的操作,即嵌入许多数组 当我尝试时,我只能返回一个链接
"ones": [
{
"producer": "Escarpment",
"name": "Kupe",
"_links": {
"self": {"href": "http://localhost:8080/ones/1"},
"one": {"href": "http://localhost:8080/ones/1"},
**"many": {"href": "http://localhost:8080/ones/1/many"}**
}
},
解决方案
推荐阅读
- javascript - Javascript Connect 4 Minimax 和 Alpha-Beta 修剪不起作用
- javascript - D3:无法使用 PHP 从数据库加载 json 数据
- linux - 如何在没有像 weston 这样的平台的情况下从终端启动 qt Wayland 合成器
- .net - 具有 SQL Server 凭据的数据库优先实体框架?
- java - 如何在实体JPA中初始化其他字段大小的字段
- android - 如何使用 xml 设置浮动操作按钮的按钮状态?
- bluetooth - BlueZ 远程设备存在
- javascript - django 博客中的计数问题:使用 django ajax
- laravel - 为什么当我使用独特的方法时我不能用 faker 创建假数据
- selenium - 如何使用 Cucumber 和 JUnit 生成 Allure 报告?