【发布时间】:2021-05-21 01:35:20
【问题描述】:
它们有 5 个实体和各自的 JPA 存储库。在服务类和控制器上实现,以 POST 数据库中的数据。
数据库映射和结构是:
实体 2、3、5 与实体 1 具有 一对一 关系(映射)。
实体 3 和 4 具有一对多
以下是请求正文格式。
{
"prpoperty1": "",
"prpoperty2": "", entity1 (main)
"prpoperty3": " ",
"entity2": {
"prpoperty1": "",
"prpoperty2": "",
},
"entity3": {
"prpoperty1": "",
"prpoperty2": ""
"entity4": [
{
"prpoperty1": "", **(NULL IN DATA BASE)**
"prpoperty2": "" **(NULL IN DATA BASE)**
},
{
"prpoperty1": "", (NULL IN DATA BASE)
"prpoperty1": "" (NULL IN DATA BASE)
}
]
},
"entity5": {
"prpoperty1": "",
"prpoperty1": "",
}
}
在服务类中使用 entity1 设置和保存数据。(来自该类的 sn-p)
@Transactional
public ResponseEntity<Object> storeSomething(Entity1 entity){
Entity1 entity1 = new Entity1();
entity1.set...(entity.get...());
entity1.set....(entity.get.....());
ServiceR sObj = sRepository.save(entity1);
if (sRepository.findById(sObj.getId()).isPresent()) {
return ResponseEntity.accepted().body("Successfully Created ");
} else
return ResponseEntity.unprocessableEntity().body("Failed to Create");
}
我的问题是:如何以给定的请求正文格式存储实体 4 的值?
【问题讨论】:
标签: java spring spring-boot jpa spring-data-jpa