获取用户主体的自定义属性
我有一个自定义用户详细信息对象,其中包含名字部分。下面的用户名有效,但我想要第二个类似的东西。我如何访问这个自定义属性?
<security:authentication property="principal.username" />
<security:authentication property="principal.firstname" />
I have a custom user details object with first name part of it. Below username works, but I want something like the second to work. How can I access this custom property?
<security:authentication property="principal.username" />
<security:authentication property="principal.firstname" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你已经尝试过上面的方法了,但没有成功。
检查您的自定义用户详细信息类,确保“firstname”属性的 getter 和 setter 方法的大小写正确。
I presume that you tried the above and that it didn't work.
Check your custom user details class to make sure that the capitalization of the getter and setter methods for the 'firstname' property are correct.
对我有用。这是我的测试代码:-
CustomUserDetails 类
JSP 中的自定义标记
以下标记返回
hello
。顺便说一句,请确保您没有将
getFirstName()
放入匿名类中,因为这不起作用。我想说的是,不要这样做:-
...这样做:-
Works for me. Here's my test code:-
CustomUserDetails class
Custom tag in JSP
The following tag returns
hello
.By the way, make sure you are not putting
getFirstName()
into the anonymous class, because that will not work.What I'm trying to say here is, don't do this:-
... do this:-