验证

Spring Shell 与 Bean Validation API 集成,支持对命令参数进行自动和自文档化的约束。

命令参数和方法级别的注解会得到遵守,并在命令执行之前触发验证。考虑以下命令

	@ShellMethod("Change password.")
	public String changePassword(@Size(min = 8, max = 40) String password) {
		return "Password successfully set to " + password;
	}

从前面的示例中,您免费获得以下行为

shell:>change-password hello
The following constraints were not met:
	--password : size must be between 8 and 40 (You passed 'hello')
© . This site is unofficial and not affiliated with VMware.