MongoDB中,如果有JPA默认实现不了的查询,可以用@Query注解实现自定义的查询功能,例如:
- @Repository
- public interface SystemParameterRepository extends MongoRepository<SystemParameter, String> {
- SystemParameter findByParmName(String parmName);
-
- * Query System Parameter by param name and expiry date, like: <br/>
- * <pre>{@code
- * select * from SystemParameter where parmName = 'name' and 'current date' < expiryDate
- * }</pre>
- *
- * @param parmName
- * @param currentDate
- * @return
- */
- @Query("{'expiryDate': {$gt: ?0}, 'parmName': ?1}")
- SystemParameter findByParmNameAndExpiryDate(String parmName, Date currentDate);
- }