【问题标题】:Spring CrudRepository - find ignore case in collectionSpring CrudRepository - 在集合中查找忽略大小写
【发布时间】:2016-05-05 23:31:16
【问题描述】:

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

findByFieldIgnoreCase(Object field)

collection 查询的语法是

findByFieldIn(List<Object> fields)

ignore case collection 查询的语法是:

findByFieldIgnoreCaseIn(List<Object> fields)

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

想法?

编辑:

也不是findByFieldInIgnoreCase

【问题讨论】:

  • 不应该是findByFieldInIgnoreCase(..)吗? (如果这很重要)
  • 不,也试过了:\

标签: java spring mongodb spring-data-mongodb


【解决方案1】:

Spring Data MongoDB Reference Documentation 声明:

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

supported keywords for query methods 的表没有明确提及 InIgnoreCaseIgnoreCaseIn 关键字。

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

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

【讨论】:

    【解决方案2】:
    findByFieldInAndIgnoreCase(List<Object> fields)
    

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

    【讨论】:

    • 没有。 “启动应用程序时不抛出任何错误”!= 有效。
    猜你喜欢
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2017-01-24
    • 1970-01-01
    相关资源
    最近更新 更多