JPQL (JPA) 搜索子字符串
我面临着通过某些(子)字符串搜索实体的简单问题,它们可能包含这些字符串。
例如,我有用户 user1、usr2、useeeer3、user4,我将输入搜索窗口“use”,我希望返回 user1、useeer3、user4。
我相信你现在知道我的意思了。 JPA(JQPL)中是否有任何构造?在命名查询中以某种方式使用 WHERE 进行搜索会很好。类似“从用户 u 中选择 u,其中 u.nickname 包含 :substring”
Im facing simple problem with searching entities by some (sub)string, which they might contain.
E.g. I have users user1, usr2, useeeer3, user4 and I will enter to search window "use" and I expect to return user1, useeer3, user4.
Im sure you know what I mean now. Is there any construction in JPA (JQPL)? It would be nice to search using WHERE somehow in named queries. Something like "SELECT u FROM User u WHERE u.nickname contains :substring"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
LIKE
表达式。以下是 JPA 1.0 规范 (JSR 220) 的 4.6.9 Like Expression 部分的引用:Use a
LIKE
expression. Here is a quote from the section 4.6.9 Like Expression of the JPA 1.0 spec (JSR 220):