JPA一對多,多對一映射

@Entity
@ApiModel(value = "ClearOrder", description = "清關單據對象")
@Table(name = "orde_clear_order")
@DynamicInsert
@DynamicUpdate
@Data
public class ClearOrder extends BaseEntity {
    public static final String TABLE_NAME = "orde_clear_order";

    @ApiModelProperty(name = "insideNo", value = "訂單號")
    @Column(name = "inside_no", nullable = true, length = 50)
    private String insideNo;

    @ApiModelProperty(name = "deliveryNo", value = "國外派送單號")
    @Column(name = "delivery_no", nullable = true, length = 50)
    private String deliveryNo;

    @ApiModelProperty(name = "shipper", value = "發貨人信息(地址/姓名/電話)")
    @Column(name = "shipper", nullable = true, length = 200)
    private String shipper;

    @ApiModelProperty(name = "consignee", value = "收件人信息(地址/姓名/電話)")
    @Column(name = "consignee", nullable = true, length = 200)
    private String consignee;

    @ApiModelProperty(name = "originName", value = "出發地名稱")
    @Column(name = "origin_name", nullable = true, length = 255)
    private String originName;

    @ApiModelProperty(name = "originNo", value = "出發地編碼")
    @Column(name = "origin_no", nullable = true, length = 50)
    private String originNo;

    @ApiModelProperty(name = "destinationName", value = "目的國名稱")
    @Column(name = "destination_name", nullable = true, length = 255)
    private String destinationName;

    @ApiModelProperty(name = "destinationNo", value = "目的國編碼")
    @Column(name = "destination_no", nullable = true, length = 50)
    private String destinationNo;

    @ApiModelProperty(name = "invoiceDate", value = "發票日期")
    @Column(name = "invoice_date", nullable = true, length = 50)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date invoiceDate;

    @ApiModelProperty(name = "invoiceNumber", value = "發票號碼")
    @Column(name = "invoice_number", nullable = true, length = 50)
    private String invoiceNumber;

    @ApiModelProperty(name = "remarks", value = "訂單備註")
    @Column(name = "remarks", nullable = true, length = 255)
    private String remarks;

    @ApiModelProperty(name = "totalCbm", value = "體積總計(立方米)")
    @Column(name = "total_cbm", nullable = true, length = 10)
    private Float totalCbm;

    @ApiModelProperty(name = "status", value = "訂單狀態")
    @Column(name = "status", nullable = true, length = 10)
    @Enumerated(value = EnumType.STRING)
    private ClearOrderStatusEnum status;

    @ApiModelProperty(name = "boxList", value = "箱子集合")
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name="clear_order_id",referencedColumnName = "id")
    private List<ClearBox> boxList;

    @ApiModelProperty(name = "goodsList", value = "貨物集合")
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name="clear_order_id",referencedColumnName = "id")
    @FieldSerializer.Optional("ignore")
    private List<ClearGoods> goodsList;
}

2.ide

@Entity
@ApiModel(value = "ClearGoods", description = "物品對象")
@Table(name = "orde_clear_goods")
@DynamicInsert
@DynamicUpdate
@Data
public class ClearGoods extends BaseEntity {
    public static final String TABLE_NAME = "orde_clear_goods";

    /*@ApiModelProperty(name = "clearOrderId", value = "清關單據ID")
    @Column(name = "clear_order_id", nullable = true, length = 32)
    private String clearOrderId;*/

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "clear_order_id", nullable = false)
    @FieldSerializer.Optional("ignore")
    private ClearOrder clearOrder;

    @ApiModelProperty(name = "markNumbers", value = "編號(通常爲空)")
    @Column(name = "mark_numbers", nullable = true, length = 32)
    private String markNumbers;

    @ApiModelProperty(name = "description", value = "描述")
    @Column(name = "description", nullable = true, length = 255)
    private String description;

    @ApiModelProperty(name = "quantity", value = "貨物數量")
    @Column(name = "quantity", nullable = true, length = 10)
    private Integer quantity;

    @ApiModelProperty(name = "unitPrice", value = "貨物單價")
    @Column(name = "unit_price", nullable = true, columnDefinition = "decimal(17,2) default '0.00'")
    private BigDecimal unitPrice;

    @ApiModelProperty(name = "amount", value = "貨物總價")
    @Column(name = "amount", nullable = true, columnDefinition = "decimal(17,2) default '0.00'")
    private BigDecimal amount;
}
相關文章
相關標籤/搜索