【问题标题】:grails findWhere not equalgrails findWhere不等于
【发布时间】:2013-03-18 15:09:38
【问题描述】:

有没有办法使用findWhere 和不相等的值(尝试使用它与标准)?

例如

Books.findWhere('sale' : true, 'category': ne('exclude me') )

我有一个可行的解决方案,但想知道是否有使用 findWhere 的方法,我发现它更易于阅读。

def result = Books.createCriteria().get{
            eq('sale', true)
            ne("category", 'exclude me')
}

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

    您可以使用任一动态查找器方法:

    Books.findAllBySaleAndCategoryNotEqual(true, 'exclude me')
    

    或 where 查询(使用 DetachedCriteria:

    Books.findAll {
         (sale == true) && (category != 'exclude me')
    }
    

    【讨论】:

      【解决方案2】:

      我不知道使用findWhere 的方法,但是对于两个属性的动态查找器有一个很好的语法,其中一个是boolean

      Books.findSaleByCategoryNotEqual('exclude me')
      

      (或findNotSaleBy...,如果您希望销售为false)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-02
        • 2015-04-06
        • 2014-02-22
        • 1970-01-01
        相关资源
        最近更新 更多