概述
什么是 spring webflux, 它是一種異步的, 非阻塞的, 支持背壓(back pressure)機(jī)制的web 開(kāi)發(fā)框架. 要深入了解 spring webflux, 首先要了知道 reactive stream . 另一種編程姿勢(shì), 和命令式編程相對(duì)的姿勢(shì).
webflux 支持兩種編程風(fēng)(姿)格(勢(shì))
- 使用 @controller 這種基于注解的姿勢(shì), 與sring mvc的姿勢(shì)相同
- 基于java 8 lambda的函數(shù)式編程風(fēng)格
注意: 上面只是兩種編程的姿勢(shì), 和"普通話和重慶話都是中國(guó)話"是一個(gè)道理. 我們公司也有外地的, 對(duì)他我說(shuō)普通話, 對(duì)本地同事說(shuō)重慶話. 這叫多態(tài)
創(chuàng)建項(xiàng)目
通過(guò) http://start.spring.io 創(chuàng)建項(xiàng)目骨架.
如果是手工配置, 需要添加spring的里程碑(milestone)倉(cāng)庫(kù):
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> |
測(cè)試
列舉所有用戶
創(chuàng)建用戶
獲取單個(gè)用戶
修改
刪除
源碼
demo-spring-boot-webflux-annotaion
總結(jié)
以上所述是小編給大家介紹的使用 spring boot 2.0 + webflux 實(shí)現(xiàn) restful api功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!
原文鏈接:https://segmentfault.com/a/1190000012896148