是在执行@ShellMethod
的过程中捕获用户输入的一种方法。基本上停止执行该方法以请求用户输入并在捕获之后继续进行。
这里有可能的解决方案:https://stackoverflow.com/a/50954716撰写的ZachOfAllTrades
它仅在您的应用程序基于SpringBoot时才有效,因此您可以访问由SpringBoot配置的LineReader
对象。
@Autowired
LineReader reader;
public String ask(String question) {
return this.reader.readLine("\n" + question + " > ");
}
@ShellMethod(key = { "setService", "select" }, value = "Choose a Speech to Text Service")
public void setService() {
boolean success = false;
do {
String question = "Please select a service.";
// Get Input
String input = this.ask(question);
// Input handling
/*
* do something with input variable
*/
success = true;
}
} while (!success);
}
不过,我自己也没试过。
你应该能够直接与System.in
交互,虽然它不是Spring Shell的真正含义:命令应该是自包含的。