2014-05-14 1 views
0

재고 표준 휴식 CRUD API를 만들려고하는데 스프링 데이터 프레임 워크에서 제공되는 편리한 CrudRepository 클래스를 기록했습니다. 나는 또한 봄을 사용하여 @RequestMapping을 선언하여 URL 대응 (예 :/customer/{id} -> CrudRepository.findOne ({id}) 등)에 기본 crud 작업을 연결하도록 계획하고 있습니다.CrudRepository에 Spring의 기본 휴식 URI 끝점이 자동 매핑됩니다.

이것을 달성 할 수있는 봄용 유틸리티 클래스가 있습니까? 아니면 내 롤을 돌려야합니까?

답변

3

아하! 내가 찾고있는 건 org.springframework.data.rest.core.annotation.RepositoryRestResource 봄 데이터 나머지 webmvc 프로젝트에 위치해 있습니다. 받는다는 좌표 : "org.springframework.data:spring-data-rest-webmvc"

documentation에서 예 추출물이 저장소는 인터페이스이고 당신을 수

@RepositoryRestResource(collectionResourceRel = "people", path = "people") 
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> { 

    List<Person> findByLastName(@Param("name") String name); 

} 
enter code here 

Person 객체와 관련된 다양한 작업을 수행합니다. Spring Data Commons에 정의 된 PagingAndSortingRepositry 인터페이스를 확장하여 이러한 작업을 얻습니다.

런타임시 스프링 데이터 REST는이 인터페이스의 구현을 자동으로 작성합니다. 그런 다음 @RepositoryRestResource> 주석을 사용하여 Spring MVC가/people에 RESTful 끝점을 생성하도록 지시한다.