我有这个枚举:

enum CompanyType {
    RESTAURANT('R'),
    BAR('B'),
    NIGHT_CLUB('N')

    final String id

    CompanyType(String id) {
        this.id = id
    }

    public Boolean isRestaurant() {
        this == RESTAURANT
    }

    public Boolean isBar() {
        this == BAR
    }

    public Boolean isNightClub() {
        this == NIGHT_CLUB
    }
}

我有一个像这样的域名:
class Company {
    String name
    String description
    CompanyType companyType
}

在我的 Controller 上,当我尝试按CompanyType列出筛选时,我这样做:
companyList = Company.findAll(params,{companyType.id == selectedCompanyType.id})

我收到此错误消息:
Class
groovy.lang.MissingMethodException
Message
No signature of method: grails.gorm.DetachedCriteria.companyType() is applicable for argument types: (com.memobile.where2go.CompanyController$_tt__index_closure9_closure15) values: [com.memobile.where2go.CompanyController$_tt__index_closure9_closure15@483c17c1]

如果我只把companyType == selectedCompanyType放到一个空列表...

最佳答案

我将使用“where”查询:

def companyList = Company.where {
    companyType == selectedCompanyType
}.list(params)

关于grails - 我该如何解决这个分离标准问题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29617803/

10-11 13:38