Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何在WebFlux中验证请求参数_Spring_Spring Boot_Spring Webflux - Fatal编程技术网

Spring 如何在WebFlux中验证请求参数

Spring 如何在WebFlux中验证请求参数,spring,spring-boot,spring-webflux,Spring,Spring Boot,Spring Webflux,如何在WebFlux中验证请求参数 有什么建议可以使这段代码像使用JSR303和RestControllers时一样美观和简短 public Mono<ServerResponse> getStatistic(ServerRequest request) { Integer pageSize = request.queryParam(Constants.SIZE_PARAM) .map(Integer::parseInt) .f

如何在WebFlux中验证请求参数

有什么建议可以使这段代码像使用JSR303和RestControllers时一样美观和简短

public Mono<ServerResponse> getStatistic(ServerRequest request) {
    Integer pageSize = request.queryParam(Constants.SIZE_PARAM)
            .map(Integer::parseInt)
            .filter(x -> x.compareTo(Constants.MAX_PAGE_SIZE) <= 0)
            .orElseThrow(() -> new IllegalArgumentException("..."));
    // ...

}
公共Mono getStatistic(服务器请求){ 整数pageSize=request.queryParam(常数.SIZE\u参数) .map(整数::parseInt) .filter(x->x.compareTo(Constants.MAX\u PAGE\u SIZE)新的IllegalArgumentException(“…”); // ... }
我假设您有(at)个用(at)RestController注释的类的(at)有效方法内签名。在WebFlux中,我没有找到一个解决方案来处理处理程序类。因此,我将@Validated添加到我的(at)服务类中,并将@Validated添加到相应的方法中。我只是不想把参数验证和业务逻辑混为一谈。