欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Springboot JPA注解@Enumerated

程序员文章站 2022-04-23 15:44:56
...

Springboot JPA注解@Enumerated


1.用途
@Enumerated用于标注枚举字段,对应mysql的enum类型


// 源码中支持2种类型
public enum EnumType {
    ORDINAL, // 按照枚举的下标
    STRING;  // 按照枚举的名字

    private EnumType() {
    }
}
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.http.HttpMethod;

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

/**
 * @author Created by 谭健 on 2018/4/20 0020. Friday. 8:56.
 * © All Rights Reserved.
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Slf4j
@Entity
@Table(name = "visit_info")
@DynamicInsert
@DynamicUpdate
public class VisitInfo implements Serializable{


    private static final long serialVersionUID = 6906097418517275871L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long pkId;

    private Date gmtModify;
    private Date gmtCreate;


    private String ip;
    private String location;
    private Long userId;

    @Enumerated(EnumType.STRING)
    private HttpMethod method;

}