persist会话

k2arahey  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(244)

什么是等效的:

@GetMapping("/v1/shop-products/search")
    private Flux<FoundProduct> getShopProducts(@RequestParam String code, WebSession webSession) {

        webSession.start();

        return productService.findShopProductsByCode(code)
                .subscriberContext(context -> context.put("SESSION", webSession));
    }

对于springwebflux中的函数请求处理程序。我无法将会话示例传递到上下文中,这是我的处理程序:

@Override
    public Mono<ServerResponse> handle(ServerRequest serverRequest) {
        Optional<String> productCode = serverRequest.queryParam("code");
        if (productCode.isEmpty()) {
            return ServerResponse.badRequest()
                                 .build();
        }

        Flux<FoundProduct> shopProductsByCode = serverRequest.session()
                                                             .flatMapMany(webSession -> productService.findShopProductsByCode(productCode.get()))
                                                             .subscriberContext(ctx -> ctx.put("SESSION", "")); // here I'd like to pass session object

        return ServerResponse.ok()
                             .contentType(MediaType.APPLICATION_JSON)
                             .body(shopProductsByCode, FoundProduct.class);
    }

带注解的控制器工作正常,我可以在较低的函数中访问会话。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题