JPQL like 子句中的参数 [英] Parameter in like clause JPQL
本文介绍了JPQL like 子句中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 like 子句编写 JPQL 查询:
LIKE '%:code%'
我想要代码=4 并找到
<前>455554646...我无法通过 :code = '%value%'
namedQuery.setParameter("%" + this.value + "%");
因为在另一个地方我需要 :value
不被 %
字符包裹.有什么帮助吗?
解决方案
如果你这样做
LIKE :code
然后做
namedQuery.setParameter("code", "%" + this.value + "%");
然后值保持没有%"符号.如果您需要在同一查询中的其他地方使用它,只需使用 'code' 以外的另一个参数名称.
I am trying to write a JPQL query with a like clause:
LIKE '%:code%'
I would like to have code=4 and find
455 554 646 ...
I cannot pass :code = '%value%'
namedQuery.setParameter("%" + this.value + "%");
because in another place I need :value
not wrapped by the %
chars. Any help?
解决方案
If you do
LIKE :code
and then do
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' .
这篇关于JPQL like 子句中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文