如何在WebFlux中验证请求参数

时间:2017-12-06 17:13:34

标签: spring spring-boot spring-webflux

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

是否有任何建议使这段代码与使用JSR 303和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("..."));
    // ...

}

0 个答案:

没有答案