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

枚举类型

程序员文章站 2022-07-12 23:15:02
...

枚举类型实例

枚举实体

public enum AuthorityType {
不可见, 
只读,
可读写
}

权限实体

@Entity
@Table(name = "Permission")
 public class Permission extends BaseEntity {
private static final long serialVersionUID = -5067770823940934837L;
/**
 * 角色
 */
private Role role;
/**
 * 模块信息
 */
private ModelResources model;

/**
 * 权限
 */
private AuthorityType authorityType;

/**
 * 附加属性
 */
private String  attachAttr;

@JsonIgnore
@ManyToOne(fetch=FetchType.LAZY)
public Role getRole() {
	return role;
}

public void setRole(Role role) {
	this.role = role;
}

**@Enumerated(EnumType.ORDINAL)**
@Column()
public AuthorityType getAuthorityType() {
	return authorityType;
}

public void setAuthorityType(AuthorityType authorityType) {
	this.authorityType = authorityType;
}

public String getAttachAttr() {
	return attachAttr;
}

public void setAttachAttr(String attachAttr) {
	this.attachAttr = attachAttr;
}


@ManyToOne(fetch=FetchType.LAZY)
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 
public ModelResources getModel() {
	return model;
}

public void setModel(ModelResources model) {
	this.model = model;
}
}

@Enumerated(EnumType.ORDINAL) 采用枚举类型的序号值与数据库进行交互
序号从零开始
赋值方式 :permissionmodel.setAuthorityType(AuthorityType.不可见);

相关标签: 枚举