Created
April 11, 2020 15:44
-
-
Save ntub46010/b4b216d890e9c6c45cfecd806713ed8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 查詢price欄位在特定範圍的文件(參數亦可使用Date) | |
// gte:大於等於;lte:小於等於;Between:大於及小於,兩者略有差異。 | |
@Query("{'price': {'$gte': ?0, '$lte': ?1}}") | |
List<Product> findByPriceBetween(int from, int to); | |
// 查詢name字串欄位有包含參數的文件,不分大小寫 | |
@Query("{'name': {'$regex': ?0, '$options': 'i'}}") | |
List<Product> findByNameLikeIgnoreCase(String name); | |
// 查詢同時符合上述兩個條件的文件 | |
@Query("{'$and': [{'price': {'$gte': ?0, '$lte': ?1}}, {'name': {'$regex': ?2, '$options': 'i'}}]}") | |
List<Product> findByPriceBetweenAndNameLikeIgnoreCase(int priceFrom, int priceTo, String name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment