【问题标题】:Spring Rest Error: Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODINGSpring Rest 错误:无法加载资源:net::ERR_INCOMPLETE_CHUNKED_ENCODING
【发布时间】:2017-03-27 19:22:44
【问题描述】:

我正在使用带有 spring data 的 rest 服务。当我从单个表中获取数据时,它会以 json 格式返回正确的结果。但是当我在使用休眠的实体之间使用多对多关联时,我得到了一个不可接受的结果,并在 chrome 的控制台中出现以下错误。

Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING

我的结果看起来只有一行重复自己,而且它是一个特别是通过关联在新生成的表中使用的字段。

[{"id":7,"name":"Milk pack","description":"haleeb","imageUrl":"milk.jpg","price":350.00,"category":null,"orderDetail":[]},{"id":8,"name":"oil","description":"olive oil ","imageUrl":"/resources/uploads/olive.png","price":670.00,"category":null,"orderDetail":[{"id":263,"productlist":[{"id":10,"name":"Mobile","description":"awesome design, slim design ","imageUrl":"/static/uploads","price":34569.00,"category":null,"orderDetail":[{"id":263,"productlist":[{"id":10,"name":"Mobile","description":"awesome design, slim design ","imageUrl":"/static/uploads","price":34569.00,"category":null,"orderDetail":[{"id":263,"productlist":[{"id":10,"name":"Mobile","description":"awesome design, slim design ","imageUrl":"/static/uploads","price":34569.00,"category":null,"orderDetail":[{"id":263,"productlist":[{"id":10,"name":"Mobile","description":"awesome design, slim design 
.
.
.and so on

我的实体正在关注

产品表

@ManyToMany(mappedBy = "productlist")
private List<OrderDetail> orderDetail =new ArrayList<OrderDetail>();

订单明细表

@ManyToMany
@JoinTable(
        name="order_detail_productlist",
        joinColumns=@JoinColumn(name="order_detail_id", referencedColumnName="id"),
        inverseJoinColumns=@JoinColumn(name="productlist_id", referencedColumnName="id"))
private Set<Product> productlist = new HashSet<Product>();

我正在使用 spring data jpa 存储库来获取它们

List<Product> findAll();

注意:哪些尚未订购的产品可以正常工作

【问题讨论】:

    标签: spring spring-data spring-data-jpa spring-data-rest


    【解决方案1】:

    您需要所有日志来获取信息,这可能是在使用jackson 时由循环引起的。所以你需要添加@JsonIgnoreProperties。请看http://stackoverflow.com/questions/3325387

    【讨论】:

      【解决方案2】:

      使用 jackson 2.0 文档解决了我的问题

      通过添加以下注解或 OrderDetail 表

      @JsonBackReference
      

      它打破循环并正确显示结果

      【讨论】:

        猜你喜欢
        • 2015-08-17
        • 2014-04-08
        • 2014-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-17
        • 2019-02-03
        • 1970-01-01
        相关资源
        最近更新 更多