-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b98f2d
commit 83d4e76
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.1.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<groupId>com.sanshengshui</groupId> | ||
<artifactId>netty-webflux</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>netty :: Webflux</name> | ||
|
||
<description>netty 之响应式编程</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- 实现对 Spring WebFlux 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
</dependency> | ||
|
||
<!-- 方便等会写单元测试 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
netty-webflux/src/main/java/com/sanshengshui/webflux/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.sanshengshui.webflux; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author james mu | ||
* @date 2019/12/10 17:16 | ||
*/ | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
netty-webflux/src/main/java/com/sanshengshui/webflux/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.sanshengshui.webflux.controller; | ||
|
||
import com.sanshengshui.webflux.vo.UserVO; | ||
import org.reactivestreams.Publisher; | ||
import org.springframework.web.bind.annotation.*; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author james mu | ||
* @date 2019/12/10 18:02 | ||
*/ | ||
@RestController | ||
@RequestMapping("/users") | ||
public class UserController { | ||
|
||
@GetMapping("/list") | ||
public Flux<UserVO> list() { | ||
List<UserVO> result = new ArrayList<>(); | ||
UserVO userVO = new UserVO(); | ||
userVO.setId(1); | ||
userVO.setUsername("mushuwei"); | ||
result.add(userVO); | ||
|
||
UserVO userVO1 = new UserVO(); | ||
userVO1.setId(2); | ||
userVO1.setUsername("sanshengshui"); | ||
result.add(userVO1); | ||
|
||
UserVO userVO2 = new UserVO(); | ||
userVO2.setId(3); | ||
userVO2.setUsername("jamesmsw"); | ||
result.add(userVO2); | ||
|
||
return Flux.fromIterable(result); | ||
} | ||
|
||
@GetMapping("/get") | ||
public Mono<UserVO> get(@RequestParam("id") Integer id) { | ||
UserVO userVO = new UserVO(); | ||
userVO.setId(id); | ||
userVO.setUsername("mushuwei"); | ||
return Mono.just(userVO); | ||
} | ||
|
||
@PostMapping("add") | ||
public Mono<Integer> add(@RequestBody Publisher<UserVO> addVO) { | ||
Integer returunId = 1; | ||
return Mono.just(returunId); | ||
} | ||
|
||
@PostMapping("/update") | ||
public Mono<Boolean> update(@RequestBody Publisher<UserVO> updateVO) { | ||
Boolean success = true; | ||
return Mono.just(success); | ||
} | ||
|
||
@PostMapping("/delete") | ||
public Mono<Boolean> delete(@RequestParam("id") Integer id) { | ||
Boolean success = false; | ||
return Mono.just(success); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
netty-webflux/src/main/java/com/sanshengshui/webflux/vo/UserVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sanshengshui.webflux.vo; | ||
|
||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author james mu | ||
* @date 2019/12/10 17:31 | ||
*/ | ||
@Data | ||
@ToString | ||
public class UserVO implements Serializable { | ||
|
||
private Integer id; | ||
|
||
private String username; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters