谁能建议我,如何在 mongorepository 中使用“findbynameRegexIgnorecase”?我需要在查找名称本身时检查 (regex,Ignorecase)。 spring1.4.2.发布
public interface SampleAreaMongoRepository extends MongoRepository<SampleArea, String> {
SampleArea findByAreaRegexIgnoreCase(String area);}
最佳答案
好吧,您可以使用 SpringData mongo finder @Query
注释来实现这一点。
查询注解来自org.springframework.data.mongodb.repository
包
public interface MyMongoRepository extends MongoRepository<Users, String>{
@Query(value = "{'name': {$regex : ?0, $options: 'i'}}")
List<Users> findByAreaRegexIgnoreCase(String name);
}
$regex : ?0
是接受输入名称作为参数的正则表达式,$options: 'i'
忽略大小写。
希望这对您有所帮助,祝您好运!
关于spring - 我们可以在 mongorepository 中使用带空格的 Ignorecase 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44340630/