Spring JPA,SpEL解析有效表达式,表达式中还有更多数据,'comma(,)'
我必须使用 spring JPA 从 oracle 12c 检索一些特定数据,这些数据以逗号 (,) 分隔。
Ex - Branch
ID Location
--------- ----------
101 NL,MX,USA
102 UK,IND,BLG
103 UK,NL,AUS
@Query(value = "select * from branch m where lower(m.location) like %:loc% offset :offset rows fetch next :limit rows only",nativeQuery = true)
List<Location> getBranchListByLocation(@Param("loc") String loc,@Param("offset") int offset,@Param("limit") limit)
但是当我将 loc 值作为“NL”传递时,会发生以下错误。
spelparseexception: el1041e: after parsing a valid expression, there is still more data in the expression: 'comma(,)'
有其他方法可以解决该问题吗?
I have to retrieve some specific data from oracle 12c using spring JPA which are separated by comma (,).
Ex - Branch
ID Location
--------- ----------
101 NL,MX,USA
102 UK,IND,BLG
103 UK,NL,AUS
@Query(value = "select * from branch m where lower(m.location) like %:loc% offset :offset rows fetch next :limit rows only",nativeQuery = true)
List<Location> getBranchListByLocation(@Param("loc") String loc,@Param("offset") int offset,@Param("limit") limit)
But when i pass loc value as "NL" then the following error has occurred.
spelparseexception: el1041e: after parsing a valid expression, there is still more data in the expression: 'comma(,)'
Is there an alternative way to solve the issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
%
字符需要包含在字符串文字中,并与:loc
绑定变量连接:或者,您可以将
%
前置并附加到Java 中的loc
变量,然后只需使用:loc
而无需在 SQL 查询中包装%
s。(注意:您使用的是
lower
,因此您希望传入nl
而不是NL
。)但是,您会发现如果您传递
:loc
值in
那么它将匹配in
以及ind
和墨水
。如果您想匹配完整的分隔项,那么您需要在匹配中包含周围的逗号:The
%
characters need to be contained in string literals and concatenated with the:loc
bind variable:Alternatively, you can prepend and append
%
to theloc
variable in Java and then just use:loc
without the wrapping%
s in the SQL query.(Note: you are using
lower
so you want to pass innl
and notNL
.)However, you will find if you pass the
:loc
valuein
then it will matchin
as well asind
andink
. If you want to match the full delimited item then you want to include the surrounding commas in the match: