本文介绍了Spring 5 Webflux功能端点-如何执行输入验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据当前文档(5.0.0.RELEASE),Spring Webflux在使用带注释的控制器时支持验证:

According to the current doc (5.0.0.RELEASE) Spring Webflux supports validation when working with annotated controllers:

但是,关于如何使用功能性端点使它自动化的内容却一言不发.实际上,文档中输入处理的唯一示例无法验证任何内容:

However nothing is said about how to automate it with functional endpoints. In fact, the only example of input processing in the documentation doesn't validate anything:

public Mono<ServerResponse> createPerson(ServerRequest request) {
    Mono<Person> person = request.bodyToMono(Person.class);
    return ServerResponse.ok().build(repository.savePerson(person));
}

我们应该手动执行此操作还是有一些自动方法来执行此操作?

Are we supposed to do this manually or there is some automatic way to do it?

推荐答案

在Spring 5.0中,没有在功能端点中进行验证的自动方法,因此必须手动进行验证.

In Spring version 5.0, there is no automatic way to do validation in functional endpoints, and as such validation must be done manually.

尽管目前尚无具体计划,但将来我们可能会添加某种形式的验证.但是即使那样,它将是一个显式的方法调用,而不是自动的机制.总体而言,功能端点模型的设计比基于注释的模型要明确得多.

Though there are currently no concrete plans to do so, we might add some sort of validation in the future. But even then it will be an explicit method call, and not an automatic mechanism. Overall, the functional endpoint model is designed to be a lot more explicit than the annotation-based model.

这篇关于Spring 5 Webflux功能端点-如何执行输入验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:09