mysql 代码生成 2023年2月22日16:32:34
parent
cd790833c1
commit
a1325ee66d
|
|
@ -1,17 +1,33 @@
|
|||
package com.zhangmeng.tools.controller;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.zhangmeng.tools.dto.BeanField;
|
||||
import com.zhangmeng.tools.dto.GenerateDetail;
|
||||
import com.zhangmeng.tools.dto.GenerateInput;
|
||||
import com.zhangmeng.tools.utils.AlertUtils;
|
||||
import com.zhangmeng.tools.utils.TemplateUtil;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.control.cell.TextFieldListCell;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import javafx.util.Callback;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -48,9 +64,231 @@ public class MySQLCodeGenController {
|
|||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private TextField table_name;
|
||||
|
||||
@FXML
|
||||
public void preview_code() {
|
||||
String text = data_base.getText();
|
||||
if (text.length() == 0) {
|
||||
AlertUtils.alert_warning("请输入数据库名!");
|
||||
return;
|
||||
}
|
||||
|
||||
String table = table_name.getText();
|
||||
if (table.length() == 0) {
|
||||
AlertUtils.alert_warning("请输入表名!");
|
||||
return;
|
||||
}
|
||||
GenerateDetail generateDetail = generateByTableName(table);
|
||||
log.info("generateDetail:{}", generateDetail);
|
||||
assignment_to_filed(generateDetail);
|
||||
bean_info.set(generateDetail);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private TextField path_field;
|
||||
|
||||
@FXML
|
||||
private TextField bean_class_name_field;
|
||||
|
||||
@FXML
|
||||
private TextField bean_package_name_field;
|
||||
|
||||
@FXML
|
||||
private TextField dao_clas_name_field;
|
||||
|
||||
@FXML
|
||||
private TextField dao_package_name_field;
|
||||
|
||||
@FXML
|
||||
private TextField controller_class_name_field;
|
||||
|
||||
@FXML
|
||||
private TextField controller_package_name_field;
|
||||
|
||||
@FXML
|
||||
private TableColumn<BeanField,String> column_name;
|
||||
|
||||
@FXML
|
||||
private TableColumn<BeanField,String> column_type;
|
||||
|
||||
@FXML
|
||||
private TableColumn<BeanField,String> bean_field_name;
|
||||
|
||||
@FXML
|
||||
private TableColumn<BeanField,String> bean_field_type;
|
||||
|
||||
@FXML
|
||||
private TableColumn<BeanField,String> bean_field_value;
|
||||
|
||||
@FXML
|
||||
private TableView<BeanField> tableView;
|
||||
|
||||
public ObservableList<BeanField> list = FXCollections.observableArrayList();
|
||||
|
||||
@FXML
|
||||
private TextField username;
|
||||
|
||||
@FXML
|
||||
private TextField password;
|
||||
|
||||
@FXML
|
||||
private TextField data_base;
|
||||
|
||||
@FXML
|
||||
private TextField ip_address;
|
||||
|
||||
@FXML
|
||||
private TextField port;
|
||||
|
||||
@FXML
|
||||
private ComboBox<String> comboBox_table;
|
||||
|
||||
private SimpleObjectProperty<GenerateDetail> bean_info = new SimpleObjectProperty<>();
|
||||
|
||||
private ObservableList<String> table_list = FXCollections.observableArrayList();
|
||||
|
||||
public static final String path = "d:/generate";
|
||||
public static final String bean_package_name = "com.dashidao.server.model";
|
||||
public static final String dao_package_name = "com.dashidao.server.dao";
|
||||
public static final String controller_package_name = "com.dashidao.server.controller";
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
username.setText("root");
|
||||
password.setText("root");
|
||||
ip_address.setText("localhost");
|
||||
port.setText("3306");
|
||||
tableView.setFixedCellSize(30);
|
||||
tableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
||||
tableView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
System.out.println(newValue.getName());
|
||||
}
|
||||
});
|
||||
column_name.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
column_name.setCellValueFactory(new PropertyValueFactory<>("columnName"));
|
||||
|
||||
column_type.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
column_type.setCellValueFactory(new PropertyValueFactory<>("columnType"));
|
||||
|
||||
bean_field_name.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
bean_field_name.setCellValueFactory(new PropertyValueFactory<>("name"));
|
||||
|
||||
bean_field_type.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
bean_field_type.setCellValueFactory(new PropertyValueFactory<>("type"));
|
||||
|
||||
bean_field_value.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
bean_field_value.setCellValueFactory(new PropertyValueFactory<>("columnDefault"));
|
||||
tableView.setItems(list);
|
||||
|
||||
double width = tableView.getPrefWidth() / tableView.getColumns().size() + 100;
|
||||
column_name.setPrefWidth(width);
|
||||
column_type.setPrefWidth(width);
|
||||
bean_field_name.setPrefWidth(width);
|
||||
bean_field_type.setPrefWidth(width);
|
||||
bean_field_value.setPrefWidth(width);
|
||||
|
||||
comboBox_table.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if(newValue != null){
|
||||
log.info("选择的表名为:{}",newValue);
|
||||
table_name.setText(newValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void save_code(){
|
||||
log.info("代码生成保存!");
|
||||
GenerateDetail generateDetail = bean_info.getValue();
|
||||
if (generateDetail == null){
|
||||
AlertUtils.alert_warning("请预览之后在进行操作!");
|
||||
return;
|
||||
}
|
||||
|
||||
GenerateInput generateInput = new GenerateInput();
|
||||
generateInput.setTableName(generateDetail.getTableName());
|
||||
generateInput.setPath(path_field.getText());
|
||||
|
||||
generateInput.setControllerName(controller_class_name_field.getText());
|
||||
generateInput.setDaoName(dao_clas_name_field.getText());
|
||||
generateInput.setBeanName(generateDetail.getBeanName());
|
||||
|
||||
generateInput.setDaoPackageName(dao_package_name_field.getText());
|
||||
generateInput.setControllerPkgName(controller_package_name_field.getText());
|
||||
generateInput.setBeanPackageName(bean_package_name_field.getText());
|
||||
|
||||
List<BeanField> fields = generateDetail.getFields();
|
||||
List<String> beanFieldName = new ArrayList<>();
|
||||
List<String> beanFieldType = new ArrayList<>();
|
||||
List<String> beanFieldValue = new ArrayList<>();
|
||||
List<String> columnNames = new ArrayList<>();
|
||||
for (BeanField field : fields) {
|
||||
beanFieldName.add(field.getName());
|
||||
beanFieldType.add(field.getType());
|
||||
beanFieldValue.add(field.getColumnDefault());
|
||||
columnNames.add(field.getColumnName());
|
||||
}
|
||||
|
||||
generateInput.setBeanFieldName(beanFieldName);
|
||||
generateInput.setBeanFieldType(beanFieldType);
|
||||
generateInput.setBeanFieldValue(beanFieldValue);
|
||||
generateInput.setColumnNames(columnNames);
|
||||
|
||||
TemplateUtil.saveJava(generateInput);
|
||||
TemplateUtil.saveJavaDao(generateInput);
|
||||
TemplateUtil.saveController(generateInput);
|
||||
log.info("生成成功!");
|
||||
//清空
|
||||
bean_info.setValue(null);
|
||||
}
|
||||
|
||||
@FXML
|
||||
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");
|
||||
for (Map<String, Object> map : maps) {
|
||||
String table_name = (String) map.get("table_name");
|
||||
log.info("table_name:{}",table_name);
|
||||
table_list.add(table_name);
|
||||
}
|
||||
comboBox_table.setItems(table_list);
|
||||
comboBox_table.getSelectionModel().select(0);
|
||||
}
|
||||
|
||||
private void assignment_to_filed(GenerateDetail generateDetail) {
|
||||
path_field.setText(path);
|
||||
String bean_class_name = generateDetail.getBeanName();
|
||||
bean_class_name_field.setText(bean_class_name);
|
||||
bean_package_name_field.setText(bean_package_name);
|
||||
String dao_clas_name = bean_class_name + "Dao";
|
||||
dao_clas_name_field.setText(dao_clas_name);
|
||||
dao_package_name_field.setText(dao_package_name);
|
||||
String controller_class_name = bean_class_name + "Controller";
|
||||
controller_class_name_field.setText(controller_class_name);
|
||||
controller_package_name_field.setText(controller_package_name);
|
||||
|
||||
list.clear();
|
||||
List<BeanField> fields = generateDetail.getFields();
|
||||
list.addAll(fields);
|
||||
}
|
||||
|
||||
public JdbcTemplate getJdbcTemplate() {
|
||||
if (jdbcTemplate == null) {
|
||||
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 driverClassName = "com.mysql.cj.jdbc.Driver";
|
||||
datasource.setUrl(url);
|
||||
datasource.setUsername(username.getText());
|
||||
datasource.setPassword(password.getText());
|
||||
datasource.setDriverClassName(driverClassName);
|
||||
|
||||
jdbcTemplate.setDataSource(datasource);
|
||||
}
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
|
@ -69,16 +307,15 @@ public class MySQLCodeGenController {
|
|||
detail.setBeanName(upperFirstChar(tableName));
|
||||
List<BeanField> fields = listBeanField(tableName);
|
||||
detail.setFields(fields);
|
||||
|
||||
detail.setTableName(tableName);
|
||||
return detail;
|
||||
}
|
||||
|
||||
public List<BeanField> listBeanField(String tableName) {
|
||||
getJdbcTemplate();
|
||||
List<BeanField> beanFields = jdbcTemplate.query(
|
||||
"select column_name, data_type, column_comment, column_default FROM information_schema.columns WHERE table_name= ? and table_schema = (select database())",
|
||||
new String[]{tableName}, beanFieldMapper);
|
||||
List<BeanField> beanFields = jdbcTemplate.query("select column_name, data_type, column_comment, column_default FROM information_schema.columns WHERE table_name= ? and table_schema = (select database())", new String[]{tableName}, beanFieldMapper);
|
||||
if (CollectionUtils.isEmpty(beanFields)) {
|
||||
AlertUtils.alert_warning("表" + tableName + "不存在");
|
||||
throw new IllegalArgumentException("表" + tableName + "不存在");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ public class GenerateDetail implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = -164567294469931676L;
|
||||
|
||||
private String tableName;
|
||||
|
||||
private String beanName;
|
||||
|
||||
private List<BeanField> fields;
|
||||
|
|
@ -26,4 +28,21 @@ public class GenerateDetail implements Serializable {
|
|||
public void setFields(List<BeanField> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GenerateDetail{" +
|
||||
"tableName='" + tableName + '\'' +
|
||||
", beanName='" + beanName + '\'' +
|
||||
", fields=" + fields +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
|
|
@ -123,7 +124,7 @@ public class FileUtil {
|
|||
InputStreamReader isr = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
isr = new InputStreamReader(inputStream, "utf-8");
|
||||
isr = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
bufferedReader = new BufferedReader(isr);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String string;
|
||||
|
|
@ -155,136 +156,6 @@ public class FileUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 转存文件并且获取时长
|
||||
*
|
||||
* @param file
|
||||
* @param pathname
|
||||
* @return
|
||||
*/
|
||||
public static Map saveFileAndgetDuration(MultipartFile file, String pathname, String type,String path_name) {
|
||||
|
||||
Map map = new HashMap();
|
||||
try {
|
||||
File targetFile = new File(pathname);
|
||||
if (targetFile.exists()) {
|
||||
map.put("pathname", pathname);
|
||||
return map;
|
||||
}
|
||||
|
||||
if (!targetFile.getParentFile().exists()) {
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
map.put("pathname", pathname);
|
||||
if (type != null && type.equals("1")) {
|
||||
//获取图片的宽高
|
||||
BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
|
||||
if (bufferedImage != null) {
|
||||
int width = bufferedImage.getWidth();
|
||||
int height = bufferedImage.getHeight();
|
||||
map.put("imageWidth", width);
|
||||
map.put("imageHeight", height);
|
||||
}
|
||||
}
|
||||
//file.transferTo(targetFile);
|
||||
FileServiceFactory.imagesUpload(pathname,path_name,file.getBytes());
|
||||
//如果是视频或者音频则进行获取时长
|
||||
if (type.equals("2") || type.equals("3")) {
|
||||
Encoder encoder = new Encoder();
|
||||
MultimediaInfo m = encoder.getInfo(targetFile);
|
||||
long ms = m.getDuration();
|
||||
|
||||
int ss = 1000;
|
||||
int mi = ss * 60;
|
||||
int hh = mi * 60;
|
||||
int dd = hh * 24;
|
||||
|
||||
long day = ms / dd;
|
||||
long hour = (ms - day * dd) / hh;
|
||||
long minute = (ms - day * dd - hour * hh) / mi;
|
||||
long second = (ms - day * dd - hour * hh - minute * mi) / ss;
|
||||
|
||||
String strHour = hour < 10 ? "0" + hour : "" + hour;//小时
|
||||
String strMinute = minute < 10 ? "0" + minute : "" + minute;//分钟
|
||||
String strSecond = second < 10 ? "0" + second : "" + second;//秒
|
||||
|
||||
if (type.equals("3")){
|
||||
VedioUtils.getTempPath(pathname,targetFile,map);
|
||||
}
|
||||
|
||||
if (strHour.equals("00")) {
|
||||
map.put("duration", strMinute + ":" + strSecond);
|
||||
return map;
|
||||
} else {
|
||||
map.put("duration", strHour + ":" + strMinute + ":" + strSecond);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return map;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
map.put("msg", "保存错误");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图像
|
||||
* @param file
|
||||
* @param type
|
||||
* @param accessory_path
|
||||
* @param filesPath
|
||||
* @return
|
||||
*/
|
||||
public static Map uploadphoto(MultipartFile file ,String type, String accessory_path, String filesPath) {
|
||||
Map map = new HashMap();
|
||||
String pathname=null;
|
||||
if (type.equals("6")) {//头像
|
||||
accessory_path = "upload/portrait";
|
||||
map.put("accessory_path",accessory_path);
|
||||
}else if (type.equals("7")){
|
||||
accessory_path = "upload/platform";
|
||||
map.put("accessory_path",accessory_path);
|
||||
}
|
||||
String fileOrigName = file.getOriginalFilename();
|
||||
//fileOrigName = fileOrigName.substring(fileOrigName.lastIndexOf("."));
|
||||
SimpleDateFormat dateformat1 = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String path = dateformat1.format(new Date()) + "-" + fileOrigName;
|
||||
map.put("path",path);
|
||||
pathname = filesPath + "/"+ accessory_path + "/"+path;
|
||||
try {
|
||||
File targetFile = new File(pathname);
|
||||
if (targetFile.exists()) {
|
||||
map.put("pathname", pathname);
|
||||
return map;
|
||||
}
|
||||
if (!targetFile.getParentFile().exists()) {
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
if (type != null && type.equals("6")||type.equals("7")) {
|
||||
//获取图片的宽高
|
||||
BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
|
||||
if (bufferedImage != null) {
|
||||
int width = bufferedImage.getWidth();
|
||||
int height = bufferedImage.getHeight();
|
||||
map.put("imageWidth", width);
|
||||
map.put("imageHeight", height);
|
||||
}
|
||||
}
|
||||
//file.transferTo(targetFile);
|
||||
FileServiceFactory.imagesUpload(pathname,accessory_path + "/"+path,file.getBytes());
|
||||
return map;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断文件大小
|
||||
* @param len 文件长度
|
||||
|
|
|
|||
|
|
@ -1,14 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="com.zhangmeng.tools.controller.MySQLCodeGenController"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<AnchorPane prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.MySQLCodeGenController">
|
||||
<children>
|
||||
<TableView fx:id="tableView" layoutX="98.0" layoutY="368.0" prefHeight="281.0" prefWidth="1200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="368.0">
|
||||
<columns>
|
||||
<TableColumn fx:id="column_name" prefWidth="200.0" text="表字段名" />
|
||||
<TableColumn fx:id="column_type" prefWidth="200.0" text="表类型" />
|
||||
<TableColumn prefWidth="202.0" text="字段描述" />
|
||||
<TableColumn fx:id="bean_field_name" prefWidth="198.0" text="java字段名" />
|
||||
<TableColumn fx:id="bean_field_type" prefWidth="200.0" text="java字段类型" />
|
||||
<TableColumn fx:id="bean_field_value" prefWidth="200.0" text="默认值" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<Label layoutX="10.0" layoutY="333.0" text="字段详情" AnchorPane.leftAnchor="10.0" />
|
||||
<Label layoutX="10.0" layoutY="194.0" text="基本配置" AnchorPane.leftAnchor="10.0" />
|
||||
<Label layoutX="84.0" layoutY="230.0" text="路径" />
|
||||
<TextField fx:id="path_field" layoutX="164.0" layoutY="226.0" prefHeight="25.0" prefWidth="197.0" />
|
||||
<TextField fx:id="bean_class_name_field" layoutX="164.0" layoutY="296.0" prefHeight="25.0" prefWidth="197.0" />
|
||||
<TextField fx:id="bean_package_name_field" layoutX="164.0" layoutY="262.0" prefHeight="25.0" prefWidth="197.0" />
|
||||
<TextField fx:id="dao_package_name_field" layoutX="520.0" layoutY="262.0" prefHeight="25.0" prefWidth="197.0" />
|
||||
<TextField fx:id="dao_clas_name_field" layoutX="520.0" layoutY="296.0" prefHeight="25.0" prefWidth="197.0" />
|
||||
<TextField fx:id="controller_package_name_field" layoutX="903.0" layoutY="262.0" prefHeight="25.0" prefWidth="197.0" />
|
||||
<TextField fx:id="controller_class_name_field" layoutX="903.0" layoutY="296.0" prefHeight="25.0" prefWidth="197.0" />
|
||||
<Label layoutX="84.0" layoutY="266.0" text="bean包名" />
|
||||
<Label layoutX="84.0" layoutY="300.0" text="bean类名" />
|
||||
<Label layoutX="429.0" layoutY="266.0" text="dao包名" />
|
||||
<Label layoutX="429.0" layoutY="300.0" text="dao类名" />
|
||||
<Label layoutX="786.0" layoutY="266.0" text="controller包名" />
|
||||
<Label layoutX="786.0" layoutY="300.0" text="controller类名" />
|
||||
<Label layoutX="438.0" layoutY="186.0" text="表名" />
|
||||
<TextField fx:id="table_name" layoutX="488.0" layoutY="182.0" />
|
||||
<Button layoutX="666.0" layoutY="182.0" mnemonicParsing="false" onAction="#preview_code" text="预览代码" />
|
||||
<Button layoutX="754.0" layoutY="182.0" mnemonicParsing="false" onAction="#save_code" text="保存代码" />
|
||||
<Label layoutX="10.0" layoutY="48.0" text="数据源配置" />
|
||||
<TextField fx:id="username" layoutX="164.0" layoutY="85.0" />
|
||||
<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="数据名" />
|
||||
<TextField fx:id="ip_address" layoutX="164.0" layoutY="119.0" />
|
||||
<TextField fx:id="data_base" layoutX="698.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"/>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
package {controllerPkgName};
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dashidao.server.page.table.PageTableRequest;
|
||||
import com.dashidao.server.page.table.PageTableHandler;
|
||||
import com.dashidao.server.page.table.PageTableResponse;
|
||||
import com.dashidao.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.dashidao.server.page.table.PageTableHandler.ListHandler;
|
||||
import {daoPackageName}.{daoName};
|
||||
import {beanPackageName}.{beanName};
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/{beanParamName}s")
|
||||
public class {controllerName} {
|
||||
|
||||
@Autowired
|
||||
private {daoName} {daoParamName};
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation(value = "保存")
|
||||
public {beanName} save(@RequestBody {beanName} {beanParamName}) {
|
||||
{daoParamName}.save({beanParamName});
|
||||
|
||||
return {beanParamName};
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation(value = "根据id获取")
|
||||
public {beanName} get(@PathVariable Long id) {
|
||||
return {daoParamName}.getById(id);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@ApiOperation(value = "修改")
|
||||
public {beanName} update(@RequestBody {beanName} {beanParamName}) {
|
||||
{daoParamName}.update({beanParamName});
|
||||
|
||||
return {beanParamName};
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "列表")
|
||||
public PageTableResponse list(PageTableRequest request) {
|
||||
return new PageTableHandler(new CountHandler() {
|
||||
|
||||
@Override
|
||||
public int count(PageTableRequest request) {
|
||||
return {daoParamName}.count(request.getParams());
|
||||
}
|
||||
}, new ListHandler() {
|
||||
|
||||
@Override
|
||||
public List<{beanName}> list(PageTableRequest request) {
|
||||
return {daoParamName}.list(request.getParams(), request.getOffset(), request.getLimit());
|
||||
}
|
||||
}).handle(request);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@ApiOperation(value = "删除")
|
||||
public void delete(@PathVariable Long id) {
|
||||
{daoParamName}.delete(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package {daoPackageName};
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import {beanPackageName}.{beanName};
|
||||
|
||||
@Mapper
|
||||
public interface {daoName} {
|
||||
|
||||
@Select("select * from {table_name} t where t.id = #{id}")
|
||||
{beanName} getById(Long id);
|
||||
|
||||
@Delete("delete from {table_name} where id = #{id}")
|
||||
int delete(Long id);
|
||||
|
||||
int update({beanName} {beanParamName});
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
@Insert("insert into {table_name}({insert_columns}) values({insert_values})")
|
||||
int save({beanName} {beanParamName});
|
||||
|
||||
int count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<{beanName}> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package {beanPackageName};
|
||||
|
||||
{import}
|
||||
|
||||
public class {beanName} extends BaseEntity<Long> {
|
||||
|
||||
{filelds}
|
||||
{getset}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="{daoPackageName}.{daoName}">
|
||||
|
||||
<sql id="where">
|
||||
<where>
|
||||
{where}
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="count" resultType="int">
|
||||
select count(1) from {table_name} t
|
||||
<include refid="where" />
|
||||
</select>
|
||||
|
||||
<select id="list" resultType="{beanName}">
|
||||
select * from {table_name} t
|
||||
<include refid="where" />
|
||||
${params.orderBy}
|
||||
limit #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<update id="update">
|
||||
update {table_name} t
|
||||
<set>
|
||||
{update_sets}
|
||||
</set>
|
||||
|
||||
where t.id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue