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

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:

主站蜘蛛池模板: 榆树市| 丹凤县| 镇宁| 巨野县| 铜陵市| 新宾| 睢宁县| 永城市| 武威市| 赤水市| 小金县| 兴国县| 武宣县| 武川县| 东乡县| 辰溪县| 阜康市| 抚顺市| 乡城县| 砀山县| 怀化市| 化德县| 通江县| 泗水县| 酉阳| 孝昌县| 年辖:市辖区| 布尔津县| 晋州市| 衡阳市| 庆城县| 荥经县| 宣恩县| 富宁县| 彰化市| 上虞市| 南昌县| 内黄县| 漯河市| 双鸭山市| 股票|