相关疑难解决方法(0)

关联,聚合和组合有什么区别?

关联,聚合和组合有什么区别?请解释一下实施情况.

oop uml associations composition aggregation

361
推荐指数
18
解决办法
34万
查看次数

如何通过Spring的@RepositoryRestResource REST API在多对多关系中添加元素?

我无法弄清楚如何使用@RepositoryRestResource接口在两个相当简单的实体之间创建多对多关系.

例如,我有一个简单的父子实体关系,如下所示:

@Entity
public class ParentEntity {
    @Id
    @GeneratedValue
    private Long id;

   @ManyToMany
   private List<ChildEntity> children;
}

@Entity
public class ChildEntity {
    @Id
    @GeneratedValue
    private Long id;

    @ManyToMany(mappedBy="children")
    private List<ParentEntity> parents;
}
Run Code Online (Sandbox Code Playgroud)

我的存储库正在使用vanilla Spring @RepositoryRestResource HATEOS API:

@RepositoryRestResource(collectionResourceRel = "parents", path = "parents")
public interface ParentRepository extends PagingAndSortingRepository<ParentEntity, Long> {
}

@RepositoryRestResource(collectionResourceRel = "children", path = "children")
public interface ChildRepository extends PagingAndSortingRepository<ChildEntity, Long> {
}
Run Code Online (Sandbox Code Playgroud)

我已成功使用POST来创建单独的ParentEntity和ChildEntity,但我似乎无法弄清楚如何使用内置接口PUT/PATCH两者之间的关系.

看起来我应该能够使用PUT将JSON发送到类似的东西http://localhost:8080/api/parents/1/children,但到目前为止,我找不到一个有效的结构.

java spring spring-data-rest

5
推荐指数
1
解决办法
5574
查看次数