jpa一对多查询结果有问题

问题遇到的现象和发生背景

jpa一对多查询,结果值总是多一层

用代码块功能插入代码,请勿粘贴截图

这是一表,一个文章对应多条评论

@Entity
@Data
@Table(name = "article")

public class Article {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "article_name")
    private String articleName;

    @OneToMany(mappedBy = "article",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JsonIgnoreProperties("article")
    private List<Comment> comments;

}
@Entity
@Data
@Table(name = "comment")
public class Comment {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "article_id",insertable = false,updatable = false)
    private int articleId;

    @Column(name = "content")
    private String content;

    @Column(name = "author")
    private String author;

    @ManyToOne
    @JoinColumn(name = "article_id")
    private Article article;

}
运行结果及报错内容
{
    "id":2,
    "articleId":2,
    "content":"content for bbb",
    "author":"author2",
    "article":{
        "id":2,
        "articleName":"bbb",
        "comments":[
            {
                "id":2,
                "articleId":2,
                "content":"content for bbb",
                "author":"author2"
            },
            {
                "id":3,
                "articleId":2,
                "content":"content also for bbb",
                "author":"author3"
            },
            {
                "id":4,
                "articleId":2,
                "content":"content2 also for bbb",
                "author":"author4"
            }
        ]
    }
}

我想要达到的结果
{"id":2,
        "articleName":"bbb",
        "comments":[
            {
                "id":2,
                "articleId":2,
                "content":"content for bbb",
                "author":"author2"
            },
            {
                "id":3,
                "articleId":2,
                "content":"content also for bbb",
                "author":"author3"
            },
            {
                "id":4,
                "articleId":2,
                "content":"content2 also for bbb",
                "author":"author4"
            }
        ]
}

重写toString方法

你的查询sql怎么写的呢,是查询直接返回的数据有问题,还是查询之后又组装的数据有问题

有点没理解 如果你想返回下边的数据的话 数据不是已经返回到前端了吗 可以自己查出来article当中的数据啊。 如果想单纯返回报错内容当中的article 这个得看一下你的代码是怎么写的了