HAL이 Spring Data Rest 행동하는 방법을 읽은 후 약간의 버그가있을 수 있습니다.
이것은 tasks
수집 자원에 대한 표준 스프링 데이터 나머지 links
출력은 다음과 같습니다
"_links": {
"first": {
"href": "http://localhost:8080/tasks?page=0&size=20"
},
"self": {
"href": "http://localhost:8080/tasks"
},
"next": {
"href": "http://localhost:8080/tasks?page=1&size=20"
},
"last": {
"href": "http://localhost:8080/tasks?page=2&size=20"
},
"profile": {
"href": "http://localhost:8080/profile/tasks"
},
"search": {
"href": "http://localhost:8080/tasks/search"
}
없음 링크에 표시된 것과 달리 봄 데이터 나머지에 의해 렌더링 박스 HAL 응답,에서의 템플릿되고 있지 docs. 내가 next
링크를 따라하는 경우
는 self
링크는 올바르지 않습니다 :
"_links": {
"first": {
"href": "http://localhost:8080/tasks?page=0&size=20"
},
"prev": {
"href": "http://localhost:8080/tasks?page=0&size=20"
},
"self": {
"href": "http://localhost:8080/tasks"
},
"next": {
"href": "http://localhost:8080/tasks?page=2&size=20"
},
"last": {
"href": "http://localhost:8080/tasks?page=2&size=20"
},
"profile": {
"href": "http://localhost:8080/profile/tasks"
},
"search": {
"href": "http://localhost:8080/tasks/search"
}
}
나는 컨트롤러 오버라이드 (override)하는 경우 :
@RequestMapping(method = RequestMethod.GET, path = "/tasks")
public ResponseEntity<Page<Task>> read(Pageable pageRequest, PersistentEntityResourceAssembler assembler) {
Page<Task> pendingTasks = taskService.read(pageRequest);
return new ResponseEntity(pageAssembler.toResource(pendingTasks, (ResourceAssembler) assembler),
HttpStatus.OK);
}
을 그리고 Pageable
를 초기화 컨트롤러와 저장소 사이에 서비스를 추가 인스턴스가 지정되지 않은 경우에도 인스턴스를 기본값으로 설정합니다.
public Page<Task> read(Pageable pageRequest) {
Pageable effectivePageRequest = pageRequest;
if (effectivePageRequest == null) {
effectivePageRequest = new PageRequest(0, 20, DEFAULT_SORT);
}
if (effectivePageRequest.getSort() == null) {
//override Sort
effectivePageRequest = new PageRequest(effectivePageRequest.getPageNumber(),
effectivePageRequest.getPageSize(), DEFAULT_SORT);
}
return taskRepository.findByStatus(Task.Status.PENDING, effectivePageRequest);
}
self
링크의 문제를 해결할 수 있습니다. 그러나 템플리트 화 된 URI를 생성 할 방법이 없습니다. 다음은 두 번째 페이지에 대한 링크입니다 :이 가능성을 폐기하는 데 도움이
"_links": {
"first": {
"href": "http://localhost:8080/tasks?page=0&size=20&sort=created,desc"
},
"prev": {
"href": "http://localhost:8080/tasks?page=0&size=20&sort=created,desc"
},
"self": {
"href": "http://localhost:8080/tasks?page=1&size=20&sort=created,desc"
},
"next": {
"href": "http://localhost:8080/tasks?page=2&size=20&sort=created,desc"
},
"last": {
"href": "http://localhost:8080/tasks?page=2&size=20&sort=created,desc"
}
희망하지만, 여기에 표시된 기본 동작은 수집 링크를 생성 할 때 봄 HATEOAS/봄 데이터 나머지 몇 가지 문제가있을 수 있음을 시사한다.
내가 org.springframework.boot:spring-boot-starter-data-rest:jar:1.4.0.RELEASE
, org.springframework.data:spring-data-rest-webmvc:jar:2.5.2.RELEASE
, org.springframework.hateoas:spring-hateoas:jar:0.20.0.RELEASE
같은 결과는 selfrel에서 어떤 템플릿을 사용하고 있습니다. –
자신을 템플릿으로 만들 때 템플릿이 표시됩니까? 예를 들어,'http : // localhost : 8080/projects? size = 2'에 접근하면 –
첫 번째, 다음 그리고 마지막 링크는 잘 동작합니다. 그것들은 각 매개 변수로 올바르게 설정됩니다. selfref의 템플릿 정보가 누락되었습니다 .--( –