grails - gorm .where with like

标签 grails gorm

groovy的新手,grails。

我有以下查询,在这里我想将一些参数与通过(eq)完全匹配,但对于其中一个,我想使用“like”

if (params.ret_code) {
            ret_cod = params.ret_code+"%"
 }       

    def srchresults = DmnObj.where {
    if (params.doc_num) { doc_num == params.doc_num.trim() } //works as expected

    //How do I do this????
     if (params.retn_code) { retn_code like ret_cod }

    }

试过这个,但是徒劳。

我如何设置一个喜欢的retn_code?

谢谢!

最佳答案

这就是你可以做到的

    // case sensitive like 
    def result = Domain.where {
        fieldName ==~ "value"            
    }

    // case insensitive like 
    def result = Domain.where {
        fieldName =~ "value"            
    }

请记住,在value的前缀,后缀或两者都加上%。有关where的更多信息,请查询https://grails.github.io/grails-doc/latest/guide/GORM.html#whereQueries

关于grails - gorm .where with like,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32481655/

相关文章:

grails - 在Grails中本地化验证(错误)消息

java - 将 SSL 自签名证书添加到 Java keystore 以供 JAX-RS 在 webstart 应用程序中使用

caching - GORM(纹理)-缓存Blob图片或其他内容

hibernate - Grails更新引用

database - 具有链式调用的 Grails 服务类的事务行为

exception - 在日志中记录 Grails 应用程序中的错误

grails - 在测试环境中,如何在GORM中为HQL加入多对多关联?

mongodb - Grails过渡属性无法验证错误?

hibernate - 根据GORM查询中的字段过滤出对象

java - 在 Tomcat Grails 中禁用缓存