- Building RESTful Web Services with Spring 5(Second Edition)
- Raja CSP Raman Ludovic Dewailly
- 202字
- 2021-06-30 19:13:30
Sample values in the repository
In order to use the repository, we will have to create a concrete class and fill in some values to test the GET operation. In the following method, we can do that:
package com.packtpub.reactive;
// import statements
public class UserRepositorySample implements UserRepository {
// initiate Users
private final Map<Integer, User> users = new HashMap<>();
// fill dummy values for testing
public UserRepositorySample() {
this.users.put(100, new User(100, "David"));
this.users.put(101, new User(101, "John"));
this.users.put(102, new User(102, "Kevin"));
}
}
In the preceding class, we just implemented UserRepository and filled in some sample values.
In order to simplify our code, we have used only application-based data storage, which means that once the application is restarted, our data will be reinitialized. In this case, we can't store any new data in our application. However, this will help us to focus on our main topics, such as Reactive and Spring 5, which are not related to persistence.
We can use this sample repository in the routing method:
public RouterFunction<ServerResponse> routingFunction() {
UserRepository repository = new UserRepositorySample();
UserHandler handler = new UserHandler(repository);
}
The preceding lines will insert dummy values in our repository. This will be enough for testing the GET operation.
- MERN Quick Start Guide
- GPS/GNSS原理與應(yīng)用(第3版)
- 5G承載網(wǎng)網(wǎng)絡(luò)規(guī)劃與組網(wǎng)設(shè)計(jì)
- 物聯(lián)網(wǎng)檢驗(yàn)檢測(cè)技術(shù)
- 計(jì)算機(jī)網(wǎng)絡(luò)安全實(shí)訓(xùn)教程(第二版)
- SD-WAN架構(gòu)與技術(shù)(第2版)
- 互聯(lián)網(wǎng)基礎(chǔ)資源技術(shù)與應(yīng)用發(fā)展態(tài)勢(shì)(2021—2023)
- 物聯(lián)網(wǎng)時(shí)代
- C/C++串口通信:典型應(yīng)用實(shí)例編程實(shí)踐
- 5G技術(shù)與標(biāo)準(zhǔn)
- 計(jì)算機(jī)網(wǎng)絡(luò)技術(shù)及應(yīng)用
- 物聯(lián)網(wǎng)工程概論
- 從實(shí)踐中學(xué)習(xí)手機(jī)抓包與數(shù)據(jù)分析
- 設(shè)備監(jiān)控技術(shù)詳解
- 互聯(lián)網(wǎng)安全的40個(gè)智慧洞見(2016)