代码拉取完成,页面将自动刷新
同步操作将从 huifer/Code-Analysis 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Author: HuiFer
源码阅读仓库: SourceHot-spring
类全路径: org.springframework.core.env.CommandLinePropertySource
作用: 用来存储命令行参数
public abstract class CommandLinePropertySource<T> extends EnumerablePropertySource<T> {
public static final String COMMAND_LINE_PROPERTY_SOURCE_NAME = "commandLineArgs";
public static final String DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME = "nonOptionArgs";
private String nonOptionArgsPropertyName = DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME;
public CommandLinePropertySource(T source) {
// 命令行参数, 属性值
super(COMMAND_LINE_PROPERTY_SOURCE_NAME, source);
}
public CommandLinePropertySource(String name, T source) {
// 参数名称, 参数值
super(name, source);
}
public void setNonOptionArgsPropertyName(String nonOptionArgsPropertyName) {
this.nonOptionArgsPropertyName = nonOptionArgsPropertyName;
}
@Override
public final boolean containsProperty(String name) {
// 输入值是否等于nonOptionArgs
if (this.nonOptionArgsPropertyName.equals(name)) {
// 等于后判断参数列表是否为空
return !this.getNonOptionArgs().isEmpty();
}
// 是否存在 name 属性
return this.containsOption(name);
}
@Override
@Nullable
public final String getProperty(String name) {
if (this.nonOptionArgsPropertyName.equals(name)) {
// 获取 非可选项参数列表
Collection<String> nonOptionArguments = this.getNonOptionArgs();
if (nonOptionArguments.isEmpty()) {
return null;
}
else {
// 可选参数命令行参数
return StringUtils.collectionToCommaDelimitedString(nonOptionArguments);
}
}
Collection<String> optionValues = this.getOptionValues(name);
if (optionValues == null) {
return null;
}
else {
// 命令行参数
return StringUtils.collectionToCommaDelimitedString(optionValues);
}
}
/**
* 是否存在 name 的命令行参数
*/
protected abstract boolean containsOption(String name);
/**
* 获取参数列表集合
*/
@Nullable
protected abstract List<String> getOptionValues(String name);
/**
* 获取 non-option 参数列表
*/
protected abstract List<String> getNonOptionArgs();
}
/**
* Return the collection of values associated with the command line option having the
* given name.
* <ul>
* <li>if the option is present and has no argument (e.g.: "--foo"), return an empty
* collection ({@code []})</li>
* <li>if the option is present and has a single value (e.g. "--foo=bar"), return a
* collection having one element ({@code ["bar"]})</li>
* <li>if the option is present and the underlying command line parsing library
* supports multiple arguments (e.g. "--foo=bar --foo=baz"), return a collection
* having elements for each value ({@code ["bar", "baz"]})</li>
* <li>if the option is not present, return {@code null}</li>
* </ul>
*
* 获取参数列表集合
*/
@Nullable
protected abstract List<String> getOptionValues(String name);
阅读注释可以知道该方法可以获取命令行参数的列表.
--foo
作为开头当输入命令行为 --foo=bar --foo=baz
在输入参数名称 foo
会得到数据bar,baz
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。