官术网_书友最值得收藏!

How to do it...

  1. We will start by adding another dependency to our build.gradle file in order to add the spring-boot-starter-data-rest artifact:
dependencies { 
  ... 
  compile("org.springframework.boot:spring-boot-starter-data-rest") 
  ... 
} 
  1. Now, let's create a new interface to define AuthorRepository in the src/main/java/com/example/bookpub/repository directory from the root of our project with the following content:
@RepositoryRestResource 
public interface AuthorRepository extends  
  PagingAndSortingRepository<Author, Long> { 
}
  1. While we are at it—given how little code it takes—let's create the repository interfaces for the remaining entity models, PublisherRepository and ReviewerRepository by placing the files in the same package directory as AuthorRepository with the following content:
@RepositoryRestResource 
public interface PublisherRepository extends  
  PagingAndSortingRepository<Publisher, Long> { 
} 

Otherwise, you can use the following code instead of the preceding code:

@RepositoryRestResource 
public interface ReviewerRepository extends  
  PagingAndSortingRepository<Reviewer, Long> { 
} 
  1. Start the application by running ./gradlew clean bootRun
  2. After the application has started, open the browser and go to http://localhost:8080/authors and you should see the following response:

主站蜘蛛池模板: 利津县| 合肥市| 新密市| 江北区| 镇平县| 天长市| 佛冈县| 安徽省| 泰来县| 板桥市| 锡林浩特市| 神池县| 辉南县| 磐安县| 泰宁县| 清水县| 厦门市| 鲜城| 巫溪县| 永定县| 安康市| 清新县| 淳化县| 铜梁县| 湘乡市| 宁河县| 简阳市| 浏阳市| 新巴尔虎右旗| 赣榆县| 海林市| 旬阳县| 翁源县| 武胜县| 翁牛特旗| 留坝县| 汤原县| 阿图什市| 关岭| 瑞丽市| 旺苍县|