此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Shell 3.3.0Spring中文文档

此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Shell 3.3.0Spring中文文档

当您的 shell 开始提供大量功能时,您最终可能会 有很多命令,这可能会让您的用户感到困惑。通过键入 , 他们会看到一个令人生畏的命令列表,按字母顺序排列, 这可能并不总是显示可用命令的最佳方式。helpSpring中文文档

为了减少这种可能的混淆,Spring Shell 提供了将命令组合在一起的功能, 具有合理的默认值。然后,相关命令将最终位于同一组中(例如,) 并一起显示在帮助屏幕和其他地方。User Management CommandsSpring中文文档

默认情况下,命令根据它们实现的类进行分组, 将 camelCase 类名转换为单独的单词(so 变成 )。 这是一个明智的默认值,因为相关命令通常已经在类中, 因为他们需要使用相同的协作对象。URLRelatedCommandsURL Related CommandsSpring中文文档

但是,如果此行为不适合您,则可以覆盖该组 命令按优先级顺序排列:Spring中文文档

  1. 在批注中指定 a。group()@ShellMethodSpring中文文档

  2. 在定义命令的类上放置 a。这适用 该类中定义的所有命令的组(除非被覆盖,如前所述)。@ShellCommandGroupSpring中文文档

  3. 在包装上放置一个(通过) 其中定义了命令。这适用于 包(除非在方法或类级别重写,如前所述)。@ShellCommandGrouppackage-info.javaSpring中文文档

以下列表显示了一个示例:Spring中文文档

public class UserCommands {
    @ShellMethod(value = "This command ends up in the 'User Commands' group")
    public void foo() {}

    @ShellMethod(value = "This command ends up in the 'Other Commands' group",
    	group = "Other Commands")
    public void bar() {}
}

...

@ShellCommandGroup("Other Commands")
public class SomeCommands {
	@ShellMethod(value = "This one is in 'Other Commands'")
	public void wizz() {}

	@ShellMethod(value = "And this one is 'Yet Another Group'",
		group = "Yet Another Group")
	public void last() {}
}