概述
什么是 spring webflux, 它是一種異步的, 非阻塞的, 支持背壓(back pressure)機制的web 開發框架. 要深入了解 spring webflux, 首先要了知道 reactive stream . 另一種編程姿勢, 和命令式編程相對的姿勢.
webflux 支持兩種編程風(姿)格(勢)
- 使用 @controller 這種基于注解的姿勢, 與sring mvc的姿勢相同
- 基于java 8 lambda的函數式編程風格
注意: 上面只是兩種編程的姿勢, 和"普通話和重慶話都是中國話"是一個道理. 我們公司也有外地的, 對他我說普通話, 對本地同事說重慶話. 這叫多態
創建項目
通過 http://start.spring.io 創建項目骨架.
如果是手工配置, 需要添加spring的里程碑(milestone)倉庫:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<repositories> <repository> <id>spring-snapshots</id> <name>spring snapshots</name> <url>https: //repo.spring.io/snapshot</url> <snapshots> <enabled> true </enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>spring milestones</name> <url>https: //repo.spring.io/milestone</url> <snapshots> <enabled> false </enabled> </snapshots> </repository> </repositories> <pluginrepositories> <pluginrepository> <id>spring-snapshots</id> <name>spring snapshots</name> <url>https: //repo.spring.io/snapshot</url> <snapshots> <enabled> true </enabled> </snapshots> </pluginrepository> <pluginrepository> <id>spring-milestones</id> <name>spring milestones</name> <url>https: //repo.spring.io/milestone</url> <snapshots> <enabled> false </enabled> </snapshots> </pluginrepository> </pluginrepositories> |
測試
列舉所有用戶
創建用戶
獲取單個用戶
修改
刪除
源碼
demo-spring-boot-webflux-annotaion
總結
以上所述是小編給大家介紹的使用 spring boot 2.0 + webflux 實現 restful api功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:https://segmentfault.com/a/1190000012896148