Grails Spring安全核心:获取具有特定角色的用户

Grails Spring安全核心:获取具有特定角色的用户,grails,spring-security,Grails,Spring Security,我正在尝试获取所有遵循特定标准且具有角色的用户 标准: ArrayList<User> users = User.createCriteria().list() { inList("gender", whichGenderList) ne("uid", uid) profile { inList("age", whichAge) } firstResult(usersPerPage * currentPage) maxResults(usersPerP

我正在尝试获取所有遵循特定标准且具有
角色的
用户

标准:

ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}
  ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  role {
     eq("authority","ROLE_USER")
  }
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}
ArrayList users=User.createCriteria().list(){
inList(“性别”,whichGenderList)
东北(“uid”,uid)
侧面图{
inList(“年龄”,whichAge)
}
第一个结果(usersPerPage*currentPage)
maxResults(usersPerPage)
}
问题: 是否可以在此条件中添加一个条件,仅选择具有
角色的用户\u USER

我正在使用:

ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}
  ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  role {
     eq("authority","ROLE_USER")
  }
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}
  • Grails2.4.4
更新:

ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}
  ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  role {
     eq("authority","ROLE_USER")
  }
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}
最小
用户
表格:


角色
表格:

ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}
  ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  role {
     eq("authority","ROLE_USER")
  }
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}


用户角色
表格:

ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}
  ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  role {
     eq("authority","ROLE_USER")
  }
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}

ArrayList users=User.createCriteria().list(){
inList(“性别”,whichGenderList)
东北(“uid”,uid)
角色{
eq(“权限”、“角色\用户”)
}
侧面图{
inList(“年龄”,whichAge)
}
第一个结果(usersPerPage*currentPage)
maxResults(usersPerPage)
}

为什么您觉得这很难?它拥有所有标准的结构。你只需再添加一行
eq(“角色”、“角色用户”)
@Suganthan我认为你不理解这个问题。:)根据您的建议,我得到的
无法解析属性:角色:foo.User
。您能否发布您的
域模型
,我认为只有映射是足够的,还有一点是永远不要在公共系统中共享原始数据。.我的
用户
类上没有
角色
属性。您可以看到域类。