且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在同一列的 Sping JPA 中使用多个 LIKE '%keyword%'?

更新时间:2022-12-12 11:43:00

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

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.