跳到主要内容

确认

QWen Max 中英对照 Confirmation

确认组件要求用户进行简单的确认。它本质上是一个是非问题。

@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();
}
}
java

以下屏幕录制显示了确认组件的典型输出:

上下文对象是 ConfirmationInputContext。下表描述了其上下文变量:

表 1. ConfirmationInputContext 模板变量

Key描述
defaultValue默认值 — truefalse
model父上下文变量(参见 TextComponentContext 模板变量)。