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

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:

主站蜘蛛池模板: 比如县| 抚宁县| 涟源市| 沈阳市| 精河县| 巴彦淖尔市| 石楼县| 团风县| 思南县| 怀仁县| 张家港市| 镇江市| 济阳县| 临清市| 桃源县| 镇江市| 鸡泽县| 盐池县| 正宁县| 石河子市| 刚察县| 石屏县| 肥西县| 伊金霍洛旗| 梁山县| 平定县| 紫云| 海南省| 奉贤区| 绿春县| 平湖市| 天水市| 柳州市| 庄河市| 仪陇县| 娄烦县| 台山市| 和硕县| 阜城县| 赣州市| 马边|