[Spring Boot] - 对 Data REST 的支持
在文章[Spring Boot] - RESTful {Controller层的业务设计}中,通过在Controller中引入xxxRepository来对外提供REST API。Spring Boot还可以通过spring-boot-starter-data-rest
来对外提供REST API,可以免于编写对应的Controller,且具备分页和排序的功能。
官网:User Guides
实践
在pom文件中添加Spring Boot 对Data REST支持的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
@RepositoryRestResource注解让编程人员可以直接通过repository提供数据接口,在这个“前端负责V和C,后端负责提供数据”的时代,非常方便;并且,可以通过给该注解传入参数来改变URL。
只要在项目的classpath中包含spring-boot-starter-data-rest,同时就包含了spring-hateoas库支持,这个库可以提供ALPS元数据——一种数据格式,可以用于描述应用级别的API语义。
参考资料:
文/杜琪(简书作者)
原文链接:http://www.jianshu.com/p/3ea7170a1099
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。