如何在@RestController中修复Error ManyToMany?

时间:2018-11-20 19:17:38

标签: spring-boot spring-data-jpa

我是实体故事:

@Entity
@Table(name = "story", schema = "")
@Data
public class Story implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "sID", unique = true, nullable = false)
    private Long sID;
    @Column(name = "vnName", nullable = false)
    private String vnName;
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinTable(name = "_scategory",
            joinColumns = {@JoinColumn(name = "sID", nullable = false)},
            inverseJoinColumns = {@JoinColumn(name = "cID", nullable = false)})
    private List<Category> categoryList;
}

和实体类别:

@Entity
@Table(name = "category", schema = "", uniqueConstraints = {@UniqueConstraint(columnNames = {"cMetatitle"}),
        @UniqueConstraint(columnNames = {"cName"})})
@Data
public class Category implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "cID", unique = true, nullable = false)
    private Integer cID;
    @Column(name = "cName", unique = true, nullable = false, length = 150)
    private String cName;
    @ManyToMany(mappedBy = "categoryList")
    private List<Story> storyList;
}

但是当我在RestController中获取Story时,会收到以下错误消息:

  

警告http-nio-8080-exec-9   o.s.w.s.m.s.DefaultHandlerExceptionResolver:234-尝试时失败   解决异常   [org.springframework.http.converter.HttpMessageNotWritableException]   java.lang.IllegalStateException:无法在调用之后调用sendError()   响应已提交

有人可以教我如何解决它吗?谢谢!

0 个答案:

没有答案