spring-data jpa로 스프링 데이터 나머지를 사용하여 자체 href에 대한 올바른 URL을 표시하는 데 문제가 있습니다. StudentInformation 클래스스프링 데이터 - 나머지 잘못된 리소스 href
@Entity
@Table(name="studentinformation", schema="main")
public class StudentInformation {
@Id
private Long id;
...
...
}
(다른 속성/게터/세터도 있습니다 해당 저장소 파일
@RepositoryRestResource(collectionResourceRel = "students", path = "students")
public interface StudentRepository extends PagingAndSortingRepository<Student, Long> {
}
와
@Entity
@Table(name="student", schema="main")
public class Student {
@Id
private Long id;
...
...
@OneToOne
@JoinColumn(name = "id")
private StudentInformation studentInformation;
}
:
그래서 나는 학생 클래스가 생략 됨)
해당 저장소 내가 ID로 하나를 검색 할 때이 기대하는 것처럼@RepositoryRestResource(collectionResourceRel = "studentinformation", path = "students/studentinformation")
public interface StudentInformationRepository extends CrudRepository<StudentInformation, Long> {
}
학생 디스플레이와
, 내가 studentInformation 학생들의 링크를 따라하는 경우를 제외하고
{
"id": 1,
...
...
"_links": {
"self": {
"href": "http://localhost:8080/students/1"
},
"student": {
"href": "http://localhost:8080/students/1"
},
"studentinformation": {
"href": "http://localhost:8080/students/1/studentinformation"
}
}
}
, studentInformation는있다 잘못된 자기 링크.
{
"id": 1,
...
...
"_links": {
"self": {
"href": "http://localhost:8080/students/studentinformation/1"
},
"studentinformation": {
"href": "http://localhost:8080/students/studentinformation/1"
}
}
}
가 어떻게 "HREF"를 읽어 해당 링크를받을 수 있나요 : HREF "http://localhost:8080/students/1/studentinformation 대신 의" ":"http://localhost:8080/students/studentinformation/1 "
모두 감사의
응답 해 주셔서 감사합니다. 그렇다면 자체 href URL에 리소스를 스택 할 방법이 없다는 말입니까? like, 'http : // localhost : 8080/RESOURCE/{ID}/SUB_RESOURCE' @RepositoryRestResource 사용? 내 자신의 사용자 지정 REST 컨트롤러를 정의해야합니까? 이상하게 보입니다. – user2254140
불행히도 예, 최소한 제공된 저장소의 링크가 아닌지 확인할 수 있습니다. 당신이 그것을 할 수있는 어떤 방법을 발견한다면 - 알고 좋은 것입니다. 이를 수행 할 수있는 방법은 사용자 정의 구현으로 @RepositoryRestController를 정의하고이를 자원과 연관시키는 것입니다. –
저장소 구현으로 가고 싶다면'SUB_RESOURCE/{ID}? RESOURCE_ID = {RESOURCE_ID}'할 수 있습니다. –