【问题标题】:Case insensitive search in grailsgrails中不区分大小写的搜索
【发布时间】:2010-10-13 12:51:53
【问题描述】:

我正在开发使用文件搜索的 grails 应用程序。为此,我编写了以下代码。这段代码有效,它给出了区分大小写的结果。但我想搜索不区分大小写的文件。

def criteria = FileDomain.createCriteria()
 def results = criteria {
    and {
      like('user', User.findById(session?.user))
      or {
        like('filename', '%' + params.fileSearchKey + '%')
        like('referenceFilename', '%' + params.fileSearchKey + '%')
         }
       }
    }

谁能提供这方面的帮助?

【问题讨论】:

    标签: hibernate grails groovy frameworks


    【解决方案1】:

    我相信使用

    ilike('filename', "%${params.fileSearchKey}%")
    ilike('referenceFilename', "%${params.fileSearchKey}%")
    

    这就是你应该做的case insensitive搜索

    【讨论】:

      【解决方案2】:

      在 Grails 2.x 中执行此操作的一种方法是使用 the eq node

      eq("branch", "london", [ignoreCase: true])
      

      【讨论】:

      • 奇怪...我得到 groovy.lang.MissingMethodException:没有方法签名:eq() 适用于参数类型:(java.lang.String, java.lang.String, java .util.LinkedHashMap) 这是在 Grails 2.5.0 中。最后没有地图,它工作正常。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-15
      • 2013-09-26
      • 2023-03-20
      • 1970-01-01
      • 2012-01-04
      • 2011-07-20
      • 2015-10-23
      相关资源
      最近更新 更多