Spring 如何在WebFlux中验证请求参数
如何在WebFlux中验证请求参数 有什么建议可以使这段代码像使用JSR303和RestControllers时一样美观和简短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
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添加到相应的方法中。我只是不想把参数验证和业务逻辑混为一谈。