此版本仍在开发中,尚未被认为是稳定版。请使用最新稳定版 Spring Shell 4.0.1spring-doc.cadn.net.cn

数字输入

The number输入组件请求用户进行简单的数字输入。它可以配置为使用Number类的任何实现。以下示例展示了如何使用该组件:spring-doc.cadn.net.cn

NumberInput component = new NumberInput(getTerminal(), "Enter value", 99.9, Double.class);
ResourceLoader resourceLoader = null; // getResourceLoader();
TemplateExecutor templateExecutor = null; // getTemplateExecutor();
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);

NumberInputContext context = component.run(NumberInputContext.empty());
return "Got value " + context.getResultValue();

以下图片展示了典型的数字输入组件的输出:spring-doc.cadn.net.cn

The context对象是NumberInputContext。以下表格列出了其上下文变量:spring-doc.cadn.net.cn

表 1. NumberInputContext 模板变量
描述

defaultValuespring-doc.cadn.net.cn

默认值,如果设置。否则,null.spring-doc.cadn.net.cn

defaultClassspring-doc.cadn.net.cn

The default number class to use, if set. Otherwise, Integer.class.spring-doc.cadn.net.cn

requiredspring-doc.cadn.net.cn

true 如果输入是必需的。否则,为 falsespring-doc.cadn.net.cn

modelspring-doc.cadn.net.cn

The parent context variables (see TextComponentContext 模板变量).spring-doc.cadn.net.cn