确认
确认组件要求用户进行简单的确认。它本质上是一个是非问题。
@ShellComponent
public class ComponentCommands extends AbstractShellComponent {
@ShellMethod(key = "component confirmation", value = "Confirmation input", group = "Components")
public String confirmationInput(boolean no) {
ConfirmationInput component = new ConfirmationInput(getTerminal(), "Enter value", !no);
component.setResourceLoader(getResourceLoader());
component.setTemplateExecutor(getTemplateExecutor());
ConfirmationInputContext context = component.run(ConfirmationInputContext.empty());
return "Got value " + context.getResultValue();
}
}
以下屏幕录制显示了确认组件的典型输出:
上下文对象是 ConfirmationInputContext
。下表描述了其上下文变量:
表 1. ConfirmationInputContext 模板变量
Key | 描述 |
---|---|
defaultValue | 默认值 — true 或 false 。 |
model | 父上下文变量(参见 TextComponentContext 模板变量)。 |