WebFlux系列(九)WebClient Uri列表、数组传参

丶灬走出姿态 提交于 2020-02-28 04:52:10

#Java#Spring#WebFlux#Reactor#WebClient#Uri#传参#数组#列表#

WebClient Uri列表、数组传参

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

服务端:

@RestController
class EmployeeController {
    @GetMapping("employee")
    public Mono<String> requestList(@RequestParam List<String> names, ServerHttpRequest request){
        names.stream().forEach(System.out::println);
        return Mono.just(request.getURI().toString());
    }
}

客户端:

@RestController
class EmployeeController {
  @GetMapping("employee/{names}")
  public Mono<String> request(@PathVariable List<String> names) {
    return WebClient.create(baseUrl)
        .get()
        .uri(uriBuilder -> uriBuilder.path("/employee")
            .queryParam("names", names)
            .build())
        .retrieve()
        .bodyToMono(String.class);
  }
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!