1、导语(可跳过)
Java小白一枚,研读公司代码。发现实体类上加了@Builder、@NoArgsConstructor和@AllArgsConstructor。话不多说,上代码
2、实体类代码@Data
@EqualsAndHashCode(callSuper = false)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value="TOrder对象", description="交易订单表")
public class TOrder implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "门店ID")
private String commercialId;
@ApiModelProperty(value = "订单ID")
@TableId(value = "order_id", type = IdType.ASSIGN_UUID)
private String orderId;
@ApiModelProperty(value = "订单编号")
private String tradeNo;
/**
* 省略部分成员变量(公司代码直接CV)
*/
@ApiModelProperty(value = "订单来源")
private Long source;
@ApiModelProperty(value = "订单来源名称")
private String sourceName;
@ApiModelProperty(value = "商户实收金额")
private BigDecimal receivedAmount;
@ApiModelProperty(value = "用户实付金额")
private BigDecimal custRealPay;
@ApiModelProperty(value = "订单原始金额")
private BigDecimal tradeAmount;
@ApiModelProperty(value = "优惠总金额")
private BigDecimal privilegeAmount;
@TableField(exist = false)
private String commercialName;
/**
* 清分金额
*/
@ApiModelProperty(value = "清分金额")
private BigDecimal divideAmount;
/**
* 清分金额
*/
@ApiModelProperty(value = "清分金额")
@TableField(exist = false)
private String userId;
}
注意:此实体类中并未写任何构造器函数!但是却可以生成一个有参构造器。
3、实际运用
TOrder order = TOrder.builder()
.orderId(s)标签:String,Builder,value,ApiModelProperty,private,简单,注解,BigDecimal From: https://www.cnblogs.com/ydy-blog/p/17407582.html
.divideAmount(sum)
.build();
这就是用了@Builder 注解的快捷方便的地方。
4、补充
根据查询到的知识,一般@NoArgsConstructor 和 @AllArgsConstructor 注解配合@Builder 注解一起使用