📄 resource.java
字号:
/**
*
*/
package com.javaeye.sample.entity;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Transient;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
/**
* @author Downpour
*/
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Resource {
@Id
@GeneratedValue
private Integer id;
private String type;
private String value;
@ManyToMany(mappedBy = "resources", targetEntity = Role.class, fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Set<Role> roles;
/**
* The default constructor
*/
public Resource() {
}
/**
* Get role authorities as string
*
* @return
*/
@Transient
public String getRoleAuthorities() {
List<String> roleAuthorities = new ArrayList<String>();
for(Role role : roles) {
roleAuthorities.add(role.getName());
}
return StringUtils.join(roleAuthorities, ",");
}
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @return the type
*/
public String getType() {
return type;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @return the roles
*/
public Set<Role> getRoles() {
return roles;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @param type the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* @param roles the roles to set
*/
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -