gpt4 book ai didi

grails - Grails中Shiro插件的正确标准

转载 作者:行者123 更新时间:2023-12-02 15:50:03 25 4
gpt4 key购买 nike

我有如下Shiro域类:

class ShiroUser {
String email
String password

static hasMany = [ roles: ShiroRole, permissions: String ]

static constraints = {
email(nullable: false, blank: false, unique: true)
}
}


class ShiroRole {
String name

static hasMany = [ users: ShiroUser, permissions: String ]
static belongsTo = ShiroUser

static constraints = {
name(nullable: false, blank: false, unique: true)
}
}

我从params.email收到ShiroUser的电子邮件。我想使用criteria()来查找属于To ShiroUser的权限。

我尝试了以下代码,但未能成功。
 def criteria= permissions.createCriteria().listDistinct {
ShiroRole{
ShiroUser{
eq("email", params.email)
}
}
}

最佳答案

您的标准建立错误。我会保持简单,就像这样:

def permissions = ShiroUser.findByEmail( params.email )?.roles*.permissions.flatten() as Set

如果您要遵守标准:
def permissions = ShiroRole.createCriteria().listDistinct {
projections{
property 'permissions'
}
users{
eq "email", params.email
}
}

关于grails - Grails中Shiro插件的正确标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40720674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com