IntelliJ中的CLI-Spring Shell

Saj*_*had 9 java command-line-interface spring-shell

我正在使用IntelliJ中的CLI Spring shell代码.我运行它并给出一些参数.但是当我输入insert并按回车键时,控制台不接受它,看起来好像什么也没发生!

我的代码:

@Component
public class HelloWorldCommands implements CommandMarker {

    @CliCommand(value = "insert", help = "insert data to ParsEMS DB")
    public void insert() {
        try {
            Class.forName("org.postgresql.Driver");
            Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ParsEMS", "xxxxxx", "xxxxxxx");
            Statement st = con.createStatement();
            st.executeUpdate("INSERT INTO node (name, destination) VALUES ('b', 200)");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("insert to ParsEMS DB");
    }
}



public class Main {
    public static void main(String[] args) throws Exception {
        Bootstrap.main(args);
    }
}   
Run Code Online (Sandbox Code Playgroud)

我跑的时候会看到以下结果;

1.1.0.RELEASE

欢迎来到Spring Shell.如需帮助,请按或键入"提示",然后按ENTER键.

弹簧壳>

4F2*_*A2E 20

Spring Shell使用Jline.您必须编辑Intellij中的运行配置并添加vm选项参数,如下所示:

Unix机器:

-Djline.terminal=org.springframework.shell.core.IdeTerminal
Run Code Online (Sandbox Code Playgroud)

在Windows机器上:

-Djline.WindowsTerminal.directConsole=false -Djline.terminal=jline.UnsupportedTerminal
Run Code Online (Sandbox Code Playgroud)

  • 没问题!您基本上必须扩展 DefaultPromptProvider.class 并返回您自己的字符串,请参阅 https://gist.github.com/4F2E4A2E/96ec03bdd9ac457b5206 (2认同)