2017-06-03 94 views
1

任何人都可以建議我,如何在mongorepository中使用「findbynameRegexIgnorecase」?我需要檢查(正則表達式,忽略),同時找到名稱本身。 spring1.4.2.Release我們可以在mongorepository中使用帶有空格的Ignorecase嗎?

public interface SampleAreaMongoRepository extends MongoRepository<SampleArea, String> { 
SampleArea findByAreaRegexIgnoreCase(String area);} 

回答

0

好了,你可以用SpringData蒙戈取景@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'忽略的情況。

希望這會有所幫助,祝你好運!

+0

謝謝@harshavmb,它工作正常。 – vignesh

+0

很高興它幫助你.. :) – harshavmb

相關問題