Examples of common annotations for spring boot entity classes

Source: Internet
Author: User
Tags json

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.