【问题标题】:How to use @Embedded with List in Spring Boot REST如何在 Spring Boot REST 中使用 @Embedded 和 List
【发布时间】:2021-07-29 17:16:00
【问题描述】:

一个项目有多个记录,需要存储在同一个表中。

如何将@Embedded 注释用于List<SomeClassName> someclassName;

@Entity
public class Child {

@Embedded
List<SomeClassName> someclassName;
/** 
* other code .....
*
/
}

JSON 的片段示例如下所示:

{
  "main": {
    "child": [
      {
        "list": [
          {
            "item1": "string",
            "item2": "string"
          }
        ]
      }
    ]
  }
}

【问题讨论】:

    标签: spring-boot spring-data-jpa hibernate-mapping spring-rest


    【解决方案1】:

    根据您的业务逻辑,您不能在同一个表中存储多个项目。您可以使用 @ElementCollection 映射非实体,使用 @OneToMany 映射实体,两者都需要额外的表.

    【讨论】:

      猜你喜欢
      • 2015-12-28
      • 2020-12-11
      • 2019-09-16
      • 2015-12-09
      • 2017-11-06
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      • 2020-09-12
      相关资源
      最近更新 更多