枚举类型映射配置(Annotation方式)

package com.vlives.boss.merchant.domain;

@TypeDefs({ @TypeDef(name = "status", typeClass = EnumType.class, parameters = { @Parameter(name = "class", value = "com.vlives.boss.merchant.domain.Merchant$Status") })

})

@Entity

@org.hibernate.annotations.Entity(mutable = false, dynamicUpdate = false, dynamicInsert = false)

@Table(name = "URMTMINF")

public class Merchant extends BaseEntity {

扫描二维码关注公众号,回复: 842177 查看本文章

private String id;

private Merchant parent;

private Set<Merchant> childrens;

private Set<Pos> poses;

private Area area;

private String code;

private String name;

private Status status;

private String shortName;

private String englishName;

private String businessAddress;

private String businessAddressCode;

private String businessTelephone;

public static enum Status implements EnumTypeInterface {

STATUS_ACTIVE(0, "状态1"),

STATUS_DISABLE(1, " 状态2"),

STATUS_DELETE(2, " 状态3");

private int value;

private String desc;

Status(int value, String desc) {

this.value = value;

this.desc = desc;

}

public int getValue() {

return this.value;

}

public String getDesc() {

return this.desc;

}

public static Status get(int value) {

for (Status status : Status.values()) {

if (status.value == value) {

return status;

}

}

throw new IllegalArgumentException("argument error: " + value);

}

}

@Type(type = "status")

@Column(name = "MERC_STS")

public Status getStatus() {

return status;

}

public void setStatus(Status status) {

this.status = status;

}

        //other getter  &&  setter...... 

}






public interface EnumTypeInterface {
public int getValue();
public String getDesc();
}

猜你喜欢

转载自premier9527.iteye.com/blog/1544330