2023年2月21日17:52:03 根据表名获取表
parent
fa7b666333
commit
cd790833c1
|
|
@ -129,6 +129,27 @@ public class HomeController implements Serializable {
|
|||
load_codec_tools(3);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void sql_code_gen_menu_item(){
|
||||
load_sql_tools(0);
|
||||
}
|
||||
|
||||
public void load_sql_tools(int index){
|
||||
AnchorPane fx = null;
|
||||
try {
|
||||
fx = FXMLLoader.load(ResourcesUtils.getResource("sql-tools"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Scene scene = new Scene(fx);
|
||||
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||
stage.setScene(scene);
|
||||
|
||||
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||
listView.getSelectionModel().select(index);
|
||||
}
|
||||
|
||||
public void load_codec_tools(int index){
|
||||
AnchorPane fx = null;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,108 @@
|
|||
package com.zhangmeng.tools.controller;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.zhangmeng.tools.dto.BeanField;
|
||||
import com.zhangmeng.tools.dto.GenerateDetail;
|
||||
import com.zhangmeng.tools.utils.TemplateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-02-21 16:34
|
||||
*/
|
||||
@Slf4j
|
||||
public class MySQLCodeGenController {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
/**
|
||||
* mysql类型与java类型部分对应关系
|
||||
*/
|
||||
private static Map<String, String> map = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
map.put("int", Integer.class.getSimpleName());
|
||||
map.put("tinyint", Integer.class.getSimpleName());
|
||||
map.put("double", Double.class.getSimpleName());
|
||||
map.put("float", Float.class.getSimpleName());
|
||||
map.put("decimal", BigDecimal.class.getSimpleName());
|
||||
map.put("date", Date.class.getSimpleName());
|
||||
map.put("timestamp", Date.class.getSimpleName());
|
||||
map.put("datetime", Date.class.getSimpleName());
|
||||
map.put("varchar", String.class.getSimpleName());
|
||||
map.put("text", String.class.getSimpleName());
|
||||
map.put("longtext", String.class.getSimpleName());
|
||||
map.put("bit", Boolean.class.getSimpleName());
|
||||
map.put("bigint", Long.class.getSimpleName());
|
||||
|
||||
}
|
||||
|
||||
public JdbcTemplate getJdbcTemplate() {
|
||||
if (jdbcTemplate == null) {
|
||||
jdbcTemplate = new JdbcTemplate();
|
||||
}
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
||||
private RowMapper<BeanField> beanFieldMapper = (rs, paramInt) -> {
|
||||
BeanField beanField = new BeanField();
|
||||
beanField.setColumnName(rs.getString("column_name"));
|
||||
beanField.setColumnType(rs.getString("data_type"));
|
||||
beanField.setColumnComment(rs.getString("column_comment"));
|
||||
beanField.setColumnDefault(rs.getString("column_default"));
|
||||
return beanField;
|
||||
};
|
||||
|
||||
public GenerateDetail generateByTableName(String tableName) {
|
||||
GenerateDetail detail = new GenerateDetail();
|
||||
detail.setBeanName(upperFirstChar(tableName));
|
||||
List<BeanField> fields = listBeanField(tableName);
|
||||
detail.setFields(fields);
|
||||
|
||||
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);
|
||||
if (CollectionUtils.isEmpty(beanFields)) {
|
||||
throw new IllegalArgumentException("表" + tableName + "不存在");
|
||||
}
|
||||
|
||||
beanFields.parallelStream().forEach(b -> {
|
||||
b.setName(TemplateUtil.str2hump(b.getColumnName()));
|
||||
String type = map.get(b.getColumnType());
|
||||
if (type == null) {
|
||||
type = String.class.getSimpleName();
|
||||
}
|
||||
b.setType(type);
|
||||
if ("id".equals(b.getName())) {
|
||||
b.setType(Long.class.getSimpleName());
|
||||
}
|
||||
|
||||
b.setColumnDefault(b.getColumnDefault() == null ? "" : b.getColumnDefault());
|
||||
});
|
||||
|
||||
return beanFields;
|
||||
}
|
||||
|
||||
public String upperFirstChar(String string) {
|
||||
String name = TemplateUtil.str2hump(string);
|
||||
String firstChar = name.substring(0, 1);
|
||||
name = name.replaceFirst(firstChar, firstChar.toUpperCase());
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,299 @@
|
|||
package com.zhangmeng.tools.controller;
|
||||
|
||||
import com.zhangmeng.tools.utils.ImagePath;
|
||||
import com.zhangmeng.tools.utils.ResourcesUtils;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Callback;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-02-21 16:23
|
||||
*/
|
||||
@Slf4j
|
||||
public class SqlToolsController {
|
||||
|
||||
private SimpleDoubleProperty width = new SimpleDoubleProperty(0.0);
|
||||
private SimpleDoubleProperty height = new SimpleDoubleProperty(0.0);
|
||||
private AnchorPane root;
|
||||
private AnchorPane mysql_code_gen;
|
||||
private AnchorPane spring_security;
|
||||
|
||||
public static final String color_cell = "#f4f4f4";
|
||||
|
||||
@FXML
|
||||
private ListView<ResourcesUtils.SqlTools> listView;
|
||||
|
||||
@FXML
|
||||
private SplitPane splitPane;
|
||||
|
||||
@FXML
|
||||
public void md5_menu_item() {
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void spring_security_menu_item() {
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void video_menu_item() {
|
||||
load_player(0);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void music_menu_item() {
|
||||
load_player(1);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void vip_parser_menu_item() {
|
||||
load_player(2);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void hex_16(){
|
||||
load_small_tools(0);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void hex_16_menu_item(){
|
||||
load_small_tools(0);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void unicode_menu_item(){
|
||||
load_small_tools(1);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void jwt_menu_item(){
|
||||
load_small_tools(2);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void color_choose_menu_item(){
|
||||
load_small_tools(3);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void base_62_menu_item(){
|
||||
load_codec_tools(0);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void base_64_menu_item(){
|
||||
load_codec_tools(1);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void base_32_menu_item(){
|
||||
load_codec_tools(2);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void morse_coder_menu_item(){
|
||||
load_codec_tools(3);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void sql_code_gen_menu_item(){
|
||||
boolean flag = false;
|
||||
if (mysql_code_gen != null){
|
||||
flag = true;
|
||||
}
|
||||
mysql_code_gen(flag);
|
||||
}
|
||||
|
||||
public void load_codec_tools(int index){
|
||||
AnchorPane fx = null;
|
||||
try {
|
||||
fx = FXMLLoader.load(ResourcesUtils.getResource("codec-tools"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Scene scene = new Scene(fx);
|
||||
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||
stage.setScene(scene);
|
||||
|
||||
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||
listView.getSelectionModel().select(index);
|
||||
}
|
||||
|
||||
public void load_small_tools(int index){
|
||||
AnchorPane fx = null;
|
||||
try {
|
||||
fx = FXMLLoader.load(ResourcesUtils.getResource("small-tools"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Scene scene = new Scene(fx);
|
||||
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||
stage.setScene(scene);
|
||||
|
||||
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||
listView.getSelectionModel().select(index);
|
||||
}
|
||||
|
||||
public void load_player(int index) {
|
||||
AnchorPane fx = null;
|
||||
try {
|
||||
fx = FXMLLoader.load(ResourcesUtils.getResource("player"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Scene scene = new Scene(fx);
|
||||
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||
stage.setScene(scene);
|
||||
|
||||
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||
listView.getSelectionModel().select(index);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
init();
|
||||
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
boolean flag = false;
|
||||
|
||||
if (newValue.getIndex() == 0) {
|
||||
if (mysql_code_gen != null){
|
||||
flag = true;
|
||||
}
|
||||
mysql_code_gen(flag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Image getImage(ResourcesUtils.SqlTools player){
|
||||
return switch (player){
|
||||
case MySql_Code_Generate -> new Image(ImagePath.path(ImagePath.ImagePathType.MD5));
|
||||
};
|
||||
}
|
||||
|
||||
public void init() {
|
||||
ResourcesUtils.SqlTools[] values = ResourcesUtils.SqlTools.values();
|
||||
ObservableList<ResourcesUtils.SqlTools> list = FXCollections.observableArrayList();
|
||||
list.addAll(Arrays.asList(values));
|
||||
listView.setItems(list);
|
||||
listView.setFixedCellSize(40);
|
||||
listView.setCellFactory(new Callback<>() {
|
||||
private int position;
|
||||
@Override
|
||||
public ListCell<ResourcesUtils.SqlTools> call(ListView<ResourcesUtils.SqlTools> playerListView) {
|
||||
Label label = new Label();
|
||||
label.setPrefWidth(200);
|
||||
ListCell<ResourcesUtils.SqlTools> listCell = new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(ResourcesUtils.SqlTools player, boolean b) {
|
||||
super.updateItem(player, b);
|
||||
if (!b) {
|
||||
HBox hBox = new HBox(25);
|
||||
hBox.setAlignment(Pos.CENTER);
|
||||
label.setText(player.getTitle());
|
||||
label.setTextFill(Paint.valueOf("#000000"));
|
||||
Image im = getImage(player);
|
||||
ImageView iv = new ImageView(im);
|
||||
iv.setPreserveRatio(true);
|
||||
iv.setFitWidth(15);
|
||||
hBox.getChildren().add(iv);
|
||||
|
||||
hBox.getChildren().add(label);
|
||||
this.setGraphic(hBox);
|
||||
}
|
||||
this.setStyle("-fx-background-color: " + color_cell);
|
||||
}
|
||||
};
|
||||
|
||||
listCell.hoverProperty().addListener((observableValue, aBoolean, t1) -> {
|
||||
if (t1 && !label.getText().equals("")) {
|
||||
position = playerListView.getItems().indexOf(label.getText());
|
||||
label.setFont(new Font(16));
|
||||
playerListView.getFocusModel().focus(position);
|
||||
listCell.setStyle("-fx-background-color: #369e7d");
|
||||
} else {
|
||||
label.setPrefHeight(20);
|
||||
label.setFont(new Font(13));
|
||||
listCell.setStyle("-fx-background-color: " + color_cell);
|
||||
}
|
||||
});
|
||||
|
||||
return listCell;
|
||||
}
|
||||
});
|
||||
|
||||
mysql_code_gen(false);
|
||||
}
|
||||
|
||||
private void mysql_code_gen(boolean flag) {
|
||||
//默认选择第一个
|
||||
listView.getSelectionModel().select(0);
|
||||
|
||||
if (!flag){
|
||||
try {
|
||||
root = FXMLLoader.load(ResourcesUtils.getResource("mysql-code-gen"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mysql_code_gen = root;
|
||||
}else {
|
||||
root = mysql_code_gen;
|
||||
}
|
||||
common_method();
|
||||
}
|
||||
|
||||
private void common_method() {
|
||||
splitPane.getItems().remove(1);
|
||||
splitPane.getItems().add(1, root);
|
||||
root.widthProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
double width = splitPane.getWidth();
|
||||
SqlToolsController.this.width.set(width);
|
||||
log.info("home:--->width:{}", width);
|
||||
}
|
||||
});
|
||||
root.heightProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
double height = splitPane.getHeight();
|
||||
SqlToolsController.this.height.set(height);
|
||||
log.info("home:--->height:{}", height);
|
||||
}
|
||||
});
|
||||
|
||||
this.width.addListener((observable, oldValue, newValue) -> {
|
||||
SqlToolsController.this.root.setPrefWidth(newValue.doubleValue() - listView.getWidth());
|
||||
});
|
||||
|
||||
this.height.addListener((observable, oldValue, newValue) -> {
|
||||
SqlToolsController.this.root.setPrefHeight(newValue.doubleValue() - listView.getHeight());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.zhangmeng.tools.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BeanField implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4279960350136806659L;
|
||||
|
||||
private String columnName;
|
||||
|
||||
private String columnType;
|
||||
|
||||
private String columnComment;
|
||||
|
||||
private String columnDefault;
|
||||
|
||||
private String name;
|
||||
|
||||
private String type;
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
public String getColumnType() {
|
||||
return columnType;
|
||||
}
|
||||
|
||||
public void setColumnType(String columnType) {
|
||||
this.columnType = columnType;
|
||||
}
|
||||
|
||||
public String getColumnComment() {
|
||||
return columnComment;
|
||||
}
|
||||
|
||||
public void setColumnComment(String columnComment) {
|
||||
this.columnComment = columnComment;
|
||||
}
|
||||
|
||||
public String getColumnDefault() {
|
||||
return columnDefault;
|
||||
}
|
||||
|
||||
public void setColumnDefault(String columnDefault) {
|
||||
this.columnDefault = columnDefault;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.zhangmeng.tools.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class GenerateDetail implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -164567294469931676L;
|
||||
|
||||
private String beanName;
|
||||
|
||||
private List<BeanField> fields;
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
public List<BeanField> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(List<BeanField> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
package com.zhangmeng.tools.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class GenerateInput implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2870071259702969061L;
|
||||
|
||||
/**
|
||||
* 保存路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* bean包名
|
||||
*/
|
||||
private String beanPackageName;
|
||||
|
||||
/**
|
||||
* java类名
|
||||
*/
|
||||
private String beanName;
|
||||
/**
|
||||
* dao包名
|
||||
*/
|
||||
private String daoPackageName;
|
||||
|
||||
/**
|
||||
* dao类名
|
||||
*/
|
||||
private String daoName;
|
||||
/**
|
||||
* controller包名
|
||||
*/
|
||||
private String controllerPkgName;
|
||||
/**
|
||||
* controller类名
|
||||
*/
|
||||
private String controllerName;
|
||||
/**
|
||||
* 字段名
|
||||
*/
|
||||
private List<String> columnNames;
|
||||
/**
|
||||
* 属性名
|
||||
*/
|
||||
private List<String> beanFieldName;
|
||||
/**
|
||||
* 成员变量类型
|
||||
*/
|
||||
private List<String> beanFieldType;
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
private List<String> beanFieldValue;
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getBeanPackageName() {
|
||||
return beanPackageName;
|
||||
}
|
||||
|
||||
public void setBeanPackageName(String beanPackageName) {
|
||||
this.beanPackageName = beanPackageName;
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
public String getDaoPackageName() {
|
||||
return daoPackageName;
|
||||
}
|
||||
|
||||
public void setDaoPackageName(String daoPackageName) {
|
||||
this.daoPackageName = daoPackageName;
|
||||
}
|
||||
|
||||
public String getDaoName() {
|
||||
return daoName;
|
||||
}
|
||||
|
||||
public void setDaoName(String daoName) {
|
||||
this.daoName = daoName;
|
||||
}
|
||||
|
||||
public String getControllerPkgName() {
|
||||
return controllerPkgName;
|
||||
}
|
||||
|
||||
public void setControllerPkgName(String controllerPkgName) {
|
||||
this.controllerPkgName = controllerPkgName;
|
||||
}
|
||||
|
||||
public String getControllerName() {
|
||||
return controllerName;
|
||||
}
|
||||
|
||||
public void setControllerName(String controllerName) {
|
||||
this.controllerName = controllerName;
|
||||
}
|
||||
|
||||
public List<String> getColumnNames() {
|
||||
return columnNames;
|
||||
}
|
||||
|
||||
public void setColumnNames(List<String> columnNames) {
|
||||
this.columnNames = columnNames;
|
||||
}
|
||||
|
||||
public List<String> getBeanFieldName() {
|
||||
return beanFieldName;
|
||||
}
|
||||
|
||||
public void setBeanFieldName(List<String> beanFieldName) {
|
||||
this.beanFieldName = beanFieldName;
|
||||
}
|
||||
|
||||
public List<String> getBeanFieldType() {
|
||||
return beanFieldType;
|
||||
}
|
||||
|
||||
public void setBeanFieldType(List<String> beanFieldType) {
|
||||
this.beanFieldType = beanFieldType;
|
||||
}
|
||||
|
||||
public List<String> getBeanFieldValue() {
|
||||
return beanFieldValue;
|
||||
}
|
||||
|
||||
public void setBeanFieldValue(List<String> beanFieldValue) {
|
||||
this.beanFieldValue = beanFieldValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,311 @@
|
|||
package com.zhangmeng.tools.utils;
|
||||
|
||||
import it.sauronsoftware.jave.Encoder;
|
||||
import it.sauronsoftware.jave.MultimediaInfo;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件工具类
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
public static String saveFile(MultipartFile file, String pathname) {
|
||||
try {
|
||||
File targetFile = new File(pathname);
|
||||
if (targetFile.exists()) {
|
||||
return pathname;
|
||||
}
|
||||
|
||||
if (!targetFile.getParentFile().exists()) {
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
file.transferTo(targetFile);
|
||||
return pathname;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean deleteFile(String pathname) {
|
||||
File file = new File(pathname);
|
||||
if (file.exists()) {
|
||||
boolean flag = file.delete();
|
||||
|
||||
if (flag) {
|
||||
File[] files = file.getParentFile().listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
file.getParentFile().delete();
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String fileMd5(InputStream inputStream) {
|
||||
try {
|
||||
return DigestUtils.md5Hex(inputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPath() {
|
||||
return "/" + LocalDate.now().toString().replace("-", "/") + "/";
|
||||
}
|
||||
|
||||
public static String getPath_2() {
|
||||
return LocalDate.now().toString().replace("-", "/") + "/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文本写入文件
|
||||
*
|
||||
* @param value
|
||||
* @param path
|
||||
*/
|
||||
public static void saveTextFile(String value, String path) {
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
writer = new FileWriter(file);
|
||||
writer.write(value);
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getText(String path) {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return getText(new FileInputStream(file));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getText(InputStream inputStream) {
|
||||
InputStreamReader isr = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
isr = new InputStreamReader(inputStream, "utf-8");
|
||||
bufferedReader = new BufferedReader(isr);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String string;
|
||||
while ((string = bufferedReader.readLine()) != null) {
|
||||
string = string + "\n";
|
||||
builder.append(string);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bufferedReader != null) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (isr != null) {
|
||||
try {
|
||||
isr.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 文件长度
|
||||
* @param size 限制大小
|
||||
* @param unit 限制单位(B,K,M,G)
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkFileSize(Long len, int size, String unit) {
|
||||
double fileSize = 0;
|
||||
if ("B".equals(unit.toUpperCase())) {
|
||||
fileSize = (double) len;
|
||||
} else if ("K".equals(unit.toUpperCase())) {
|
||||
fileSize = (double) len / 1024;
|
||||
} else if ("M".equals(unit.toUpperCase())) {
|
||||
fileSize = (double) len / 1048576;
|
||||
} else if ("G".equals(unit.toUpperCase())) {
|
||||
fileSize = (double) len / 1073741824;
|
||||
}
|
||||
if (fileSize > size) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -143,4 +143,34 @@ public class ResourcesUtils {
|
|||
private String title;
|
||||
private int index;
|
||||
}
|
||||
|
||||
public enum SqlTools{
|
||||
|
||||
MySql_Code_Generate("mysql 代码生成",0),
|
||||
;
|
||||
|
||||
SqlTools(String title, int index) {
|
||||
this.title = title;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
private String title;
|
||||
private int index;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,360 @@
|
|||
package com.zhangmeng.tools.utils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.zhangmeng.tools.dto.GenerateInput;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class TemplateUtil {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger("adminLogger");
|
||||
|
||||
public static String getTemplete(String fileName) {
|
||||
return FileUtil.getText(TemplateUtil.class.getClassLoader().getResourceAsStream("generate/" + fileName));
|
||||
}
|
||||
|
||||
public static void saveJava(GenerateInput input) {
|
||||
String path = input.getPath();
|
||||
String beanPackageName = input.getBeanPackageName();
|
||||
String beanName = input.getBeanName();
|
||||
List<String> beanFieldName = input.getBeanFieldName();
|
||||
List<String> beanFieldType = input.getBeanFieldType();
|
||||
List<String> beanFieldValue = input.getBeanFieldValue();
|
||||
|
||||
String text = getTemplete("java.txt");
|
||||
text = text.replace("{beanPackageName}", beanPackageName).replace("{beanName}", beanName);
|
||||
|
||||
String imports = "";
|
||||
if (beanFieldType.contains(BigDecimal.class.getSimpleName())) {
|
||||
imports += "import " + BigDecimal.class.getName() + ";\n";
|
||||
}
|
||||
if (beanFieldType.contains(Date.class.getSimpleName())) {
|
||||
imports += "import " + Date.class.getName() + ";";
|
||||
}
|
||||
|
||||
text = text.replace("{import}", imports);
|
||||
String filelds = getFields(beanFieldName, beanFieldType, beanFieldValue);
|
||||
text = text.replace("{filelds}", filelds);
|
||||
text = text.replace("{getset}", getset(beanFieldName, beanFieldType));
|
||||
|
||||
FileUtil.saveTextFile(text, path + File.separator + getPackagePath(beanPackageName) + beanName + ".java");
|
||||
log.debug("生成java model:{}模板", beanName);
|
||||
}
|
||||
|
||||
private static String getFields(List<String> beanFieldName, List<String> beanFieldType,
|
||||
List<String> beanFieldValue) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = beanFieldName.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String name = beanFieldName.get(i);
|
||||
if ("id".equals(name) || "createTime".equals(name) || "updateTime".equals(name)) {
|
||||
continue;
|
||||
}
|
||||
String type = beanFieldType.get(i);
|
||||
buffer.append("\tprivate ").append(type).append(" ").append(name);
|
||||
// 默认值
|
||||
// String value = beanFieldValue.get(i);
|
||||
// if (!StringUtils.isEmpty(value)) {
|
||||
// buffer.append(" = ");
|
||||
// if (type.equals(String.class.getSimpleName())) {
|
||||
// value = "\"" + value + "\"";
|
||||
// } else if (type.equals(Double.class.getSimpleName())) {
|
||||
// value = value + "D";
|
||||
// } else if (type.equals(Float.class.getSimpleName())) {
|
||||
// value = value + "F";
|
||||
// } else if (type.equals(BigDecimal.class.getSimpleName())) {
|
||||
// value = "new BigDecimal(" + value + ")";
|
||||
// }
|
||||
//
|
||||
// buffer.append(value);
|
||||
// }
|
||||
buffer.append(";\n");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private static String getset(List<String> beanFieldName, List<String> beanFieldType) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = beanFieldName.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String name = beanFieldName.get(i);
|
||||
if ("id".equals(name) || "createTime".equals(name) || "updateTime".equals(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String type = beanFieldType.get(i);
|
||||
buffer.append("\tpublic ").append(type).append(" get")
|
||||
.append(StringUtils.substring(name, 0, 1).toUpperCase() + name.substring(1, name.length()))
|
||||
.append("() {\n");
|
||||
buffer.append("\t\treturn ").append(name).append(";\n");
|
||||
buffer.append("\t}\n");
|
||||
buffer.append("\tpublic void set")
|
||||
.append(StringUtils.substring(name, 0, 1).toUpperCase() + name.substring(1, name.length()))
|
||||
.append("(").append(type).append(" ").append(name).append(") {\n");
|
||||
buffer.append("\t\tthis.").append(name).append(" = ").append(name).append(";\n");
|
||||
buffer.append("\t}\n");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static void saveJavaDao(GenerateInput input) {
|
||||
String path = input.getPath();
|
||||
String tableName = input.getTableName();
|
||||
String beanPackageName = input.getBeanPackageName();
|
||||
String beanName = input.getBeanName();
|
||||
String daoPackageName = input.getDaoPackageName();
|
||||
String daoName = input.getDaoName();
|
||||
|
||||
String text = getTemplete("dao.txt");
|
||||
text = text.replace("{daoPackageName}", daoPackageName);
|
||||
text = text.replace("{beanPackageName}", beanPackageName);
|
||||
text = text.replace("{daoName}", daoName);
|
||||
text = text.replace("{table_name}", tableName);
|
||||
text = text.replace("{beanName}", beanName);
|
||||
text = text.replace("{beanParamName}", lowerFirstChar(beanName));
|
||||
|
||||
String insertColumns = getInsertColumns(input.getColumnNames());
|
||||
text = text.replace("{insert_columns}", insertColumns);
|
||||
String insertValues = getInsertValues(input.getColumnNames(), input.getBeanFieldName());
|
||||
text = text.replace("{insert_values}", insertValues);
|
||||
FileUtil.saveTextFile(text, path + File.separator + getPackagePath(daoPackageName) + daoName + ".java");
|
||||
log.debug("生成java dao:{}模板", beanName);
|
||||
|
||||
text = getTemplete("mapper.xml");
|
||||
text = text.replace("{daoPackageName}", daoPackageName);
|
||||
text = text.replace("{daoName}", daoName);
|
||||
text = text.replace("{table_name}", tableName);
|
||||
text = text.replace("{beanName}", beanName);
|
||||
String sets = getUpdateSets(input.getColumnNames(), input.getBeanFieldName());
|
||||
text = text.replace("{update_sets}", sets);
|
||||
String where = getWhere(input.getColumnNames(), input.getBeanFieldName());
|
||||
text = text.replace("{where}", where);
|
||||
FileUtil.saveTextFile(text, path + File.separator + beanName + "Mapper.xml");
|
||||
}
|
||||
|
||||
private static String getInsertValues(List<String> columnNames, List<String> beanFieldName) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String column = columnNames.get(i);
|
||||
if (!"id".equals(column)) {
|
||||
buffer.append("#{").append(beanFieldName.get(i)).append("}, ");
|
||||
}
|
||||
}
|
||||
|
||||
String sets = StringUtils.substringBeforeLast(buffer.toString(), ",");
|
||||
return sets;
|
||||
}
|
||||
|
||||
private static String getInsertColumns(List<String> columnNames) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String column = columnNames.get(i);
|
||||
if (!"id".equals(column)) {
|
||||
buffer.append(column).append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
String insertColumns = StringUtils.substringBeforeLast(buffer.toString(), ",");
|
||||
return insertColumns;
|
||||
}
|
||||
|
||||
private static String getUpdateSets(List<String> columnNames, List<String> beanFieldName) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String column = columnNames.get(i);
|
||||
if (!"id".equals(column)) {
|
||||
buffer.append("\t\t\t<if test=\"" + beanFieldName.get(i) + " != null\">\n");
|
||||
buffer.append("\t\t\t\t" + column).append(" = ").append("#{").append(beanFieldName.get(i))
|
||||
.append("}, \n");
|
||||
buffer.append("\t\t\t</if>\n");
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private static String getWhere(List<String> columnNames, List<String> beanFieldName) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String column = columnNames.get(i);
|
||||
buffer.append("\t\t\t<if test=\"params." + beanFieldName.get(i) + " != null and params." + beanFieldName.get(i) + " != ''\">\n");
|
||||
buffer.append("\t\t\t\tand " + column).append(" = ").append("#{params.").append(beanFieldName.get(i))
|
||||
.append("} \n");
|
||||
buffer.append("\t\t\t</if>\n");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 变量名
|
||||
*
|
||||
* @param beanName
|
||||
* @return
|
||||
*/
|
||||
public static String lowerFirstChar(String beanName) {
|
||||
String name = str2hump(beanName);
|
||||
String firstChar = name.substring(0, 1);
|
||||
name = name.replaceFirst(firstChar, firstChar.toLowerCase());
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转为驼峰
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String str2hump(String str) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (str != null && str.length() > 0) {
|
||||
if (str.contains("_")) {
|
||||
String[] chars = str.split("_");
|
||||
int size = chars.length;
|
||||
if (size > 0) {
|
||||
List<String> list = Lists.newArrayList();
|
||||
for (String s : chars) {
|
||||
if (s != null && s.trim().length() > 0) {
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
size = list.size();
|
||||
if (size > 0) {
|
||||
buffer.append(list.get(0));
|
||||
for (int i = 1; i < size; i++) {
|
||||
String s = list.get(i);
|
||||
buffer.append(s.substring(0, 1).toUpperCase());
|
||||
if (s.length() > 1) {
|
||||
buffer.append(s.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buffer.append(str);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
private static String getPackagePath(String packageName) {
|
||||
String packagePath = packageName.replace(".", "/");
|
||||
if (!packagePath.endsWith("/")) {
|
||||
packagePath = packagePath + "/";
|
||||
}
|
||||
|
||||
return packagePath;
|
||||
}
|
||||
|
||||
public static void saveController(GenerateInput input) {
|
||||
String path = input.getPath();
|
||||
String beanPackageName = input.getBeanPackageName();
|
||||
String beanName = input.getBeanName();
|
||||
String daoPackageName = input.getDaoPackageName();
|
||||
String daoName = input.getDaoName();
|
||||
|
||||
String text = getTemplete("controller.txt");
|
||||
text = text.replace("{daoPackageName}", daoPackageName);
|
||||
text = text.replace("{beanPackageName}", beanPackageName);
|
||||
text = text.replace("{daoName}", daoName);
|
||||
text = text.replace("{daoParamName}", lowerFirstChar(daoName));
|
||||
text = text.replace("{beanName}", beanName);
|
||||
text = text.replace("{beanParamName}", lowerFirstChar(beanName));
|
||||
text = text.replace("{controllerPkgName}", input.getControllerPkgName());
|
||||
text = text.replace("{controllerName}", input.getControllerName());
|
||||
|
||||
FileUtil.saveTextFile(text, path + File.separator + getPackagePath(input.getControllerPkgName())
|
||||
+ input.getControllerName() + ".java");
|
||||
log.debug("生成controller:{}模板", beanName);
|
||||
}
|
||||
|
||||
public static void saveHtmlList(GenerateInput input) {
|
||||
String path = input.getPath();
|
||||
String beanName = input.getBeanName();
|
||||
String beanParamName = lowerFirstChar(beanName);
|
||||
|
||||
String text = getTemplete("htmlList.txt");
|
||||
text = text.replace("{beanParamName}", beanParamName);
|
||||
text = text.replace("{beanName}", beanName);
|
||||
List<String> beanFieldNames = input.getBeanFieldName();
|
||||
text = text.replace("{columnsDatas}", getHtmlColumnsDatas(beanFieldNames));
|
||||
text = text.replace("{ths}", getHtmlThs(beanFieldNames));
|
||||
|
||||
FileUtil.saveTextFile(text, path + File.separator + beanParamName + "List.html");
|
||||
log.debug("生成查询页面:{}模板", beanName);
|
||||
|
||||
text = getTemplete("htmlAdd.txt");
|
||||
text = text.replace("{beanParamName}", beanParamName);
|
||||
text = text.replace("{addDivs}", getAddDivs(beanFieldNames));
|
||||
FileUtil.saveTextFile(text, path + File.separator + "add" + beanName + ".html");
|
||||
log.debug("生成添加页面:{}模板", beanName);
|
||||
|
||||
text = getTemplete("htmlUpdate.txt");
|
||||
text = text.replace("{beanParamName}", beanParamName);
|
||||
text = text.replace("{addDivs}", getAddDivs(beanFieldNames));
|
||||
text = text.replace("{initData}", getInitData(beanFieldNames));
|
||||
FileUtil.saveTextFile(text, path + File.separator + "update" + beanName + ".html");
|
||||
log.debug("生成修改页面:{}模板", beanName);
|
||||
}
|
||||
|
||||
private static CharSequence getInitData(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
beanFieldNames.forEach(b -> {
|
||||
builder.append("\t\t\t\t\t\t$('#" + b + "').val(data." + b + ");\n");
|
||||
});
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getAddDivs(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
beanFieldNames.forEach(b -> {
|
||||
if (!"id".equals(b) && !"createTime".equals(b) && !"updateTime".equals(b)) {
|
||||
builder.append("\t\t\t<div class='form-group'>\n");
|
||||
builder.append("\t\t\t\t<label class='col-md-2 control-label'>" + b + "</label>\n");
|
||||
builder.append("\t\t\t\t<div class='col-md-10'>\n");
|
||||
builder.append("\t\t\t\t\t<input class='form-control' placeholder='" + b + "' type='text' name='" + b
|
||||
+ "' id='" + b + "' data-bv-notempty='true' data-bv-notempty-message='" + b + " 不能为空'>\n");
|
||||
builder.append("\t\t\t\t</div>\n");
|
||||
builder.append("\t\t\t</div>\n");
|
||||
}
|
||||
});
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getHtmlThs(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
beanFieldNames.forEach(b -> {
|
||||
builder.append("\t\t\t\t\t\t\t\t\t<th>{beanFieldName}</th>\n".replace("{beanFieldName}", b));
|
||||
});
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getHtmlColumnsDatas(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
beanFieldNames.forEach(b -> {
|
||||
builder.append("\t\t\t\t{\"data\" : \"{beanFieldName}\", \"defaultContent\" : \"\"},\n"
|
||||
.replace("{beanFieldName}", b));
|
||||
});
|
||||
|
||||
builder.append("");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -45,6 +45,12 @@
|
|||
<MenuItem mnemonicParsing="false" text="摩尔斯电码" onAction="#morse_coder_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
|
||||
<Menu mnemonicParsing="false" text="sql工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="mysql代码生成" onAction="#sql_code_gen_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
</menus>
|
||||
</MenuBar>
|
||||
<SplitPane fx:id="splitPane" dividerPositions="0.5" layoutY="25.0" prefHeight="575.0" prefWidth="1200.0"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<?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">
|
||||
|
||||
</AnchorPane>
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.Menu?>
|
||||
<?import javafx.scene.control.MenuBar?>
|
||||
<?import javafx.scene.control.MenuItem?>
|
||||
<?import javafx.scene.control.SplitPane?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<AnchorPane prefHeight="800.0"
|
||||
prefWidth="1661.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.zhangmeng.tools.controller.SqlToolsController">
|
||||
<children>
|
||||
<MenuBar layoutX="14.0" layoutY="27.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0">
|
||||
<menus>
|
||||
<Menu mnemonicParsing="false" text="加密工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#md5_menu_item" text="md5 加密"/>
|
||||
<MenuItem mnemonicParsing="false" onAction="#spring_security_menu_item"
|
||||
text="spring security 加密"/>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="影音工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="视频播放" onAction="#video_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="音乐播放" onAction="#music_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="vip 视频解析" onAction="#vip_parser_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="常用小工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="16进制(Hex)" onAction="#hex_16_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="Unicode和字符串转换" onAction="#unicode_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="jwt工具" onAction="#jwt_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="颜色选择工具" onAction="#color_choose_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
|
||||
<Menu mnemonicParsing="false" text="编解码工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="Base62编码解码" onAction="#base_62_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="Base64编码解码" onAction="#base_64_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="Base32编码解码" onAction="#base_32_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="摩尔斯电码" onAction="#morse_coder_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
|
||||
<Menu mnemonicParsing="false" text="sql工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="mysql代码生成" onAction="#sql_code_gen_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
</menus>
|
||||
</MenuBar>
|
||||
<SplitPane fx:id="splitPane" dividerPositions="0.5" layoutY="25.0" prefHeight="575.0" prefWidth="1200.0"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="25.0">
|
||||
<items>
|
||||
<ListView fx:id="listView" maxWidth="300.0" minWidth="200.0" prefHeight="200.0" prefWidth="200.0"/>
|
||||
<AnchorPane prefHeight="200.0" prefWidth="200.0"/>
|
||||
</items>
|
||||
</SplitPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Loading…
Reference in New Issue