0

我是春天的新手。我有

客户.java

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.annotations.Type;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.vividsolutions.jts.geom.Geometry;

@Entity
public class Customer
{
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   public long id;

   @Column(unique=true)
   @NotNull
   @Size(min = 1)
   public String username;

   static final int MAX_NAME_LENGTH = 255; 
   @Column(length=MAX_NAME_LENGTH)
   @Size(min = 1, max=MAX_NAME_LENGTH)
   @NotNull
   public String name;

   static final int MAX_EMAIL_LENGTH = 64; 
   @Column(length=MAX_EMAIL_LENGTH)
   @Size(min = 1, max=MAX_EMAIL_LENGTH)
   @NotNull
   public String email;

   static final int MAX_MOBILE_LENGTH = 16;
   @Column(length=MAX_MOBILE_LENGTH)
   @Size(min = 1, max=MAX_MOBILE_LENGTH)
   @NotNull
   public String mobile;

   static final int MAX_ADDRESS_LENGTH = 512;
   @Column(length=MAX_ADDRESS_LENGTH)
   @NotNull
   @Size(min = 1, max=MAX_ADDRESS_LENGTH)
   public String address;

   @Column(unique=true)
   @Type(type = "org.hibernate.spatial.GeometryType")
   public Geometry location;

   @OneToMany(targetEntity=OrderItem.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
   @OrderColumn(nullable = false)
   public List<OrderItem> cart = new ArrayList<>();

   @OneToMany(mappedBy="customer")
   public List<Order> orders;

   public static interface Repository extends PagingAndSortingRepository<Customer, Long>
   {
      Customer findByUsername(@Param("username") String username);
   }
}

还有我的 OrderItem.java

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

import org.springframework.data.repository.PagingAndSortingRepository;

@Entity
public class OrderItem
{
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   public long id;

   @ManyToOne
   @NotNull
   public Product product;

   @NotNull
   public int quantity;

   public static interface Repository extends PagingAndSortingRepository<OrderItem, Long>
   {
   }
}

当我运行 hal-browser 到

http://localhost:8080/api/v1/customers/1/cart 以前是返回

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/api/v1/customers/1/cart"
    }
  },
  "_embedded": {
    "orderItems": [
      {
  ....}]}

但是现在在将 spring 的版本更改为 4.2.0.RC3 并将 jackson 版本保持为 2.6.1 之后。_embedded 没有出现在 json 响应中

它的显示像

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/api/v1/customers/1/cart"
    }
  }
}

好心提醒。

4

0 回答 0