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

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:

主站蜘蛛池模板: 东乌珠穆沁旗| 黔西| 成安县| 荣昌县| 榕江县| 治多县| 宕昌县| 乌兰察布市| 宜昌市| 商河县| 都安| 革吉县| 揭西县| 富川| 宾阳县| 呼和浩特市| 大厂| 镇康县| 泰和县| 乐山市| 晋中市| 上林县| 蒲城县| 耿马| 抚州市| 确山县| 象州县| 平遥县| 芦山县| 东丽区| 中宁县| 淳化县| 左云县| 苏尼特左旗| 华坪县| 马尔康县| 罗江县| 延川县| 平南县| 通山县| 德江县|