码迷,mamicode.com
首页 > Web开发 > 详细

WebFlux系列(七)WebClient Post传参

时间:2020-01-13 10:36:36      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:getname   static   stc   bilibili   web   tar   public   reactor   ica   

#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传参

标签:getname   static   stc   bilibili   web   tar   public   reactor   ica   

原文地址:https://www.cnblogs.com/JavaWeiBianCheng/p/12185972.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!