实体类抽取的公共父类的写法

实体类常存在一些系统字段或者公共字段,那么这个时候我们需要抽取一个父类,方便后期维护。
下面是父类的写法:

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 实体类的基类(系统字段)
 * @date 2020-06-23
 * @author xyp
 */
@Data
@MappedSuperclass
public abstract class YxSystemParent implements Serializable {

    /** 订单id */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", columnDefinition = "int(11) NOT NULL AUTO_INCREMENT COMMENT '主键'")
    @ApiModelProperty(value = "主键")
    @JSONField(serializeUsing = ToStringSerializer.class)
    protected Integer id;

    /** 创建时间 */
    @Column(name = "create_time", columnDefinition = "datetime NOT NULL COMMENT '创建时间'")
    @JSONField(name = "create_time", format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    protected Date createTime;

    /** 创建人 */
    @Column(name = "create_by", columnDefinition = "varchar(128) NOT NULL DEFAULT '' COMMENT '创建用户'")
    @JSONField(name = "create_by")
    @ApiModelProperty(value = "创建用户")
    protected String createBy;

    /** 更新时间 */
    @Column(name = "update_time", columnDefinition = "datetime NOT NULL COMMENT '修改时间'")
    @JSONField(name = "update_time", format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "修改时间")
    protected Date updateTime;

    /** 更新人 */
    @Column(name = "update_by", columnDefinition = "varchar(128) NOT NULL DEFAULT '' COMMENT '修改用户'")
    @JSONField(name = "update_by")
    @ApiModelProperty(value = "修改用户")
    protected String updateBy ;

    /** 删除标识 */
    @JSONField(name = "del_flag")
    @Column(name = "del_flag", columnDefinition = "tinyint(1) default '0' comment '删除(0.未删除,1:已删除)'")
    @ApiModelProperty(value = "删除(0.未删除,1:已删除)")
    protected String delFlag ;
}

下面是子类的写法:

/**
* @date 2020-05-27
*/
@Entity
@Data
@Table(name="ib_payment_order")
public class IbPaymentOrder extends YxSystemParent implements Serializable {

    /** 付款银行 */
    @Column(name = "paying_bank",nullable = false)
    @NotBlank
    private String payingBank;

    /** 付款人 */
    @Column(name = "drawee",nullable = false)
    private String drawee;
}

你可能感兴趣的:(Java)