jpa本机查询正则表达式与querydsl一样 [英] jpa native Query regexp like with querydsl
问题描述
我有这样的查询语句:
select t.*
from T_ex_table t
where regexp_like(t.note,
'^(.*[^[:digit:]]+)?([condition])([^[:digit:]]+.*)?$',
'n')
如果我在jpa中将它与querydsl(com.querydsl)一起使用(这是scala,并不重要):
And if I use it in jpa with querydsl(com.querydsl) like(this is scala, and it doesn't important):
@Query(value =
"select t.*" +
" from T_PURCHASE t" +
" where regexp_like(t.note," +
" '^(.*[^[:digit:]]+)?([?1])([^[:digit:]]+.*)?$'," +
" 'n')", nativeQuery = true)
def getByTrackingNo(trackingNo: String): Purchase
我调试测试时,它总是抛出
While i debug test, it always throw
为方法public abstract Purchase使用命名参数 PurchaseRepository.getByTrackingNo(java.lang.String) 但是在带注释的查询选择"中找不到参数"trackingNo" 来自T_EC_PURCHASE t的t.pt_note,t.tracking_no,其中 regexp_like(t.pt_note,'^(. [^ [:digit:]] +)?({?1})([^ [:digit:]] +.)?$', 'n')'!
Using named parameters for method public abstract Purchase PurchaseRepository.getByTrackingNo(java.lang.String) but parameter 'trackingNo' not found in annotated query 'select t.pt_note, t.tracking_no from T_EC_PURCHASE t where regexp_like(t.pt_note, '^(.[^[:digit:]]+)?({?1})([^[:digit:]]+.)?$', 'n')'!
我错过了什么吗,我该如何解决?
Did i missed something, and how can i fix it.
推荐答案
也许尝试将完整的regexp移至param方法?并在之前构建它.例如:
@Query(value = "select t.* from T_PURCHASE t where regexp_like(t.note, ?1, 'n')", nativeQuery = true)
其中?1
-您可以使用必需的参数完全构建正则表达式.
Maybe try to move full regexp to the param method? and build it before. for example :
@Query(value = "select t.* from T_PURCHASE t where regexp_like(t.note, ?1, 'n')", nativeQuery = true)
Where ?1
- yours fully build regexp with required parameters.
这篇关于jpa本机查询正则表达式与querydsl一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!