- Spring Boot 2.0 Cookbook(Second Edition)
- Alex Antonov
- 155字
- 2021-06-24 19:24:40
How to do it...
- 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") ... }
- 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> { }
- 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> { }
- Start the application by running ./gradlew clean bootRun
- After the application has started, open the browser and go to http://localhost:8080/authors and you should see the following response:
推薦閱讀
- 同步:秩序如何從混沌中涌現
- 計算機組成原理與接口技術:基于MIPS架構實驗教程(第2版)
- 達夢數據庫編程指南
- Python金融大數據分析(第2版)
- Voice Application Development for Android
- Learning Spring Boot
- Mastering Machine Learning with R(Second Edition)
- “互聯網+”時代立體化計算機組
- ZeroMQ
- Proxmox VE超融合集群實踐真傳
- 云原生數據中臺:架構、方法論與實踐
- Construct 2 Game Development by Example
- 數字IC設計入門(微課視頻版)
- Access 2010數據庫程序設計實踐教程
- Hands-On System Programming with C++