2016-10-03 2 views
0

문제점을 설명하기 위해 약간의 샘플 프로젝트를 구현했습니다. 그것은 여기에 있어요 :@ 프로젝션이 작동하지 않습니다.

https://github.com/jvillane/spring-boot-hateoas-rest 

내가 뭘 같은 법인의 @Projection 여러 년대 만드는 할 노력하고있어 :

@Projection(name = "S", types = User.class) public interface UserS { String getName(); } @Projection(name = "M", types = User.class) public interface UserM { String getName(); String getDni(); } @Projection(name = "L", types = User.class) public interface UserL { String getName(); String getDni(); Country getCountry(); } 

을 그리고 얻기 위해 그들을 사용하여 더 많은 또는 을 덜 전화 번호 (따옴표 포함 또는 불포함) :

http://localhost:8080/api/users/1?projection=S 
http://localhost:8080/api/users/1?projection=M 
http://localhost:8080/api/users/1?projection=L 

그러나 응답에서 차이를 만들지는 않습니다. 기본 방법을 사용하여 개체 정보를 표시하는 것과 같습니다.

내가 뭘 잘못하고 있는지 모르겠다. 어떤 도움도 환영합니다.

답변

2

다음을 참조하십시오. 귀하의 프로젝션 정의가 해당 엔티티와 동일한 패키지 (또는 서브 패키지)에 있습니까?

http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.projections

어떻게 봄 데이터 REST가 투사 정의를 발견합니까?

정의와 동일한 패키지에서 발견 된 모든 인터페이스 @Projection 인터페이스 (또는 그 하위 패키지 중 하나)가 등록됩니다.

RepositoryRestConfiguration.getProjectionConfiguration().addProjection(…)을 통해 수동으로 등록 할 수 있습니다.

어느 경우 든 프로젝션을 사용하는 인터페이스는 @Projection 주석을 가져야합니다.