温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能

发布时间:2020-10-11 22:55:13 来源:脚本之家 阅读:321 作者:mrr 栏目:编程语言

概述

什么是 Spring WebFlux, 它是一种异步的, 非阻塞的, 支持背压(Back pressure)机制的Web 开发框架. 要深入了解 Spring WebFlux, 首先要了知道 Reactive Stream . 另一种编程姿势, 和命令式编程相对的姿势.

WebFlux 支持两种编程风(姿)格(势)

  • 使用 @Controller 这种基于注解的姿势, 与Sring MVC的姿势相同
  • 基于Java 8 Lambda的函数式编程风格

注意: 上面只是两种编程的姿势, 和"普通话和重庆话都是中国话"是一个道理. 我们公司也有外地的, 对他我说普通话, 对本地同事说重庆话. 这叫多态

创建项目

通过 http://start.spring.io 创建项目骨架.

使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能 

如果是手工配置, 需要添加Spring的里程碑(Milestone)仓库:

<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>

测试

列举所有用户 

使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能 

创建用户 

使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能 

获取单个用户

使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能 

修改

使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能 

删除 

使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能 

源码

demo-spring-boot-webflux-annotaion

总结

以上所述是小编给大家介绍的使用 Spring Boot 2.0 + WebFlux 实现 RESTful API功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对亿速云网站的支持!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI