我有一个自定义的用户详细信息对象,其名字的一部分。在用户名下方工作,但我希望第二个工作。我怎样才能访问这个自定义属性?获取用户负责人的自定义属性
<security:authentication property="principal.username" />
<security:authentication property="principal.firstname" />
我有一个自定义的用户详细信息对象,其名字的一部分。在用户名下方工作,但我希望第二个工作。我怎样才能访问这个自定义属性?获取用户负责人的自定义属性
<security:authentication property="principal.username" />
<security:authentication property="principal.firstname" />
我认为你已经尝试了上述方法,但没有成功。
检查您的自定义用户详细信息类,以确保'firstname'属性的getter和setter方法的大小写正确。
适合我。这里是我的测试代码: -
CustomUserDetails类JSP
public class CustomUserDetails implements UserDetails {
public String getFirstName() {
return "hello";
}
...
}
自定义标签下面的标签返回hello
。
<security:authentication property="principal.firstName" />
顺便说一句,请确保你没有把getFirstName()
到匿名类,因为这是行不通的。
我想在这里的是说,不这样做: -
...
return new UserDetails() {
// adding extra method here will not work
public String getFirstName() {
return "hello";
}
public String getUsername() {
return "test";
}
...
};
...这样做: -
...
// this class implements UserDetails and contains getFirstName()
CustomUserDetails csd = new CustomUserDetails();
csd.set...(...)
...
return csd;
你是对的, “N” WASN没有大写字母。 – 2011-02-10 23:13:12