我正在编写简单的spring-boot应用程序,并希望对其进行测试。我有User
课程:
@Entity
@Table(name = "users")
@NoArgsConstructor
@AllArgsConstructor
public class User extends AbstractEntity {
public enum Type {
ADMIN, USER
}
@Getter
@Setter
private Type type;
@Getter
@Setter
private String username;
@Getter
@Setter
private String password;
@ManyToMany(mappedBy = "managers")
@Getter
@Setter
private Set<Label> label;
}
和Label
类(认为它是一个组织,其中User
有效):
@Entity
@Table(name = "labels")
@NoArgsConstructor
@AllArgsConstructor
public class Label extends AbstractEntity {
@Getter
@Setter
private String title;
@OneToOne
@Getter
@Setter
private User creator;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "label_managers")
@Getter
@Setter
private Set<User> managers;
}
这些实体由@RepositoryRestResource
s。
我应该在MockMvc
的测试中写一下User
和Label
之间的关系?
答案 0 :(得分:0)
&#34;使用&#34; Content-Type:text / uri-list&#34;而不是JSON,可以&#34;添加&#34;带有PUT的集合的资源并传入URI。您可以使用DELETE删除资源。&#34;
查看以下问题的答案:How to add elements in a many-to-many relationship via Spring's @RepositoryRestResource REST API?