订单项目如何公开?

时间:2017-11-14 08:26:35

标签: spring-data-rest

在restbucks项目中,订单包含一个私人的订单项列表。在获得单个订单时,我无法弄清楚这个字段是如何通过rest api公开的。它没有公共吸气剂或任何东西。是mixins吗?

1 个答案:

答案 0 :(得分:0)

@Data@NoArgsConstructor@AllArgsConstructor@EqualsAndHashCodeLombok annotations,用于自动生成样板代码。

@Data
@Entity
@NoArgsConstructor(force = true)
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class LineItem extends AbstractEntity {

  private final String name;
  private final int quantity;
  private final Milk milk;
  private final Size size;
  private final MonetaryAmount price;

  public LineItem(String name, MonetaryAmount price) {
    this(name, 1, Milk.SEMI, Size.LARGE, price);
  }
}

您可以将此代码与已删除的代码进行比较(欢迎使用Lombok-funs俱乐部)):

@Entity
public class LineItem extends AbstractEntity {

    private final String name;
    private final int quantity;
    private final Milk milk;
    private final Size size;
    private final MonetaryAmount price;

    public LineItem(String name, MonetaryAmount price) {
        this(name, 1, Milk.SEMI, Size.LARGE, price);
    }

    public LineItem(String name, int quantity, Milk milk, Size size, MonetaryAmount price) {
        this.name = name;
        this.quantity = quantity;
        this.milk = milk;
        this.size = size;
        this.price = price;
    }

    public LineItem() {
        this.name = null;
        this.quantity = 0;
        this.milk = null;
        this.size = null;
        this.price = null;
    }

    public String getName() {
        return this.name;
    }

    public int getQuantity() {
        return this.quantity;
    }

    public Milk getMilk() {
        return this.milk;
    }

    public Size getSize() {
        return this.size;
    }

    public MonetaryAmount getPrice() {
        return this.price;
    }

    public String toString() {
        return "LineItem(name=" + this.getName() + ", quantity=" + this.getQuantity() + ", milk=" + this.getMilk() + ", size=" + this.getSize() + ", price=" + this.getPrice() + ")";
    }

    public boolean equals(Object o) {
        if (o == this) return true;
        if (!(o instanceof LineItem)) return false;
        final LineItem other = (LineItem) o;
        if (!other.canEqual((Object) this)) return false;
        final Object this$name = this.getName();
        final Object other$name = other.getName();
        if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
        if (this.getQuantity() != other.getQuantity()) return false;
        final Object this$milk = this.getMilk();
        final Object other$milk = other.getMilk();
        if (this$milk == null ? other$milk != null : !this$milk.equals(other$milk)) return false;
        final Object this$size = this.getSize();
        final Object other$size = other.getSize();
        if (this$size == null ? other$size != null : !this$size.equals(other$size)) return false;
        final Object this$price = this.getPrice();
        final Object other$price = other.getPrice();
        if (this$price == null ? other$price != null : !this$price.equals(other$price)) return false;
        return true;
    }

    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $name = this.getName();
        result = result * PRIME + ($name == null ? 43 : $name.hashCode());
        result = result * PRIME + this.getQuantity();
        final Object $milk = this.getMilk();
        result = result * PRIME + ($milk == null ? 43 : $milk.hashCode());
        final Object $size = this.getSize();
        result = result * PRIME + ($size == null ? 43 : $size.hashCode());
        final Object $price = this.getPrice();
        result = result * PRIME + ($price == null ? 43 : $price.hashCode());
        return result;
    }

    protected boolean canEqual(Object other) {
        return other instanceof LineItem;
    }
}