考慮Custom implementations for Spring Data repositories我使用存儲庫中的@RepositoryRestResource
把所有的HATEOAS產生goodnes:春季數據REST/HATEOAS用自定義的方法實現
@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<PersonNode,Long>,
PersonRepositoryCustom {
List<PersonNode> findBySurname(@Param("0") String name);
}
現在下面所提到的文檔,我創建了PersonRepositoryCustom
額外的,簡單的對於入門的目的方法:
public interface PersonRepositoryCustom {
public String printPerson(PersonNode personNode);
}
實現是:
public class PersonRepositoryImpl implements PersonRepositoryCustom{
@Override
public String printPerson(PersonNode personNode) {
return "It Works!";
}
}
我想讓默認的SDR自動生成的端點保持不變,只需添加新的自定義方法/新實現。 我該如何使用spring-data Rest/HATEOAS這個自定義方法? 使用簡單的@RepositoryRestResource
控制器端點自動生成。如果我想提供一些自定義方法怎麼辦?我認爲我將不得不手動創建控制器,但在這個示例中應該如何看待?