深入理解 SpringBoot 注解 @ShellMethod
特别说明
当前文章内容迁移中,如有问题,请提交 issues 谢谢~~
@ShellMethod
将一个方法声明为 Shell 命令。默认情况下:
- 方法名为命令名称
- 类名称为
shell
所属分组 - springshell 默认将驼峰方法名用
-
连接符替换caculateSum -> caculate-sum
一. 定义 shell 属性
@ShellMethod(value = "caculate two value sum", key = {"add","sum"}, group = "group1", prefix = "-")
public int sum(int a, int b){
return a + b;
}
二. 查看分组名
在终端,使用 help 命令,查看更多信息。
help
三. 方法调用
shell:>add 2 1
3
shell:>sum 2 1
3
带参调用
shell:>add -a 2 -b 1
3