我想为我的Spring Boot Rest Controller创建DTO。 我有实体用户,俱乐部和两个实体ClubMember的关联。
@Entity
class User {
@Id
private long id;
private String name;
private List<ClubMember> clubMembers = new ArrayList<>();
}
@Entity
class Club {
@Id
private long id;
private String name;
private List<User> members = new ArarryList<>();
}
@Entity
@AssociationOverrides({
@AssociationOverride(name = "pk.club", joinColumns = @JoinColumn(name = "club_id")),@AssociationOverride(name = "pk.user", joinColumns = @JoinColumn(name = "user_id")) })
class ClubMember implements Serializable {
//
}
现在我创建一个UserDto:
class UserDto {
private long id;
private List<ClubDto> clubs;
}
class ClubDto {
private long id;
}
所以我想映射两个列表:ClubMember列表到ClubDto列表。
我应该那样做吗
mapper.map(Club.class, ClubDto.class).byDefault().register();
mapper.map.(ClubMember.class, ClubDto.class)
.field("pk.club.id", "id")... **i should list all the properties? Is there another solution?**
谢谢。