Defining User.java Entity Classes
@Data @Entity public class User {@Id @GeneratedValue private Long Id; @Column (nullable = false) private String name; @Co Lumn (nullable = false, unique = true, updatable = False) @JsonProperty (value = "email") Private String username; @Column (nullable = False) @JsonIgnore private String password; @Column (nullable = False) @JsonIgnore private String salt; @Column (nullable = true) private Date birthday; @Column (nullable = false) private String sex; @Column (nullable = True) @JsonFormat (pattern= "Yyyy-mm-dd HH:mm:ss") Private Timestamp access; @Column (nullable = True) @JsonFormat (pattern= "HH:mm:ss") private time accesstime; @Column (nullable = false) private Integer state; @Column (nullable = False, Insertable = false, updatable = False) @JsonFormat (pattern= "Yyyy-mm-dd HH:mm:ss") Private timest AMP created; @Column (nullable = False, Insertable = false, updatable = False) @JsonFormat (pattern= "Yyyy-mm-dd HH:mm:ss") Private timest AMP updated; }
@Data is a Lombok annotation that automatically generates getter,setter,tostring, constructors, etc.
@Entity annotations This is an entity class.
@Table Note Table related, such as aliases, etc.
@Id annotation primary key, @GeneratedValue means auto-generated
@DynamicUpdate, @DynamicInsert annotations generate INSERT, UPDATE statements dynamically, and all updates are generated by default
@Column identifies some field attributes, the field alias, whether it is allowed to be empty, whether it is unique, whether to insert and update (for example, automatic maintenance by MySQL)
@Transient identify the field is not a database field mapping
@JsonProperty defines the Spring JSON alias, ignores the field @JsonIgnore defining the JSON, and formats the JSON when it is defined @JsonFormat