mysql 代码生成 2023年2月22日18:10:35

master
zhangmeng 2023-02-22 18:10:42 +08:00
parent a1325ee66d
commit 55200ea20f
2 changed files with 56 additions and 20 deletions

View File

@ -145,9 +145,13 @@ public class MySQLCodeGenController {
@FXML
private ComboBox<String> comboBox_table;
@FXML
private ComboBox<String> comboBox_data_base;
private SimpleObjectProperty<GenerateDetail> bean_info = new SimpleObjectProperty<>();
private ObservableList<String> table_list = FXCollections.observableArrayList();
private ObservableList<String> data_base_list = FXCollections.observableArrayList();
public static final String path = "d:/generate";
public static final String bean_package_name = "com.dashidao.server.model";
@ -196,6 +200,36 @@ public class MySQLCodeGenController {
table_name.setText(newValue);
}
});
comboBox_data_base.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
log.info("选择的数据库名为:{}", newValue);
data_base.setText(newValue);
update_select_data_base();
}
});
}
private void update_select_data_base() {
String text = data_base.getText();
getJdbcTemplate();
log.info("update_select_data_base:{}", text);
this.jdbcTemplate.execute("use `" + text + "`");
}
@FXML
public void get_all_data_base() {
log.info("获取所有数据表.....");
data_base_list.clear();
getJdbcTemplate();
List<Map<String, Object>> maps = this.jdbcTemplate.queryForList("show databases");
for (Map<String, Object> map : maps) {
log.info("map->{}", map.toString());
data_base_list.add(map.get("Database").toString());
}
comboBox_data_base.setItems(data_base_list);
comboBox_data_base.getSelectionModel().select(0);
data_base.setText(comboBox_data_base.getSelectionModel().getSelectedItem());
}
@FXML
@ -248,8 +282,7 @@ public class MySQLCodeGenController {
public void fetch_table() {
table_list.clear();
getJdbcTemplate();
List<Map<String, Object>> maps = this.jdbcTemplate.queryForList
("SELECT table_name, table_type, TABLE_COMMENT FROM information_schema.tables WHERE table_schema = (select database()) ORDER BY table_name DESC");
List<Map<String, Object>> maps = this.jdbcTemplate.queryForList("SELECT table_name, table_type, TABLE_COMMENT FROM information_schema.tables WHERE table_schema = (select database()) ORDER BY table_name DESC");
for (Map<String, Object> map : maps) {
String table_name = (String) map.get("table_name");
log.info("table_name:{}", table_name);

View File

@ -45,14 +45,17 @@
<Label layoutX="93.0" layoutY="89.0" text="用户名" />
<Label layoutX="370.0" layoutY="89.0" text="密码" />
<TextField fx:id="password" layoutX="416.0" layoutY="85.0" />
<Label layoutX="645.0" layoutY="89.0" text="数据名" />
<Label layoutX="866.0" layoutY="89.0" text="数据名" />
<TextField fx:id="ip_address" layoutX="164.0" layoutY="119.0" />
<TextField fx:id="data_base" layoutX="698.0" layoutY="85.0" />
<TextField fx:id="data_base" layoutX="921.0" layoutY="85.0" />
<Label layoutX="94.0" layoutY="123.0" text="IP地址" />
<Label layoutX="370.0" layoutY="123.0" text="端口" />
<TextField fx:id="port" layoutX="416.0" layoutY="119.0" />
<ComboBox layoutX="698.0" layoutY="119.0" prefHeight="25.0" prefWidth="161.0" fx:id="comboBox_table"/>
<Label layoutX="645.0" layoutY="123.0" text="列表" />
<Button layoutX="887.0" layoutY="119.0" mnemonicParsing="false" text="获取" onAction="#fetch_table"/>
<ComboBox fx:id="comboBox_table" layoutX="921.0" layoutY="119.0" prefHeight="25.0" prefWidth="161.0" />
<Label layoutX="866.0" layoutY="123.0" text="列表" />
<Button layoutX="1100.0" layoutY="119.0" mnemonicParsing="false" onAction="#fetch_table" text="获取" />
<Label layoutX="603.0" layoutY="89.0" text="数据库列表" />
<ComboBox layoutX="679.0" layoutY="85.0" prefWidth="150.0" fx:id="comboBox_data_base"/>
<Button layoutX="652.0" layoutY="119.0" mnemonicParsing="false" text="获取数据库列表" onAction="#get_all_data_base" />
</children>
</AnchorPane>