精彩的会议。 如何查找用户名

发布于 2024-07-19 06:21:32 字数 637 浏览 5 评论 0原文

我正在 Groovy 下使用 scafoldig 开发一个应用程序。 为了安全起见,我们使用 Acegi 插件。 我们有一个名为 ChangeManagement 的类,定义如下(简化版本)

class ChangeManagement {
static constraints = {
    company(nullable:false)             
    lastModifiedByUser(nullable:false)      
}

Company company    
static belongsToCompany = [company:Company]

User lastModifiedByUser 
static belongsToUser = [lastModifiedByUser:User]
}

当我处理 create 方法时,我将得到一个下拉菜单 带有标签“最后修改者”以及用户表中的所有用户, 这是标准行为。

相反,我想直接拥有已经登录的用户并 没有下拉菜单。 我已经生成了创建模板,我可以对其进行修改。 我假设我必须从会话中获取用户名。 如果我的假设是正确的,如何获得这个用户名? 如果我错了那么我从哪里可以获得当前用户的用户名?

提前致谢。

I am developing an application under Groovy using scafoldig.
We are using the Acegi plugin for security.
We have a class called ChangeManagement defined as follows (simplified version)

class ChangeManagement {
static constraints = {
    company(nullable:false)             
    lastModifiedByUser(nullable:false)      
}

Company company    
static belongsToCompany = [company:Company]

User lastModifiedByUser 
static belongsToUser = [lastModifiedByUser:User]
}

When I address the create method I will get a pull-down menu
with the label "Last Modified By" with all the users from the table Users,
which is the standard behaviour.

Instead of this I would like to have directly the user who is already logged in and
no pull down menu. I've already generate the create template and I can modify it.
I am assuming that I have to get the username from the session.
If my assumption is true, how to get this username? and if I am wrong then from where can I get the username of the current user?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七禾 2024-07-26 06:21:32

请参阅这个问题了解如何获取当前用户名的详细信息。

我还建议研究一下 Grails Filters 作为一种轻松地将用户填充到模型中的方法控制器调用并使其在视图中可用。 我在我的应用程序上使用它来将登录用户的名称放在屏幕的右上角。

See this question for details on how to get the current username.

I'd also suggest looking into Grails Filters for one way to easily stuff the user into the model after all controller calls and make it available in the view. I use this on my app to put the name of the logged in user in the upper right hand corner of the screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文