WebFlux系列WebClient Post传参

Posted JAVA微编程

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WebFlux系列WebClient Post传参相关的知识,希望对你有一定的参考价值。

#Java#Spring#WebFlux#WebClient#Post#传参#Body#

WebClient如何通过Body以Post方式传参

视频讲解: https://www.bilibili.com/video/av82795780/

WebfluxServerApplication.java
package com.example.webfluxserver;

import lombok.extern.log4j.Log4j2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@Log4j2
@SpringBootApplication
public class WebfluxServerApplication extends BaseApplication {
    public static void main(String[] args) {
        SpringApplication.run(WebfluxServerApplication.class, args);
    }
    @RestController
    class EmployeeController {
        @PostMapping(value = "save")
        public Mono<Boolean> save(@RequestBody Mono<Employee> employeeMono) {
            Mono<Boolean> employeeMono1 = employeeMono.flatMap(employee -> {
                employee.setName(employee.getName() + " had updated");
                //save...
                return Mono.just(Boolean.TRUE);
            });
            return employeeMono1;
        }
    }
}
WebfluxConsumerApplication.java
package com.example.webfluxserver;

import lombok.extern.log4j.Log4j2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@Log4j2
@SpringBootApplication
public class WebfluxServerApplication extends BaseApplication {
    public static void main(String[] args) {
        SpringApplication.run(WebfluxServerApplication.class, args);
    }
    @RestController
    class EmployeeController {
        @PostMapping(value = "save")
        public Mono<Boolean> save(@RequestBody Mono<Employee> employeeMono) {
            Mono<Boolean> employeeMono1 = employeeMono.flatMap(employee -> {
                employee.setName(employee.getName() + " had updated");
                //save...
                return Mono.just(Boolean.TRUE);
            });
            return employeeMono1;
        }
    }
}

公众号,坚持每天3分钟视频学习

以上是关于WebFlux系列WebClient Post传参的主要内容,如果未能解决你的问题,请参考以下文章

WebFlux系列WebClient 日志

WebFlux系列WebClient 异常处理

WebFlux系列WebClient VS RestTemplate

Spring WebFlux,如何调试我的 WebClient POST 交换?

Spring WebFlux WebClient - 如何解决 400 错误请求

在 WebFlux WebClient 中测试状态码时如何获取响应正文?