如何在同一列的Sping JPA中使用多个LIKE'%keyword%'? [英] How to use multiple LIKE '%keyword%' in Sping JPA on same column?

查看:66
本文介绍了如何在同一列的Sping JPA中使用多个LIKE'%keyword%'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用

List<Application> findByProposalContainingIgnoreCase(String keyword);

如何使用关键字列表来达到相同的目的?

How can I achieve the same using a list of keywords?

例如:

List<Application> findByProposalContainingIgnoreCase(List<String> keywords);

更新:

如果无法这样做,以下方法是否有效:

If it is not possible to do so, is the below way effective:

@Autowired
private ApplicationService applicationService;

List<Application> applications = new ArrayList<>();

for (String keyword : keywords) {
    applications.addAll(applicationService.findByProposalContainingIgnoreCase(keyword));
}

推荐答案

这是不可能的,因为普通的sql也无法做到这一点.使用喜欢"一词意味着搜索包含所提供关键字的所有可能性.在您的情况下,您必须将多个包含语句串在一起,例如

It's not possible as normal sql cannot do it either. The use of the word 'like' implies searching for all the possibilities that contain the keyword provided. In your case you'd have to string multiple contains statements together like

List<Application> findByProposalContainingIgnoreCaseOrProposalContainingIgnoreCase(String keyword1, String keyword2);

您最好对列表使用 in 关键字

You might be better of doing the inkeyword for your list

List<Application> findByProposalIn(Set<String> proposals);

问题出现了,尽管现在您必须将投标的大写和小写都添加到集合中,因为它可能不区分大小写,并且它将查找不包含单词的确切匹配项.它并不理想,但我认为它将对您要尝试的工作有用.

The problem arises though that now you would have to add both uppercase and lowercase of the proposal to the set as it might not be case sensitive, and it will look for the exact matches not part of the word. Its not ideal but I think it'll work for what you're trying to do.

更新

添加for循环即可满足您的需求.

You're answer by adding the for loop would suffice for what you need.

这篇关于如何在同一列的Sping JPA中使用多个LIKE'%keyword%'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆