且构网

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

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

更新时间:2022-12-12 11:29:49

这是不可能的,因为普通的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.