java spring data 分页_java – 在Spring Data Neo4j 4中进行分页和排序

洪英豪
2023-12-01

在SDN4中是否有对自定义查询的分页支持?

>如果是,它是如何工作的?

>如果不是,是否有工作场所?

我有以下Spring Data Neo4j 4存储库:

@Repository

public interface TopicRepository

extends GraphRepository,IAuthorityLookup {

// other methods omitted

@Query("MATCH (t:Topic)-[:HAS_OFFICER]->(u:User) "

+ "WHERE t.id = {0} "

+ "RETURN u")

public Page topicOfficers(Long topicId, Pageable pageable);

}

和相应的测试用例:

@Test

public void itShouldReturnAllOfficersAsAPage() {

Pageable pageable = new PageRequest(1,10);

Page officers = topicRepository.topicOfficers(1L, pageable);

assertNotNull(officers);

}

当我运行测试时,我遇到以下异常

Failed to convert from type java.util.ArrayList> to type org.springframework.data.domain.Page> for value '[org.lecture.model.User@1]';

nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.util.ArrayList> to type org.springframework.data.domain.Page>

这是我的设置:

dependencies {

//other dependencies omitted

compile("org.neo4j:neo4j-cypher-dsl:2.0.1")

compile "org.neo4j.app:neo4j-server:2.2.2"

compile(group: 'org.springframework.data',

name: 'spring-data-neo4j',

version: '4.0.0.BUILD-SNAPSHOT')

compile(group: 'org.springframework.data',

name: 'spring-data-neo4j',

version: '4.0.0.BUILD-SNAPSHOT',

classifier: 'tests')

testCompile(group: 'org.neo4j',

name: 'neo4j-kernel',

version: '2.2.2',

classifier: 'tests')

testCompile(group: 'org.neo4j.app',

name: 'neo4j-server',

version: '2.2.2',

classifier: 'tests')

testCompile(group: 'org.neo4j',

name: 'neo4j-io',

version: '2.2.2',

classifier: 'tests')

}

我使用的快照应该能够处理分页,因为以下测试运行得很好:

@Test

public void itShouldReturnAllTopicsAsAPage() {

Pageable pageable = new PageRequest(1,10);

Page topics = topicRepository.findAll(pageable);

assertNotNull(topics);

}

 类似资料: