定义User.java实体类
- @Data
- @Entity
- public class User {
- @Id
- @GeneratedValue
- private Long id;
-
- @Column(nullable = false)
- private String name;
-
- @Column(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 Timestamp created;
-
- @Column(nullable = false, insertable = false, updatable = false)
- @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
- private Timestamp updated;
- }
-
@Data 是 lombok 的注解,自动生成Getter,Setter,toString,构造函数等
-
@Entity 注解这是个实体类
-
@Table 注解表相关,如别名等
-
@Id 注解主键,@GeneratedValue 表示自动生成
-
@DynamicUpdate,@DynamicInsert 注解可以动态的生成insert、update 语句,默认会生成全部的update
-
@Column 标识一些字段特性,字段别名,是否允许为空,是否唯一,是否进行插入和更新(比如由MySQL自动维护)
-
@Transient 标识该字段并非数据库字段映射
-
@JsonProperty 定义 Spring JSON 别名,@JsonIgnore 定义 JSON 时忽略该字段,@JsonFormat 定义 JSON 时进行格式化操作