spring_reference/IV. Spring Boot features/29.2.3. Spring Data MongoDB...

20 lines
771 B
Markdown
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 29.2.3. Spring Data MongoDB仓库
Spring Data的仓库包括对MongoDB的支持。正如上面讨论的JPA仓库基本的原则是查询会自动基于你的方法名创建。
实际上不管是Spring Data JPA还是Spring Data MongoDB都共享相同的基础设施。所以你可以使用上面的JPA示例并假设那个City现在是一个Mongo数据类而不是JPA @Entity它将以同样的方式工作。
```java
package com.example.myapp.domain;
import org.springframework.data.domain.*;
import org.springframework.data.repository.*;
public interface CityRepository extends Repository<City, Long> {
Page<City> findAll(Pageable pageable);
City findByNameAndCountryAllIgnoringCase(String name, String country);
}
```