Spring CrudRepository - 在集合中查找ignore case

时间:2016-05-04 08:33:09

标签: java spring mongodb spring-data-mongodb

我认为,因为ignore case查询的语法是:

findByFieldIgnoreCase(Object field)

collection查询的语法是

findByFieldIn(List<Object> fields)

ignore case collection查询的语法是:

findByFieldIgnoreCaseIn(List<Object> fields)

但这似乎不起作用(它仍然区分大小写)。

想法?

编辑:

它也不是findByFieldInIgnoreCase

2 个答案:

答案 0 :(得分:0)

Spring Data MongoDB Reference Documentation表示:

  

方法解析器支持为个人设置IgnoreCase标志   属性(例如,findByLastnameIgnoreCase(...))或所有   支持忽略大小写的类型的属性(通常是String   实例,例如,findByLastnameAndFirstnameAllIgnoreCase(...))。   是否支持忽略案例可能因商店而异,请咨询   参考文献中的相关部分   特定于商店的查询方法。

supported keywords for query methods表未明确提及 InIgnoreCase IgnoreCaseIn 关键字。

对于其他unsupported keywords,您可以在Spring Data MongoDB JIRA上打开功能请求。

同时,为了让代码运行,您可以使用Query注释或Querydsl实现 findByFieldInIgnoreCase findByFieldIgnoreCaseIn 。我为另一个post中的类似案例提供了几种可能的解决方案。

答案 1 :(得分:0)

findByFieldInAndIgnoreCase(List<Object> fields)

这应该可以在启动应用程序时不会抛出任何错误。