grails - 从登录的用户访问另一个对象

标签 grails spring-security gsp

我正在使用Grails的Spring安全性。我的用户有用户名,并且还引用了另一个称为卖方的域对象。

// Every user will usually be associated with a Seller
static belongsTo = [seller: Seller];

在GSP中,我可以通过执行以下操作来显示已登录用户的用户名:
<sec:ifLoggedIn>Hello <sec:username/> </sec:ifLoggedIn>

但我也想显示用户的卖方对象的属性。我尝试:
<sec:ifLoggedIn>Hello <sec:username/> <sec:seller.name/> </sec:ifLoggedIn>

但这给出了:
Tag [seller.name] does not exist. No tag library found for namespace: sec
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

有任何想法吗?

最佳答案

尽管上一个答案更灵活,但是如果您只想显示登录的用户名,则可以尝试以下两个标签之一:

<sec:ifLoggedIn>Hello ${sec.username} </sec:ifLoggedIn>

要么
<sec:ifLoggedIn>Hello ${sec.loggedInUserInfo(field:'username')} </sec:ifLoggedIn>

关于grails - 从登录的用户访问另一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18553851/

相关文章:

grails - 如何在 grails 中从我的类路径中获取 4.0 版的 httpclient

grails - 如何创建同一服务的两个配置实例?

grails - 在Grails中使用Stripe 4

java - 无法让 @EnableGlobalMethodSecurity 工作

angularjs - 在 Ionic 应用程序中一起使用 CORS 和 CSRF

email - 使用布局渲染 gsp/view 不起作用

java - Intellij 使用 JAR 库导出 WAR 文件

spring - Grails AOP 配置异常

grails - 在gsp文件中添加条件

grails - Grails 3.1.10找不到 View