我正在 IntelliJ 中编写 CLI Spring shell 代码。
我运行它并给出一些参数。但是当我输入 insert 并按 Enter 时,控制台不接受它,看起来好像什么也没发生!
My code:
@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 键。
弹簧壳>
Spring Shell 使用 Jline。您必须在 Intellij 中编辑运行配置并添加 vm 选项参数,如下所示:
Unix 机器:
-Djline.terminal=org.springframework.shell.core.IdeTerminal
在 Windows 机器上:
-Djline.WindowsTerminal.directConsole=false -Djline.terminal=jline.UnsupportedTerminal
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)