我正在开发 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。
弹簧壳>