包含查询 Spring 数据 [英] Contains query Spring data
本文介绍了包含查询 Spring 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 spring 数据中使用 LIKE
运算符,但下面的查询没有任何反应:
I would like to use the LIKE
operator in spring data but nothing happens with the query below:
@query("select a.designation from article a,stock s where (a.idArticle=s.article.idArticle and (a.designation LIKE %:x%")
public page<Stock> listArticles(@param("x") String designation);
我知道我可以使用findByDesignationContaining,但是我这里必须使用query,因为我必须连接两个表.
I know that I can use findByDesignationContaining, but I have to use query here because I have to join the two tables.
您有什么建议吗?
推荐答案
您应该使用 concat JPQL 函数:
You should use concat JPQL function:
...(a.designation LIKE concat('%', :x, '%'))
如果您需要不区分大小写的like",您可以使用upper"/lower"函数:
If you need case insensitive 'like' you can use 'upper'/'lower' functions:
...(upper(a.designation) LIKE concat('%', upper(:x), '%'))
这篇关于包含查询 Spring 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文