Validation
Spring Shell 与 Bean Validation API 相集成,支持命令参数的自动和自文档式的限制。
Spring Shell integrates with the Bean Validation API to support automatic and self-documenting constraints on command parameters.
将遵守命令参数上的注释和方法级别的注释,并在执行命令前触发验证。考虑以下命令:
Annotations found on command parameters and annotations at the method level are honored and trigger validation prior to the command executing. Consider the following command:
@ShellMethod("Change password.")
public String changePassword(@Size(min = 8, max = 40) String password) {
return "Password successfully set to " + password;
}
从前面的示例中,您将免费获得以下行为:
From the preceding example, you get the following behavior for free:
shell:>change-password hello The following constraints were not met: --password string : size must be between 8 and 40 (You passed 'hello')