我们可以在 mongorepository 中使用带空格的 Ignorecase 吗?
can we use Ignorecase with whitespace in mongorepository?
任何人都可以建议我,如何在 mongorepository 中使用 "findbynameRegexIgnorecase"?我需要在查找名称本身时检查 (regex,Ignorecase)。 spring1.4.2.Release
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'
忽略大小写。
希望这对您有所帮助,祝您好运!
任何人都可以建议我,如何在 mongorepository 中使用 "findbynameRegexIgnorecase"?我需要在查找名称本身时检查 (regex,Ignorecase)。 spring1.4.2.Release
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'
忽略大小写。
希望这对您有所帮助,祝您好运!