feat(新增): Flux和Mono使用

This commit is contained in:
Bunny 2024-08-07 23:42:45 +08:00
parent 269bcf7225
commit 4ae7bd5437
6 changed files with 69 additions and 49 deletions

View File

@ -56,6 +56,17 @@
<artifactId>spring-context-support</artifactId> <artifactId>spring-context-support</artifactId>
<version>6.1.6</version> <version>6.1.6</version>
</dependency> </dependency>
<!-- webflux -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
<version>4.1.111.Final</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,55 @@
package cn.bunny.service.controller;
import cn.bunny.pojo.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.Duration;
import java.util.ArrayList;
@Tag(name = "webflux测试i请求接口")
@RequestMapping("/api")
@RestController
public class WebFluxController {
@Operation(summary = "Mono测试")
@GetMapping("test1")
public Mono<Result<String>> test1() {
Result<String> result = Result.success("测试成功啦第一个Mono");
return Mono.just(result);
}
@Operation(summary = "Flux测试")
@GetMapping("test2")
public Flux<Result<ArrayList<String>>> test2() {
ArrayList<String> list = new ArrayList<>() {
{
add("Flux测试返回的是数组");
add("数组啊啊啊啊");
}
};
Result<ArrayList<String>> result = Result.success(list);
return Flux.just(result);
}
@Operation(summary = "模仿ChatGPT")
@GetMapping("test3")
public Flux<String> test3() {
ArrayList<String> list = new ArrayList<>() {
{
add("Flux测试返回的是数组");
add("数组啊啊啊啊");
}
};
Result<ArrayList<String>> result = Result.success(list);
return Flux.range(1, 10).map(i -> "输出:" + i).delayElements(Duration.ofMillis(500));
}
}

View File

@ -4,4 +4,4 @@ bunny:
port: 3306 port: 3306
sqlData: myDS sqlData: myDS
username: root username: root
password: "123456" password: "02120212"

View File

@ -4,8 +4,7 @@ bunny:
port: 3306 port: 3306
sqlData: myDS sqlData: myDS
username: root username: root
password: "123456" password: "02120212"
knife4j: knife4j:
enable: true enable: true

View File

@ -7,5 +7,5 @@ org.quartz.jobStore.dataSource=myDS
org.quartz.dataSource.myDS.driver=com.mysql.cj.jdbc.Driver org.quartz.dataSource.myDS.driver=com.mysql.cj.jdbc.Driver
org.quartz.dataSource.myDS.URL=jdbc:mysql://192.168.3.98:3306/myDS?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true org.quartz.dataSource.myDS.URL=jdbc:mysql://192.168.3.98:3306/myDS?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
org.quartz.dataSource.myDS.user=root org.quartz.dataSource.myDS.user=root
org.quartz.dataSource.myDS.password=123456 org.quartz.dataSource.myDS.password=02120212
org.quartz.dataSource.myDS.maxConnections=5 org.quartz.dataSource.myDS.maxConnections=5

View File

@ -1,45 +0,0 @@
<body style="margin: 0; padding: 0; background-color: #f5f5f5;">
<div style="max-width: 600px; margin: 0 auto;">
<table style="width: 100%; border-collapse: collapse; background-color: #ffffff; font-family: Arial, sans-serif;">
<tr>
<th style="height: 60px; padding: 20px; background-color: #0074d3; border-radius: 5px 5px 0 0;"
valign="middle">
<h1 style="margin: 0; color: #ffffff; font-size: 24px;">BunnyBBS邮箱验证码</h1>
</th>
</tr>
<tr>
<td style="padding: 20px;">
<div style="background-color: #ffffff; padding: 25px;">
<h2 style="margin: 10px 0; font-size: 18px; color: #333333;">
尊敬的用户,
</h2>
<p style="margin: 10px 0; font-size: 16px; color: #333333;">
感谢您注册我们的产品. 您的账号正在进行电子邮件验证.
</p>
<p style="margin: 10px 0; font-size: 16px; color: #333333;">
验证码为: <span class="button" style="color: #1100ff;">${verifyCode}</span>
</p>
<p style="margin: 10px 0; font-size: 16px; color: #333333;">
验证码的有效期只有一分钟,请抓紧时间进行验证吧!
</p>
<p style="margin: 10px 0; font-size: 16px; color: #dc1818;">
如果非本人操作,请忽略此邮件
</p>
</div>
</td>
</tr>
<tr>
<td style="text-align: center; padding: 20px; background-color: #f5f5f5;">
<p style="margin: 0; font-size: 12px; color: #747474;">
XXXXX<br>
Contact us: XXXXXXX@qq.com
</p>
<p style="margin: 10px 0; font-size: 12px; color: #747474;">
This is an automated email, please do not reply.<br>
© Company Name
</p>
</td>
</tr>
</table>
</div>
</body>