假设您使用这样的JDL脚本为博客创建了一个jhipster应用程序,您希望有一个blogdto来显示其中的文章(以及一个blogdto来显示每个文章的评论):
entity Blog {
creationDate Instant required
title String minlength(2) maxlength(100) required
}
entity Post {
creationDate Instant required
headline String minlength(2) maxlength(100) required
bodytext String minlength(2) maxlength(1000) required
image ImageBlob
}
entity Comment {
creationDate Instant required
commentText String minlength(2) maxlength(1000) required
}
// RELATIONSHIPS:
relationship OneToMany {
Blog to Post{blog required}
Post{comment} to Comment{post(headline) required}
}
// Set pagination options
paginate all with pagination
// DTOs for all
dto * with mapstruct
// Set service options to all except few
service all with serviceClass
// Filtering
filter *
jhipster将用DTO创建您的博客、帖子和评论实体,并假设您不希望在博客中填充帖子或带有评论的帖子,因此您的bloggmapper将如下所示:
@Mapper(componentModel = "spring", uses = {})
public interface BlogMapper extends EntityMapper<BlogDTO, Blog> {
@Mapping(target = "posts", ignore = true)
Blog toEntity(BlogDTO blogDTO);
default Blog fromId(Long id) {
if (id == null) {
return null;
}
Blog blog = new Blog();
blog.setId(id);
return blog;
}
}
像这样的博客:
public class BlogDTO implements Serializable {
private Long id;
@NotNull
private Instant creationDate;
@NotNull
@Size(min = 2, max = 100)
private String title;
//GETTERS, SETTERS, HASHCODE, EQUALS & TOSTRING
任何人都能帮助修改代码,使blogdto显示文章(postdto显示注释)吗?谢谢
因为我把注释改为包含Postmapper类
@映射器(componentmodel=“spring”,使用postmapper.class)
而@mapping(target=“posts”,ignore=false)为false,但不起作用。API示例(swagger)看起来不错,但postdto为空(即使数据在那里)。