某些Entity返回不应该被修改的属性时使用guava的ImmutableList
This commit is contained in:
+3
-2
@@ -1,6 +1,5 @@
|
||||
package org.springside.examples.quickstart.entity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
@@ -12,6 +11,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
//JPA标识
|
||||
@Entity
|
||||
@@ -87,7 +87,8 @@ public class User extends IdEntity {
|
||||
@Transient
|
||||
@JsonIgnore
|
||||
public List<String> getRoleList() {
|
||||
return Arrays.asList(StringUtils.split(roles, ","));
|
||||
//角色列表在数据库中实际以逗号分隔字符串存储,因此返回不能修改的List.
|
||||
return ImmutableList.copyOf(StringUtils.split(roles, ","));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.springside.examples.showcase.entity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
@@ -13,6 +11,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* 角色.
|
||||
*
|
||||
@@ -34,7 +34,6 @@ public class Role extends IdEntity {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -53,7 +52,7 @@ public class Role extends IdEntity {
|
||||
|
||||
@Transient
|
||||
public List<String> getPermissionList() {
|
||||
return Arrays.asList(StringUtils.split(permissions, ","));
|
||||
return ImmutableList.copyOf(StringUtils.split(permissions, ","));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user