- 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:
推薦閱讀
- MySQL從入門到精通(第3版)
- 云計算與大數據應用
- MATLAB Graphics and Data Visualization Cookbook
- 深入淺出Greenplum分布式數據庫:原理、架構和代碼分析
- PostgreSQL指南:內幕探索
- 達夢數據庫運維實戰
- openGauss數據庫核心技術
- 企業大數據處理:Spark、Druid、Flume與Kafka應用實踐
- 算力經濟:從超級計算到云計算
- 數據指標體系:構建方法與應用實踐
- Visual Studio 2012 and .NET 4.5 Expert Development Cookbook
- 數據庫基礎與應用
- Hadoop大數據技術開發實戰
- 一本書講透數據治理:戰略、方法、工具與實踐
- 高效使用Redis:一書學透數據存儲與高可用集群