使用操作mongodb数据库JPA的版本
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.0.1.RELEASE</verison>
</dependency>
下面是我写的测试的代码,但是不知道为什么取不出来数据
@Autowired
CmsPageRepository cmsPageRepository;
@Test
public void testFindAllByExample(){
int page = 0;
int size = 10;
Pageable pageable = PageRequest.of(page,size);
CmsPage cmsPage = new CmsPage();
cmsPage.setSiteId("1");
System.out.println(cmsPage);
//条件查询配匹器
ExampleMatcher exampleMatcher = ExampleMatcher.matching();
Example<CmsPage> example =Example.of(cmsPage,exampleMatcher);
Page<CmsPage> all = cmsPageRepository.findAll(example, pageable);
List<CmsPage> content = all.getContent();
System.out.println(content);
}
这个是cmsPageRepository对象接口
public interface CmsPageRepository extends MongoRepository<CmsPage,String> {
}
需要查询的字段在对象中是存在的
实体类里面的注解也应该是对的
但是我不知道为什么数据库里面的数据取不出来,也没有错误提示,请教下,谢谢