11

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

我的代码:

@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);
    }
}   

当我运行它时,我看到了下面的结果;

1.1.0.发布

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

弹簧壳>

4

1 回答 1

22

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

Unix机器:

-Djline.terminal=org.springframework.shell.core.IdeTerminal

在 Windows 机器上:

-Djline.WindowsTerminal.directConsole=false -Djline.terminal=jline.UnsupportedTerminal
于 2015-05-30T09:32:25.093 回答