like子句JPQL中的参数 [英] Parameter in like clause JPQL

查看:137
本文介绍了like子句JPQL中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用like子句编写JPQL查询:

I am trying to write a JPQL query with a like clause:

LIKE '%:code%'

我想要代码= 4并找到

I would like to have code=4 and find


455
554
646
...

我不能传递:code ='%value%'

namedQuery.setParameter("%" + this.value + "%");

因为在另一个地方我需要:value 不包含在字符中。有什么帮助?

because in another place I need :value not wrapped by the % chars. Any help?

推荐答案

如果你这样做

LIKE :code

然后执行

namedQuery.setParameter("code", "%" + this.value + "%");

然后价值保持从'%'符号免费。如果您需要在同一查询中的其他位置使用它,只需使用代码以外的其他参数名称。

Then value remains free from the '%' sign. If you need to use it somewhere else in the same query simply use another parameter name other than 'code' .

这篇关于like子句JPQL中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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