如何在Integra中使用ilike在grails中 [英] how to use ilike with Integer in grails

查看:102
本文介绍了如何在Integra中使用ilike在grails中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用EasyGrid插件,并且必须找到其中整数字段如'%001%'的值

  initialCriteria {
ilike('id',%+ params.id +%)
}

但ilike不适用于Integer。

我试过: {
ilike('id'.toString(),%+ params.id +%)
}

initialCriteria {
ilike('str id)',%+ params.id +%)
}

但如果 id 是数据库中的一个整数,那么它就不起作用了。 ,那么 ilike 并没有多大意义,并且可能有更好的方法来做你正在尝试做的事情(比如向域对象添加一个类型字段或其他东西,并按类型过滤)

然而,你应该可以做这样的事情(未经测试):

 initialCriteria {
sqlRestrictioncast(id AS char(256))like'%001%''
}


I use EasyGrid plugin and must find values where integer field like '%001%'

initialCriteria {
    ilike('id', "%"+params.id+"%")
}

But ilike doesn't work with Integer. How to do it?

I tried to do:

    initialCriteria {
        ilike('id'.toString(), "%"+params.id+"%")
    }

    initialCriteria {
        ilike('str(id)', "%"+params.id+"%")
    }

but it's not work.

解决方案

If id is an integer in the database, then ilike doesn't really make much sense and there is probably a better way to do what you are trying to do (like adding a type field or something to the domain object, and filter by type)

However, you should be able to do something like this (untested):

initialCriteria {
    sqlRestriction "cast( id AS char( 256 ) ) like '%001%'"
}

这篇关于如何在Integra中使用ilike在grails中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆