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

@ -108,19 +108,19 @@ public class MySQLCodeGenController {
private TextField controller_package_name_field;
@FXML
private TableColumn<BeanField,String> column_name;
private TableColumn<BeanField, String> column_name;
@FXML
private TableColumn<BeanField,String> column_type;
private TableColumn<BeanField, String> column_type;
@FXML
private TableColumn<BeanField,String> bean_field_name;
private TableColumn<BeanField, String> bean_field_name;
@FXML
private TableColumn<BeanField,String> bean_field_type;
private TableColumn<BeanField, String> bean_field_type;
@FXML
private TableColumn<BeanField,String> bean_field_value;
private TableColumn<BeanField, String> bean_field_value;
@FXML
private TableView<BeanField> tableView;
@ -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";
@ -191,18 +195,48 @@ public class MySQLCodeGenController {
bean_field_value.setPrefWidth(width);
comboBox_table.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if(newValue != null){
log.info("选择的表名为:{}",newValue);
if (newValue != null) {
log.info("选择的表名为:{}", newValue);
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 save_code(){
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
public void save_code() {
log.info("代码生成保存!");
GenerateDetail generateDetail = bean_info.getValue();
if (generateDetail == null){
if (generateDetail == null) {
AlertUtils.alert_warning("请预览之后在进行操作!");
return;
}
@ -245,14 +279,13 @@ public class MySQLCodeGenController {
}
@FXML
public void fetch_table(){
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);
log.info("table_name:{}", table_name);
table_list.add(table_name);
}
comboBox_table.setItems(table_list);
@ -281,7 +314,7 @@ public class MySQLCodeGenController {
jdbcTemplate = new JdbcTemplate();
DruidDataSource datasource = new DruidDataSource();
String url = "jdbc:mysql://"+ ip_address.getText() +": " + port.getText() + "/" + data_base.getText() + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true";
String url = "jdbc:mysql://" + ip_address.getText() + ": " + port.getText() + "/" + data_base.getText() + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true";
String driverClassName = "com.mysql.cj.jdbc.Driver";
datasource.setUrl(url);
datasource.setUsername(username.getText());

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>