문제

I am trying to query database using GORM, when I pass '%' as value, its returning all the rows in the table. how can I escape % character?

def query="from Person as t WHERE  (firstName like :firstName)"
def v ="%"
gSearchMap[ firstName]= "%"+v+"%"
def rows = domain.findAll(query.toString(),gSearchMap,limits)
도움이 되었습니까?

해결책

You should check the documentation of your sql server for that syntax details.

in MySQL you would use the \ for that:

def query="from Person as t WHERE firstName like '%\\%%"

see Escaping MySQL wild cards

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top