├── src └── main │ ├── resources │ ├── 代办事项 │ ├── image │ │ ├── icon.png │ │ ├── about.png │ │ ├── config.png │ │ ├── table.png │ │ ├── computer.png │ │ ├── database.png │ │ ├── setting.png │ │ ├── instructions.png │ │ └── template-set.png │ ├── config │ │ ├── ConfigDB.db │ │ ├── log4j.properties │ │ └── language │ │ │ └── language_en.properties │ ├── css │ │ └── style.css │ ├── FXML │ │ ├── HistoryConfig.fxml │ │ ├── Setting.fxml │ │ ├── About.fxml │ │ ├── UpdateConnection.fxml │ │ ├── Connection.fxml │ │ ├── SetCustomProperty.fxml │ │ ├── SetCustom.fxml │ │ └── SetAbstractSQL.fxml │ └── template │ │ ├── Service.ftl │ │ ├── Entity.ftl │ │ ├── UnitTest.ftl │ │ ├── Controller.ftl │ │ ├── Dao.ftl │ │ └── ServiceImpl.ftl │ └── java │ └── com │ └── szmirren │ ├── controller │ ├── StageManager.java │ ├── FXMLPage.java │ ├── SettingController.java │ ├── AboutController.java │ ├── BaseController.java │ └── HistoryConfigController.java │ ├── common │ ├── SpringGenerator.java │ ├── Constant.java │ ├── CreateFileUtil.java │ ├── TemplateUtil.java │ ├── LanguageUtil.java │ ├── JDBCType.java │ ├── JavaType.java │ ├── StrUtil.java │ └── IoUtil.java │ ├── spi │ └── DatabaseTypeNames.java │ ├── entity │ ├── CustomContent.java │ ├── CustomPropertyContent.java │ ├── DaoContent.java │ ├── UnitTestContent.java │ ├── ServiceContent.java │ ├── MapperContent.java │ ├── ServiceImplContent.java │ ├── ControllerContent.java │ ├── SqlAssistContent.java │ ├── DatabaseContent.java │ ├── FieldAttribute.java │ ├── GeneratorContent.java │ ├── TableContent.java │ ├── EntityContent.java │ └── TableColumnsAttribute.java │ ├── models │ ├── DatabaseDTO.java │ ├── HistoryConfigCVF.java │ ├── DBType.java │ ├── TableAttributeEntityEditingCell.java │ ├── TableAttributeKeyValueEditingCell.java │ ├── TableAttributeKeyValueTemplateEditingCell.java │ ├── TableAttributeKeyValueTemplateVO.java │ ├── TableAttributeKeyValue.java │ ├── TableAttributeKeyValueTemplate.java │ └── TableAttributeEntity.java │ ├── options │ ├── CustomPropertyConfig.java │ ├── DatabaseConfig.java │ ├── SqlAssistConfig.java │ ├── EntityConfig.java │ ├── MapperConfig.java │ ├── CustomConfig.java │ ├── UnitTestConfig.java │ ├── ServiceConfig.java │ ├── ServiceImplConfig.java │ ├── ControllerConfig.java │ └── DaoConfig.java │ ├── view │ └── AlertUtil.java │ └── Main.java ├── .gitignore ├── .project ├── LICENSE ├── .classpath ├── README.md └── pom.xml /src/main/resources/代办事项: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/image/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/icon.png -------------------------------------------------------------------------------- /src/main/resources/image/about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/about.png -------------------------------------------------------------------------------- /src/main/resources/image/config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/config.png -------------------------------------------------------------------------------- /src/main/resources/image/table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/table.png -------------------------------------------------------------------------------- /src/main/resources/config/ConfigDB.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/config/ConfigDB.db -------------------------------------------------------------------------------- /src/main/resources/image/computer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/computer.png -------------------------------------------------------------------------------- /src/main/resources/image/database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/database.png -------------------------------------------------------------------------------- /src/main/resources/image/setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/setting.png -------------------------------------------------------------------------------- /src/main/resources/image/instructions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/instructions.png -------------------------------------------------------------------------------- /src/main/resources/image/template-set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliMirren/Spring-generator/HEAD/src/main/resources/image/template-set.png -------------------------------------------------------------------------------- /src/main/java/com/szmirren/controller/StageManager.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.controller; 2 | 3 | import java.util.Map; 4 | 5 | import javafx.stage.Stage; 6 | 7 | public class StageManager { 8 | public static Map STAGE=null; 9 | public static Map CONTROLLER=null; 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | /.settings/ 25 | /config/ 26 | /logs/ 27 | /target/ 28 | /template/ 29 | /.idea/ 30 | /Spring-generator.iml 31 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/SpringGenerator.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | /** 3 | * SpringGenerator相关属性的常量 4 | * 5 | * @author Mirren 6 | * 7 | */ 8 | public interface SpringGenerator { 9 | /** 版本号 x.x.x */ 10 | public final static String VERSION = "1.0.8"; 11 | /** 软件的名字Srping-generator */ 12 | public final static String NAME = "Spring-generator"; 13 | /** 软件的名字和版本Srping-generator_x.x.x */ 14 | public final static String NAME_VERSION = NAME + "_" + VERSION; 15 | } 16 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Spring-generator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/spi/DatabaseTypeNames.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.spi; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.common.Constant; 7 | 8 | /** 9 | * 数据库名字 10 | * 11 | * @author Mirren 12 | * 13 | */ 14 | public class DatabaseTypeNames { 15 | /** 16 | * 数据库的名称集合 17 | * 18 | * @return 19 | */ 20 | public static List dbTypeNames() { 21 | List result = new ArrayList<>(); 22 | result.add(Constant.MYSQL); 23 | result.add(Constant.POSTGRE_SQL); 24 | result.add(Constant.ORACLE); 25 | result.add(Constant.SQL_SERVER); 26 | result.add(Constant.SQLITE); 27 | return result; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/CustomContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * CustomContent的实体类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class CustomContent { 13 | /** CustomContent类的配置文件 */ 14 | private Map item = new HashMap<>(); 15 | 16 | /** 17 | * 初始化 18 | */ 19 | public CustomContent() { 20 | super(); 21 | } 22 | 23 | public Map getItem() { 24 | return item; 25 | } 26 | 27 | public void setItem(Map item) { 28 | this.item = item; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "CustomContent [item=" + item + "]"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/CustomPropertyContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 自定义属性的属性类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class CustomPropertyContent { 13 | /** 自定义属性类的配置信息 */ 14 | private Map item = new HashMap<>(); 15 | 16 | /** 17 | * 初始化 18 | */ 19 | public CustomPropertyContent() { 20 | super(); 21 | } 22 | 23 | public Map getItem() { 24 | return item; 25 | } 26 | 27 | public void setItem(Map item) { 28 | this.item = item; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "CustomPropertyContent [item=" + item + "]"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/css/style.css: -------------------------------------------------------------------------------- 1 | .btn-success:hover { 2 | -fx-text-fill: #fff; 3 | -fx-background-color: #449d44; 4 | -fx-border-color: #398439; 5 | } 6 | 7 | .btn-success { 8 | -fx-text-fill: #fff; 9 | -fx-background-color: #269f42; 10 | -fx-border-color: #15C13E; 11 | } 12 | .btn { 13 | -fx-border-width: 1.0px; 14 | -fx-border-color: transparent; 15 | -fx-border-radius: 4.0px; 16 | } 17 | .btn-executable { 18 | -fx-text-fill: #333; 19 | -fx-background-color: #fff; 20 | -fx-border-color: #5CB85C; 21 | } 22 | 23 | .btn-executable:hover { 24 | -fx-background-color: #F4F4F4; 25 | -fx-border-color: #5CB85C; 26 | } 27 | 28 | .btn-default { 29 | -fx-text-fill: #333; 30 | -fx-background-color: #fff; 31 | -fx-border-color: #ccc; 32 | } 33 | 34 | .btn-default:hover { 35 | -fx-background-color: #e6e6e6; 36 | -fx-border-color: #adadad; 37 | } 38 | .pane-padding{ 39 | -fx-padding: 0.0px 10.0px; 40 | } -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/DatabaseDTO.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | /** 4 | * 数据库连接DTO 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class DatabaseDTO { 10 | 11 | private String name; 12 | private int value; 13 | private String driverClass; 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | public int getValue() { 24 | return value; 25 | } 26 | 27 | public void setValue(int value) { 28 | this.value = value; 29 | } 30 | 31 | public String getDriverClass() { 32 | return driverClass; 33 | } 34 | 35 | public void setDriverClass(String driverClass) { 36 | this.driverClass = driverClass; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "DatabaseDTO [name=" + name + ", value=" + value + ", driverClass=" + driverClass + "]"; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/resources/FXML/HistoryConfig.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/HistoryConfigCVF.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | import javafx.beans.property.SimpleStringProperty; 4 | import javafx.beans.property.StringProperty; 5 | import javafx.scene.layout.HBox; 6 | 7 | /** 8 | * 配置文件设置项 9 | * 10 | * @author Mirren 11 | * 12 | */ 13 | public class HistoryConfigCVF { 14 | 15 | StringProperty name; 16 | HBox hbox; 17 | 18 | public HistoryConfigCVF() { 19 | super(); 20 | } 21 | 22 | public HistoryConfigCVF(String name, HBox hbox) { 23 | super(); 24 | this.name = new SimpleStringProperty(name); 25 | this.hbox = hbox; 26 | } 27 | 28 | public HistoryConfigCVF(HBox hbox) { 29 | super(); 30 | this.hbox = hbox; 31 | } 32 | 33 | public HBox getHbox() { 34 | return hbox; 35 | } 36 | 37 | public void setHbox(HBox hbox) { 38 | this.hbox = hbox; 39 | } 40 | 41 | public String getName() { 42 | return name.get(); 43 | } 44 | 45 | public void setName(SimpleStringProperty name) { 46 | this.name = name; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 MirrenTools 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/DBType.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | /** 4 | * 数据库类型 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public enum DBType { 10 | Oracle("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@%s:%s:%s"), 11 | OracleServiceName("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@%s:%s/%s"), 12 | MySQL("com.mysql.cj.jdbc.Driver", "jdbc:mysql://%s:%s/%s?useUnicode=true&useSSL=false&characterEncoding=%s&serverTimezone=UTC"), 13 | SqlServer("com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://%s:%s;databaseName=%s"), 14 | PostgreSQL("org.postgresql.Driver","jdbc:postgresql://%s:%s/%s"), 15 | Sqlite("org.sqlite.JDBC","jdbc:sqlite:%s%s/%s"); 16 | private final String driverClass; 17 | private final String connectionUrlPattern; 18 | 19 | DBType(String driverClass, String connectionUrlPattern) { 20 | this.driverClass = driverClass; 21 | this.connectionUrlPattern = connectionUrlPattern; 22 | } 23 | 24 | public String getDriverClass() { 25 | return driverClass; 26 | } 27 | 28 | public String getConnectionUrlPattern() { 29 | return connectionUrlPattern; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/main/resources/config/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger = debug,Console,info,err 2 | 3 | #Console 4 | log4j.appender.Console=org.apache.log4j.ConsoleAppender 5 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.Console.layout.ConversionPattern=[%p] %-d{yyyy-MM-dd HH\:mm\:ss} --> %m --> %F:%L %n 7 | 8 | log4j.appender.info = org.apache.log4j.DailyRollingFileAppender 9 | log4j.appender.info.Encoding=UTF-8 10 | log4j.appender.info.File =logs/info/info.log 11 | log4j.appender.info.DatePattern = '-'yyyy-MM-dd'.log' 12 | log4j.appender.info.Append = true 13 | log4j.appender.info.Threshold = DEBUG 14 | log4j.appender.info.layout = org.apache.log4j.PatternLayout 15 | log4j.appender.info.layout.ConversionPattern = [%p] %-d{yyyy-MM-dd HH\:mm\:ss} --> %m --> %F:%L %n%n 16 | 17 | 18 | log4j.appender.err = org.apache.log4j.DailyRollingFileAppender 19 | log4j.appender.err.Encoding=UTF-8 20 | log4j.appender.err.File =logs/error/error.log 21 | log4j.appender.err.DatePattern = '-'yyyy-MM-dd'.log' 22 | log4j.appender.err.Append = true 23 | log4j.appender.err.Threshold = ERROR 24 | log4j.appender.err.layout = org.apache.log4j.PatternLayout 25 | log4j.appender.err.layout.ConversionPattern = [%p] %-d{yyyy-MM-dd HH\:mm\:ss} --> %m --> %F:%L %n%n 26 | 27 | 28 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/controller/FXMLPage.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.controller; 2 | 3 | /** 4 | * 页面枚举类 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public enum FXMLPage { 10 | /** 数据库连接页面 */ 11 | CONNECTION("FXML/Connection.fxml"), 12 | /** 数据库修改页面 */ 13 | UPDATE_CONNECTION("FXML/UpdateConnection.fxml"), 14 | /** 配置信息页面 */ 15 | HISTORY_CONFIG("FXML/HistoryConfig.fxml"), 16 | /** 实体类属性设置页面 */ 17 | SET_ENTITY_ATTRIBUTE("FXML/setEntityAttribute.fxml"), 18 | /** Service设置页面 */ 19 | SET_ROUTER_SERVICE("FXML/SetService.fxml"), 20 | /** ServiceImpl设置页面 */ 21 | SET_ROUTER_SERVICE_IMPL("FXML/SetServiceImpl.fxml"), 22 | /** Router设置页面 */ 23 | SET_ROUTER("FXML/SetRouter.fxml"), 24 | /** SQL设置页面 */ 25 | SET_SQL("FXML/SetSql.fxml"), 26 | /** SQLAssist设置页面 */ 27 | SET_ASSIST("FXML/SetAssist.fxml"), 28 | /** AbstractSQL设置页面 */ 29 | SET_ABSTRACT_SQL("FXML/SetAbstractSQL.fxml"), 30 | /** SQLAssist设置页面 */ 31 | SET_MAPPER("FXML/SetMapper.fxml"), 32 | /** SQLAssist设置页面 */ 33 | SET_UNIT_TEST("FXML/SetUnitTest.fxml"), 34 | /** SetCustomProperty设置页面 */ 35 | SET_CUSTOM("FXML/SetCustom.fxml"), 36 | /** SetCustomProperty设置页面 */ 37 | SET_CUSTOM_PROPERTY("FXML/SetCustomProperty.fxml"), 38 | /** 使用说明页面 */ 39 | ABOUT("FXML/About.fxml"), 40 | /** 设置页面 */ 41 | SETTING("FXML/Setting.fxml"); 42 | 43 | private String fxml; 44 | 45 | FXMLPage(String fxml) { 46 | this.fxml = fxml; 47 | } 48 | 49 | public String getFxml() { 50 | return this.fxml; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/controller/SettingController.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.controller; 2 | 3 | import java.net.URL; 4 | import java.util.Locale; 5 | import java.util.ResourceBundle; 6 | 7 | import com.szmirren.Main; 8 | import com.szmirren.common.LanguageKey; 9 | 10 | import javafx.fxml.FXML; 11 | import javafx.scene.control.Label; 12 | import javafx.scene.control.MenuButton; 13 | 14 | public class SettingController extends BaseController { 15 | /** 语言 */ 16 | @FXML 17 | private Label lblLanguage; 18 | /** 语言选择 */ 19 | @FXML 20 | private MenuButton mbLanguage; 21 | /** 英语 */ 22 | @FXML 23 | private Label lblEnglish; 24 | /** 中文 */ 25 | @FXML 26 | private Label lblSimpleChinese; 27 | 28 | @Override 29 | public void initialize(URL arg0, ResourceBundle arg1) { 30 | lblLanguage.textProperty().bind(Main.LANGUAGE.get(LanguageKey.SETTING_LBL_LANGUAGE)); 31 | lblLanguage.widthProperty().addListener(ev -> mbLanguage.setLayoutX(10 + lblLanguage.getLayoutX() + lblLanguage.getWidth())); 32 | // 设置选择框里面的文字跟选择框一样大 33 | mbLanguage.widthProperty().addListener(ev -> { 34 | if (mbLanguage.getWidth() > 100) { 35 | lblEnglish.setPrefWidth(mbLanguage.getWidth() - 15); 36 | lblSimpleChinese.setPrefWidth(mbLanguage.getWidth() - 15); 37 | } 38 | }); 39 | // 给语言添加事件 40 | lblEnglish.setOnMouseClicked(ev -> { 41 | Main.loadLanguage(Locale.ENGLISH); 42 | closeDialogStage(); 43 | }); 44 | lblSimpleChinese.setOnMouseClicked(ev -> { 45 | Main.loadLanguage(Locale.SIMPLIFIED_CHINESE); 46 | closeDialogStage(); 47 | }); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/CustomPropertyConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.models.TableAttributeKeyValue; 7 | 8 | import javafx.collections.ObservableList; 9 | 10 | /** 11 | * 自定义属性的配置文件 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public class CustomPropertyConfig { 17 | /** 设置的tableItem */ 18 | private List tableItem = new ArrayList<>(); 19 | 20 | /** 21 | * 初始化 22 | */ 23 | public CustomPropertyConfig() { 24 | super(); 25 | } 26 | 27 | /** 28 | * 通过 ObservableList初始化 29 | * 30 | * @param tableItem 31 | */ 32 | public CustomPropertyConfig(ObservableList item) { 33 | super(); 34 | if (item != null && !item.isEmpty()) { 35 | tableItem.addAll(item); 36 | } 37 | } 38 | 39 | /** 40 | * 初始化默认参数 41 | * 42 | * @return 43 | */ 44 | public CustomPropertyConfig initDefaultValue() { 45 | return this; 46 | } 47 | 48 | /** 49 | * 获取属性集合 50 | * 51 | * @return 52 | */ 53 | public List getTableItem() { 54 | return tableItem; 55 | } 56 | 57 | /** 58 | * 设置属性集合 59 | * 60 | * @param tableItem 61 | */ 62 | public void setTableItem(List tableItem) { 63 | this.tableItem = tableItem; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "CustomPropertyConfig [tableItem=" + tableItem + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/DaoContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * SqlAssist的实体类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class DaoContent { 13 | /** SqlAssist类的包名 */ 14 | private String classPackage; 15 | /** SqlAssist类的类型 */ 16 | private String className; 17 | /** SqlAssist类的配置文件 */ 18 | private Map item = new HashMap<>(); 19 | 20 | /** 21 | * 初始化 22 | */ 23 | public DaoContent() { 24 | super(); 25 | } 26 | 27 | /** 28 | * 通过包名与类名初始化 29 | * 30 | * @param classPackage 31 | * @param className 32 | */ 33 | public DaoContent(String classPackage, String className) { 34 | super(); 35 | this.classPackage = classPackage; 36 | this.className = className; 37 | } 38 | 39 | public String getClassPackage() { 40 | return classPackage; 41 | } 42 | 43 | public void setClassPackage(String classPackage) { 44 | this.classPackage = classPackage; 45 | } 46 | 47 | public String getClassName() { 48 | return className; 49 | } 50 | 51 | public void setClassName(String className) { 52 | this.className = className; 53 | } 54 | 55 | public Map getItem() { 56 | return item; 57 | } 58 | 59 | public void setItem(Map item) { 60 | this.item = item; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "SQLContent [classPackage=" + classPackage + ", className=" + className + ", item=" + item + "]"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/UnitTestContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * SqlAssist的实体类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class UnitTestContent { 13 | /** SqlAssist类的包名 */ 14 | private String classPackage; 15 | /** SqlAssist类的类型 */ 16 | private String className; 17 | /** SqlAssist类的配置文件 */ 18 | private Map item = new HashMap<>(); 19 | 20 | /** 21 | * 初始化 22 | */ 23 | public UnitTestContent() { 24 | super(); 25 | } 26 | 27 | /** 28 | * 通过包名与类名初始化 29 | * 30 | * @param classPackage 31 | * @param className 32 | */ 33 | public UnitTestContent(String classPackage, String className) { 34 | super(); 35 | this.classPackage = classPackage; 36 | this.className = className; 37 | } 38 | 39 | public String getClassPackage() { 40 | return classPackage; 41 | } 42 | 43 | public void setClassPackage(String classPackage) { 44 | this.classPackage = classPackage; 45 | } 46 | 47 | public String getClassName() { 48 | return className; 49 | } 50 | 51 | public void setClassName(String className) { 52 | this.className = className; 53 | } 54 | 55 | public Map getItem() { 56 | return item; 57 | } 58 | 59 | public void setItem(Map item) { 60 | this.item = item; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "UnitTestContent [classPackage=" + classPackage + ", className=" + className + ", item=" + item + "]"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/ServiceContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Service的实体类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class ServiceContent { 13 | /** Service类的包名 */ 14 | private String classPackage; 15 | /** Service类的类型 */ 16 | private String className; 17 | /** Service类的属性 */ 18 | private Map item = new HashMap<>(); 19 | 20 | /** 21 | * 初始化 22 | */ 23 | public ServiceContent() { 24 | super(); 25 | } 26 | 27 | /** 28 | * 通过包名与类名初始化 29 | * 30 | * @param classPackage 31 | * @param className 32 | */ 33 | public ServiceContent(String classPackage, String className) { 34 | super(); 35 | this.classPackage = classPackage; 36 | this.className = className; 37 | } 38 | 39 | 40 | 41 | 42 | public String getClassPackage() { 43 | return classPackage; 44 | } 45 | 46 | public void setClassPackage(String classPackage) { 47 | this.classPackage = classPackage; 48 | } 49 | 50 | public String getClassName() { 51 | return className; 52 | } 53 | 54 | public void setClassName(String className) { 55 | this.className = className; 56 | } 57 | 58 | public Map getItem() { 59 | return item; 60 | } 61 | 62 | public void setItem(Map item) { 63 | this.item = item; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "ServiceContent [classPackage=" + classPackage + ", className=" + className + ", item=" + item + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/MapperContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * SqlAssist的实体类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class MapperContent { 13 | /** SqlAssist类的包名 */ 14 | private String classPackage; 15 | /** SqlAssist类的类型 */ 16 | private String className; 17 | /** SqlAssist类的配置文件 */ 18 | private Map item = new HashMap<>(); 19 | 20 | /** 21 | * 初始化 22 | */ 23 | public MapperContent() { 24 | super(); 25 | } 26 | 27 | /** 28 | * 通过包名与类名初始化 29 | * 30 | * @param classPackage 31 | * @param className 32 | */ 33 | public MapperContent(String classPackage, String className) { 34 | super(); 35 | this.classPackage = classPackage; 36 | this.className = className; 37 | } 38 | 39 | 40 | 41 | 42 | public String getClassPackage() { 43 | return classPackage; 44 | } 45 | 46 | public void setClassPackage(String classPackage) { 47 | this.classPackage = classPackage; 48 | } 49 | 50 | public String getClassName() { 51 | return className; 52 | } 53 | 54 | public void setClassName(String className) { 55 | this.className = className; 56 | } 57 | 58 | public Map getItem() { 59 | return item; 60 | } 61 | 62 | public void setItem(Map item) { 63 | this.item = item; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "SQLContent [classPackage=" + classPackage + ", className=" + className + ", item=" + item + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/ServiceImplContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * ServiceImpl的实体类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class ServiceImplContent { 13 | /** ServiceImpl类的包名 */ 14 | private String classPackage; 15 | /** ServiceImpl类的类型 */ 16 | private String className; 17 | /** ServiceImpl类的属性 */ 18 | private Map item = new HashMap<>(); 19 | 20 | /** 21 | * 初始化 22 | */ 23 | public ServiceImplContent() { 24 | super(); 25 | } 26 | 27 | /** 28 | * 通过包名与类名初始化 29 | * 30 | * @param classPackage 31 | * @param className 32 | */ 33 | public ServiceImplContent(String classPackage, String className) { 34 | super(); 35 | this.classPackage = classPackage; 36 | this.className = className; 37 | } 38 | 39 | public String getClassPackage() { 40 | return classPackage; 41 | } 42 | 43 | public void setClassPackage(String classPackage) { 44 | this.classPackage = classPackage; 45 | } 46 | 47 | public String getClassName() { 48 | return className; 49 | } 50 | 51 | public void setClassName(String className) { 52 | this.className = className; 53 | } 54 | 55 | public Map getItem() { 56 | return item; 57 | } 58 | 59 | public void setItem(Map item) { 60 | this.item = item; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "ServiceImplContent [classPackage=" + classPackage + ", className=" + className + ", item=" + item + "]"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/ControllerContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * SqlAssist的实体类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class ControllerContent { 13 | /** SqlAssist类的包名 */ 14 | private String classPackage; 15 | /** SqlAssist类的类型 */ 16 | private String className; 17 | /** SqlAssist类的配置文件 */ 18 | private Map item = new HashMap<>(); 19 | 20 | /** 21 | * 初始化 22 | */ 23 | public ControllerContent() { 24 | super(); 25 | } 26 | 27 | /** 28 | * 通过包名与类名初始化 29 | * 30 | * @param classPackage 31 | * @param className 32 | */ 33 | public ControllerContent(String classPackage, String className) { 34 | super(); 35 | this.classPackage = classPackage; 36 | this.className = className; 37 | } 38 | 39 | 40 | 41 | 42 | public String getClassPackage() { 43 | return classPackage; 44 | } 45 | 46 | public void setClassPackage(String classPackage) { 47 | this.classPackage = classPackage; 48 | } 49 | 50 | public String getClassName() { 51 | return className; 52 | } 53 | 54 | public void setClassName(String className) { 55 | this.className = className; 56 | } 57 | 58 | public Map getItem() { 59 | return item; 60 | } 61 | 62 | public void setItem(Map item) { 63 | this.item = item; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "RouterContent [classPackage=" + classPackage + ", className=" + className + ", item=" + item + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/SqlAssistContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * SqlAssist的实体类 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class SqlAssistContent { 13 | /** SqlAssist类的包名 */ 14 | private String classPackage; 15 | /** SqlAssist类的类型 */ 16 | private String className; 17 | /** SqlAssist类的配置文件 */ 18 | private Map item = new HashMap<>(); 19 | 20 | /** 21 | * 初始化 22 | */ 23 | public SqlAssistContent() { 24 | super(); 25 | } 26 | 27 | /** 28 | * 通过包名与类名初始化 29 | * 30 | * @param classPackage 31 | * @param className 32 | */ 33 | public SqlAssistContent(String classPackage, String className) { 34 | super(); 35 | this.classPackage = classPackage; 36 | this.className = className; 37 | } 38 | 39 | 40 | 41 | 42 | public String getClassPackage() { 43 | return classPackage; 44 | } 45 | 46 | public void setClassPackage(String classPackage) { 47 | this.classPackage = classPackage; 48 | } 49 | 50 | public String getClassName() { 51 | return className; 52 | } 53 | 54 | public void setClassName(String className) { 55 | this.className = className; 56 | } 57 | 58 | public Map getItem() { 59 | return item; 60 | } 61 | 62 | public void setItem(Map item) { 63 | this.item = item; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "SqlAssistContent [classPackage=" + classPackage + ", className=" + className + ", item=" + item + "]"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 基本介绍 2 | 官方QQ交流群号:519714660;
3 | Spring-generator是基于javafx8开发的图形界面Spring代码生成器,使用 Apache FreeMarker 4 | 作为代码文件的模板,用户可以一键将数据库中的表生成为任意风格的.java代码文件(比如经典的三层模型);
5 | 该工具支持所有实现JDBC规范的数据库;默认集成了Oracle , SqlServer , MySQL , PostgreSql数据库驱动jar包;
6 | Spring-generator默认生成MyBatis的Dao并配有MyBatis的查询帮助工具Assist,但是Spring-generator并不局限于生成Spring与MyBatis等,它的使命是将数据库中表的属性提取为实体类属性,剩下的事情就取决你如何使用FreeMarker操作它
7 | ```html 8 | Spring-generator不是框架它不会影响任何现有的结构,Spring-generator只是一个生成工具,不拘于语言,只取决于你怎么使用FreeMarker编写模板,Assist是一个非常好用的帮助工具配合动态Mapper很完美 9 | ``` 10 | # 执行方法 11 | 执行方式在项目根目录执行mvn jfx:jar进行打包;jar打包为jar包native打包为系统安装软件;
12 | 该软件基于jdk1.8.66开发,测试环境1.8.121,已知最低要求特性为1.8.40,理论上大于1.8.40就可以运行;没有1.8环境的可以自己下载一个jre包并编写执行脚本运行就可以,可以参考文档说明
13 | ```html 14 | mvn jfx:jar 15 | 编译后进入target/jfx/app/ 双击执行Spring-Generator.jar 或者 java -jar Spring-Generator.jar 16 | ``` 17 | 18 | # 软件使用说明 19 | [Spring-generator的使用帮助文档](http://mirren.gitee.io/spring-generator-doc/)
20 | 21 | # 模板仓库 22 | [Spring-generator的模板仓库](https://github.com/EliMirren/Spring-generator-Template)
23 | 24 | # 工具主页
25 | ![index](https://raw.githubusercontent.com/shenzhenMirren/MyGithubResources/master/image/Spring-generator-index.png) 26 | 27 | # 特色功能预览:
28 |
    29 |
  1. 生成实体类
  2. 30 |
  3. 生成WEB API相关接口 Router
  4. 31 |
  5. 生成业务逻辑相关的Service/ServiceImpl
  6. 32 |
  7. 生成操作数据库的SQL类
  8. 33 |
  9. 生成单元测试
  10. 34 |
  11. 软件最大的特色就是操作SQL类的SqlAssist查询帮助类(Assist是特别定制的查询工具,使用该工具一切操作都会变得超简单,比如:分页通过Assist只需要设置2个参数就可以实现,比如参数1=10,参数2=5,查询出来就是第10行到15行的数据,同时也可以防注入动态添加查询添加,去重,排序,自定义返回列等); 35 |
  12. 36 |
37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/view/AlertUtil.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.view; 2 | 3 | import java.util.Optional; 4 | 5 | import javafx.scene.control.Alert; 6 | import javafx.scene.control.ButtonType; 7 | 8 | public class AlertUtil { 9 | /** 10 | * 信息提示框 11 | * 12 | * @param message 13 | */ 14 | public static void showInfoAlert(String message) { 15 | Alert alert = new Alert(Alert.AlertType.INFORMATION); 16 | alert.setContentText(message); 17 | alert.show(); 18 | } 19 | 20 | /** 21 | * 等待信息提示框 22 | * 23 | * @param message 24 | */ 25 | public static void showAndWaitInfoAlert(String message) { 26 | Alert alert = new Alert(Alert.AlertType.INFORMATION); 27 | alert.setContentText(message); 28 | alert.showAndWait(); 29 | } 30 | 31 | /** 32 | * 注意提示框 33 | * 34 | * @param message 35 | */ 36 | public static void showWarnAlert(String message) { 37 | Alert alert = new Alert(Alert.AlertType.WARNING); 38 | alert.setContentText(message); 39 | alert.show(); 40 | } 41 | 42 | /** 43 | * 异常提示框 44 | * 45 | * @param message 46 | */ 47 | public static void showErrorAlert(String message) { 48 | Alert alert = new Alert(Alert.AlertType.ERROR); 49 | alert.setContentText(message); 50 | alert.show(); 51 | } 52 | 53 | /** 54 | * 确定提示框 55 | * 56 | * @param message 57 | */ 58 | public static boolean showConfirmAlert(String message) { 59 | Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 60 | alert.setContentText(message); 61 | Optional optional = alert.showAndWait(); 62 | if (ButtonType.OK == optional.get()) { 63 | return true; 64 | } else { 65 | return false; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/resources/template/Service.ftl: -------------------------------------------------------------------------------- 1 | package ${content.service.classPackage}; 2 | import java.util.List; 3 | 4 | import ${content.serviceImpl.classPackage}.${content.serviceImpl.className}; 5 | import ${content.assist.classPackage}.${content.assist.className}; 6 | import ${content.entity.classPackage}.${content.entity.className}; 7 | 8 | /** 9 | * ${content.entity.className}的服务接口 10 | * 11 | * @author 12 | * 13 | */ 14 | public interface ${content.service.className} { 15 | /** 16 | * 获得${content.entity.className}数据集,可以通过辅助工具Assist进行条件查询,如果没有条件则传入null 17 | * 18 | * @return 19 | */ 20 | String ${content.service.item.select.value!}(${content.entity.className} value); 21 | 22 | <#if content.entity.primaryKeyAttr??> 23 | /** 24 | * 通过${content.entity.className}的id获得${content.entity.className}对象 25 | * 26 | * @param id 27 | * @return 28 | */ 29 | String ${content.service.item.selectById.value!}(${content.entity.primaryKeyAttr.javaType} id); 30 | <#else> 31 | // TODO 你的表中没有找到主键属性,你可以修改模板使用Assist来作为条件值做一些操作,比如用Assist来做删除与修改 32 | 33 | 34 | /** 35 | * 将${content.entity.className}中属性值不为null的数据到数据库 36 | * 37 | * @param value 38 | * @return 39 | */ 40 | String ${content.service.item.insertNotNull.value!}(${content.entity.className} value); 41 | 42 | <#if content.entity.primaryKeyAttr??> 43 | /** 44 | * 通过${content.entity.className}的id更新${content.entity.className}中属性不为null的数据 45 | * 46 | * @param enti 47 | * @return 48 | */ 49 | String ${content.service.item.updateNotNull.value!}(${content.entity.className} enti); 50 | 51 | /** 52 | * 通过${content.entity.className}的id删除${content.entity.className} 53 | * 54 | * @param id 55 | * @return 56 | */ 57 | String ${content.service.item.deleteById.value!}(${content.entity.primaryKeyAttr.javaType} id); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/Constant.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | 3 | import com.szmirren.Main; 4 | 5 | /** 6 | * 工具需要用到的常量词 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public interface Constant { 12 | // 数据库名字 13 | /** MySQL */ 14 | static final String MYSQL = "MySQL"; 15 | /** PostgreSQL */ 16 | static final String POSTGRE_SQL = "PostgreSQL"; 17 | /** SqlServer */ 18 | static final String SQL_SERVER = "SqlServer"; 19 | /** Oracle */ 20 | static final String ORACLE = "Oracle"; 21 | /** Oracle */ 22 | static final String SQLITE = "Sqlite"; 23 | 24 | /** java的后缀名.java */ 25 | static final String JAVA_SUFFIX = ".java"; 26 | 27 | /** default */ 28 | static final String DEFAULT = "default"; 29 | /** language */ 30 | static final String LANGUAGE = "language"; 31 | /** 模板的文件夹名称 */ 32 | static final String TEMPLATE_DIR_NAME = "template"; 33 | /** 刷新模板文件夹 */ 34 | static final String TEMPLATE_DIR_REFRESH = "刷新模板文件夹"; 35 | /** 实体类模板的默认名字 */ 36 | static final String TEMPLATE_NAME_ENTITY = "Entity.ftl"; 37 | /** Service模板的默认名字 */ 38 | static final String TEMPLATE_NAME_SERVICE = "Service.ftl"; 39 | /** ServiceImpl模板的默认名字 */ 40 | static final String TEMPLATE_NAME_SERVICE_IMPL = "ServiceImpl.ftl"; 41 | /** Service模板的默认名字 */ 42 | static final String TEMPLATE_NAME_ROUTER = "Controller.ftl"; 43 | /** Dao模板的默认名字 */ 44 | static final String TEMPLATE_NAME_DAO = "Dao.ftl"; 45 | /** Mapper模板的默认名字 */ 46 | static final String TEMPLATE_NAME_MAPPER = Main.LANGUAGE.get(LanguageKey.SET_ABSTRACT_AUTOMATIC).get(); 47 | /** Mapper模板的默认名字 */ 48 | static final String TEMPLATE_NAME_MAPPER_SUFFIX = "Mapper.ftl"; 49 | /** SqlAssist模板的默认名字 */ 50 | static final String TEMPLATE_NAME_SQL_ASSIST = "SqlAssist.ftl"; 51 | /** 单元测试模板的默认名字 */ 52 | static final String TEMPLATE_NAME_UNIT_TEST = "UnitTest.ftl"; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/resources/FXML/Setting.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 28 | 29 | 30 | 31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/TableAttributeEntityEditingCell.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | import javafx.beans.value.ObservableValue; 4 | import javafx.scene.control.TableCell; 5 | import javafx.scene.control.TextField; 6 | 7 | /** 8 | * table中列的监听与改变 9 | * 10 | * @author Mirren 11 | * 12 | */ 13 | public class TableAttributeEntityEditingCell extends TableCell { 14 | private TextField textField; 15 | 16 | public TableAttributeEntityEditingCell() { 17 | } 18 | 19 | @Override 20 | public void startEdit() { 21 | if (!isEmpty()) { 22 | super.startEdit(); 23 | createTextField(); 24 | setText(null); 25 | setGraphic(textField); 26 | textField.selectAll(); 27 | } 28 | } 29 | 30 | @Override 31 | public void cancelEdit() { 32 | super.cancelEdit(); 33 | 34 | setText((String) getItem()); 35 | setGraphic(null); 36 | } 37 | 38 | @Override 39 | public void updateItem(String item, boolean empty) { 40 | super.updateItem(item, empty); 41 | 42 | if (empty) { 43 | setText(null); 44 | setGraphic(null); 45 | } else { 46 | if (isEditing()) { 47 | if (textField != null) { 48 | textField.setText(getString()); 49 | } 50 | setText(null); 51 | setGraphic(textField); 52 | } else { 53 | setText(getString()); 54 | setGraphic(null); 55 | } 56 | } 57 | } 58 | 59 | private void createTextField() { 60 | textField = new TextField(getString()); 61 | textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2); 62 | textField.focusedProperty().addListener((ObservableValue arg0, Boolean arg1, Boolean arg2) -> { 63 | if (!arg2) { 64 | commitEdit(textField.getText()); 65 | } 66 | }); 67 | } 68 | 69 | private String getString() { 70 | return getItem() == null ? "" : getItem().toString(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/TableAttributeKeyValueEditingCell.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | import javafx.beans.value.ObservableValue; 4 | import javafx.scene.control.TableCell; 5 | import javafx.scene.control.TextField; 6 | 7 | /** 8 | * table中列的监听与改变 9 | * 10 | * @author Mirren 11 | * 12 | */ 13 | public class TableAttributeKeyValueEditingCell extends TableCell { 14 | private TextField textField; 15 | 16 | public TableAttributeKeyValueEditingCell() { 17 | } 18 | 19 | @Override 20 | public void startEdit() { 21 | if (!isEmpty()) { 22 | super.startEdit(); 23 | createTextField(); 24 | setText(null); 25 | setGraphic(textField); 26 | textField.selectAll(); 27 | } 28 | } 29 | 30 | @Override 31 | public void cancelEdit() { 32 | super.cancelEdit(); 33 | 34 | setText((String) getItem()); 35 | setGraphic(null); 36 | } 37 | 38 | @Override 39 | public void updateItem(String item, boolean empty) { 40 | super.updateItem(item, empty); 41 | 42 | if (empty) { 43 | setText(null); 44 | setGraphic(null); 45 | } else { 46 | if (isEditing()) { 47 | if (textField != null) { 48 | textField.setText(getString()); 49 | } 50 | setText(null); 51 | setGraphic(textField); 52 | } else { 53 | setText(getString()); 54 | setGraphic(null); 55 | } 56 | } 57 | } 58 | 59 | private void createTextField() { 60 | textField = new TextField(getString()); 61 | textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2); 62 | textField.focusedProperty().addListener((ObservableValue arg0, Boolean arg1, Boolean arg2) -> { 63 | if (!arg2) { 64 | commitEdit(textField.getText()); 65 | } 66 | }); 67 | } 68 | 69 | private String getString() { 70 | return getItem() == null ? "" : getItem().toString(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/TableAttributeKeyValueTemplateEditingCell.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | import javafx.beans.value.ObservableValue; 4 | import javafx.scene.control.TableCell; 5 | import javafx.scene.control.TextField; 6 | 7 | /** 8 | * table中列的监听与改变 9 | * 10 | * @author Mirren 11 | * 12 | */ 13 | public class TableAttributeKeyValueTemplateEditingCell extends TableCell { 14 | private TextField textField; 15 | 16 | public TableAttributeKeyValueTemplateEditingCell() { 17 | } 18 | 19 | @Override 20 | public void startEdit() { 21 | if (!isEmpty()) { 22 | super.startEdit(); 23 | createTextField(); 24 | setText(null); 25 | setGraphic(textField); 26 | textField.selectAll(); 27 | } 28 | } 29 | 30 | @Override 31 | public void cancelEdit() { 32 | super.cancelEdit(); 33 | 34 | setText((String) getItem()); 35 | setGraphic(null); 36 | } 37 | 38 | @Override 39 | public void updateItem(String item, boolean empty) { 40 | super.updateItem(item, empty); 41 | 42 | if (empty) { 43 | setText(null); 44 | setGraphic(null); 45 | } else { 46 | if (isEditing()) { 47 | if (textField != null) { 48 | textField.setText(getString()); 49 | } 50 | setText(null); 51 | setGraphic(textField); 52 | } else { 53 | setText(getString()); 54 | setGraphic(null); 55 | } 56 | } 57 | } 58 | 59 | private void createTextField() { 60 | textField = new TextField(getString()); 61 | textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2); 62 | textField.focusedProperty().addListener((ObservableValue arg0, Boolean arg1, Boolean arg2) -> { 63 | if (!arg2) { 64 | commitEdit(textField.getText()); 65 | } 66 | }); 67 | } 68 | 69 | private String getString() { 70 | return getItem() == null ? "" : getItem().toString(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/TableAttributeKeyValueTemplateVO.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | /** 4 | * Table的key与packageName属性 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class TableAttributeKeyValueTemplateVO { 10 | /** key列 */ 11 | private String key; 12 | /** 包名 */ 13 | private String packageName; 14 | /** 类名 */ 15 | private String className; 16 | /** 模板的值 */ 17 | private String templateValue; 18 | 19 | /** 20 | * 初始化 21 | */ 22 | public TableAttributeKeyValueTemplateVO() { 23 | super(); 24 | } 25 | 26 | /** 27 | * 初始化 28 | * 29 | * @param key 30 | * key列的值 31 | * @param packageName 32 | * packageName列的值 33 | * @param className 34 | * 当前列的描述 35 | * @param templateValue 36 | * 模板的值 37 | */ 38 | public TableAttributeKeyValueTemplateVO(String key, String packageName, String className, String templateValue) { 39 | super(); 40 | this.key = key; 41 | this.packageName = packageName; 42 | this.className = className; 43 | this.templateValue = templateValue; 44 | } 45 | 46 | public String getKey() { 47 | return key; 48 | } 49 | 50 | public void setKey(String key) { 51 | this.key = key; 52 | } 53 | 54 | public String getPackageName() { 55 | return packageName; 56 | } 57 | 58 | public void setPackageName(String packageName) { 59 | this.packageName = packageName; 60 | } 61 | 62 | public String getClassName() { 63 | return className; 64 | } 65 | 66 | public void setClassName(String className) { 67 | this.className = className; 68 | } 69 | 70 | public String getTemplateValue() { 71 | return templateValue; 72 | } 73 | 74 | public void setTemplateValue(String templateValue) { 75 | this.templateValue = templateValue; 76 | } 77 | 78 | @Override 79 | public String toString() { 80 | return "TableAttributeKeyValueTemplateClass [key=" + key + ", packageName=" + packageName + ", className=" + className 81 | + ", templateValue=" + templateValue + "]"; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/DatabaseContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | /** 3 | * 数据库配置信息 4 | * 5 | * @author Mirren 6 | * 7 | */ 8 | public class DatabaseContent { 9 | /** 首页显示的名字 */ 10 | private String displayName; 11 | /** 主机地址 */ 12 | private String host; 13 | /** 端口号 */ 14 | private String port; 15 | /** 用户名 */ 16 | private String userName; 17 | /** 密码 */ 18 | private String userPwd; 19 | /** 数据库名称 */ 20 | private String dbName; 21 | /** 数据库类型 */ 22 | private String dbType; 23 | /** 字符编码 */ 24 | private String encoding; 25 | 26 | public String getDisplayName() { 27 | return displayName; 28 | } 29 | 30 | public void setDisplayName(String displayName) { 31 | this.displayName = displayName; 32 | } 33 | 34 | public String getHost() { 35 | return host; 36 | } 37 | 38 | public void setHost(String host) { 39 | this.host = host; 40 | } 41 | 42 | public String getPort() { 43 | return port; 44 | } 45 | 46 | public void setPort(String port) { 47 | this.port = port; 48 | } 49 | 50 | public String getUserName() { 51 | return userName; 52 | } 53 | 54 | public void setUserName(String userName) { 55 | this.userName = userName; 56 | } 57 | 58 | public String getUserPwd() { 59 | return userPwd; 60 | } 61 | 62 | public void setUserPwd(String userPwd) { 63 | this.userPwd = userPwd; 64 | } 65 | 66 | public String getDbName() { 67 | return dbName; 68 | } 69 | 70 | public void setDbName(String dbName) { 71 | this.dbName = dbName; 72 | } 73 | 74 | public String getDbType() { 75 | return dbType; 76 | } 77 | 78 | public void setDbType(String dbType) { 79 | this.dbType = dbType; 80 | } 81 | 82 | public String getEncoding() { 83 | return encoding; 84 | } 85 | 86 | public void setEncoding(String encoding) { 87 | this.encoding = encoding; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return "DatabaseContent [displayName=" + displayName + ", host=" + host + ", port=" + port + ", userName=" + userName + ", userPwd=" 93 | + userPwd + ", dbName=" + dbName + ", dbType=" + dbType + ", encoding=" + encoding + "]"; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/TableAttributeKeyValue.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | 5 | import javafx.beans.property.SimpleStringProperty; 6 | import javafx.beans.property.StringProperty; 7 | 8 | /** 9 | * Table的key与value属性 10 | * 11 | * @author Mirren 12 | * 13 | */ 14 | public class TableAttributeKeyValue { 15 | /** key列 */ 16 | private StringProperty key = new SimpleStringProperty(); 17 | /** value列 */ 18 | private StringProperty value = new SimpleStringProperty(); 19 | /** 描述 */ 20 | private StringProperty describe = new SimpleStringProperty(); 21 | 22 | /** 23 | * 初始化 24 | */ 25 | public TableAttributeKeyValue() { 26 | super(); 27 | } 28 | 29 | /** 30 | * 初始化 31 | * 32 | * @param key 33 | * key列的值 34 | * @param value 35 | * value列的值 36 | * @param describe 37 | * 当前列的描述 38 | */ 39 | public TableAttributeKeyValue(String key, String value, String describe) { 40 | super(); 41 | this.key.setValue(key); 42 | this.value.setValue(value); 43 | this.describe.setValue(describe); 44 | } 45 | 46 | public String getKey() { 47 | return key.getValue(); 48 | } 49 | public void setKey(String key) { 50 | this.key.setValue(key); 51 | } 52 | @JSONField(deserialize = false) 53 | public void setKey(StringProperty key) { 54 | this.key = key; 55 | } 56 | 57 | public String getValue() { 58 | return value.getValue(); 59 | } 60 | 61 | public void setValue(String value) { 62 | this.value.setValue(value); 63 | } 64 | @JSONField(deserialize = false) 65 | public void setValue(StringProperty value) { 66 | this.value = value; 67 | } 68 | 69 | public String getDescribe() { 70 | return describe.getValue(); 71 | } 72 | 73 | public void setDescribe(String describe) { 74 | this.describe.setValue(describe); 75 | } 76 | @JSONField(deserialize = false) 77 | public void setDescribe(StringProperty describe) { 78 | this.describe = describe; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "TableAttributeKeyValue [key=" + key + ", value=" + value + ", describe=" + describe + "]"; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/CreateFileUtil.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.OutputStreamWriter; 6 | import java.io.Writer; 7 | import java.nio.file.Files; 8 | import java.nio.file.Paths; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | import org.apache.log4j.Logger; 13 | 14 | import com.szmirren.entity.GeneratorContent; 15 | 16 | import freemarker.template.Configuration; 17 | import freemarker.template.DefaultObjectWrapper; 18 | import freemarker.template.Template; 19 | /** 20 | * 创建文件的 的工具 21 | * 22 | * @author Mirren 23 | * 24 | */ 25 | public class CreateFileUtil { 26 | private static final Logger LOG = Logger.getLogger(CreateFileUtil.class); 27 | /** 28 | * 执行创建文件 29 | * 30 | * @param content 31 | * 模板所需要的上下文 32 | * @param templeteName 33 | * 模板的名字 示例:Entity.ftl 34 | * @param projectPath 35 | * 生成的项目路径 示例:D://create 36 | * @param packageName 37 | * 包名 示例:com.szmirren 38 | * @param fileName 39 | * 文件名 示例:Entity.java 40 | * @param codeFormat 41 | * 输出的字符编码格式 示例:UTF-8 42 | * @throws Exception 43 | */ 44 | public static void createFile(GeneratorContent content, String templeteName, String projectPath, String packageName, String fileName, 45 | String codeFormat, boolean isOverride) throws Exception { 46 | String outputPath = projectPath + "/" + packageName.replace(".", "/") + "/"; 47 | if (!isOverride) { 48 | if (Files.exists(Paths.get(outputPath + fileName))) { 49 | LOG.debug("设置了文件存在不覆盖,文件已经存在,忽略本文件的创建"); 50 | return; 51 | } 52 | } 53 | Configuration config = new Configuration(Configuration.VERSION_2_3_23); 54 | // 打包成jar包使用的路径 55 | String tempPath = Paths.get(Constant.TEMPLATE_DIR_NAME).toFile().getName(); 56 | // 在项目运行的模板路径 57 | // String tempPath = 58 | // Thread.currentThread().getContextClassLoader().getResource(Constant.TEMPLATE_DIR_NAME).getFile(); 59 | config.setDirectoryForTemplateLoading(new File(tempPath)); 60 | config.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_23)); 61 | config.setDefaultEncoding("utf-8"); 62 | Template template = config.getTemplate(templeteName); 63 | Map item = new HashMap<>(); 64 | item.put("content", content); 65 | if (!Files.exists(Paths.get(outputPath))) { 66 | Files.createDirectories(Paths.get(outputPath)); 67 | } 68 | try (Writer writer = new OutputStreamWriter(new FileOutputStream(outputPath + fileName), codeFormat)) { 69 | template.process(item, writer); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/DatabaseConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | /** 4 | * 数据库连接配置文件 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class DatabaseConfig { 10 | 11 | private String connName; 12 | private String connURL; 13 | private String listenPort; 14 | private String dbName; 15 | private String userName; 16 | private String userPwd; 17 | private String dbType; 18 | private String encoding; 19 | 20 | public String getConnName() { 21 | return connName; 22 | } 23 | 24 | public void setConnName(String connName) { 25 | this.connName = connName; 26 | } 27 | 28 | public String getConnURL() { 29 | return connURL; 30 | } 31 | 32 | public void setConnURL(String connURL) { 33 | this.connURL = connURL; 34 | } 35 | 36 | public String getListenPort() { 37 | return listenPort; 38 | } 39 | 40 | public void setListenPort(String listenPort) { 41 | this.listenPort = listenPort; 42 | } 43 | 44 | public String getDbName() { 45 | return dbName; 46 | } 47 | 48 | public void setDbName(String dbName) { 49 | this.dbName = dbName; 50 | } 51 | 52 | public String getUserName() { 53 | return userName; 54 | } 55 | 56 | public void setUserName(String userName) { 57 | this.userName = userName; 58 | } 59 | 60 | public String getUserPwd() { 61 | return userPwd; 62 | } 63 | 64 | public void setUserPwd(String userPwd) { 65 | this.userPwd = userPwd; 66 | } 67 | 68 | public String getDbType() { 69 | return dbType; 70 | } 71 | 72 | public void setDbType(String dbType) { 73 | this.dbType = dbType; 74 | } 75 | 76 | public String getEncoding() { 77 | return encoding; 78 | } 79 | 80 | public void setEncoding(String encoding) { 81 | this.encoding = encoding; 82 | } 83 | 84 | public DatabaseConfig() { 85 | super(); 86 | } 87 | 88 | public DatabaseConfig(String connName, String connURL, String listenPort, String dbName, String userName, String userPwd, String dbType, String encoding) { 89 | super(); 90 | this.connName = connName; 91 | this.connURL = connURL; 92 | this.listenPort = listenPort; 93 | this.dbName = dbName; 94 | this.userName = userName; 95 | this.userPwd = userPwd; 96 | this.dbType = dbType; 97 | this.encoding = encoding; 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return "DatabaseConfig [connName=" + connName + ", connURL=" + connURL + ", listenPort=" + listenPort + ", dbName=" + dbName + ", userName=" + userName + ", userPwd=" + userPwd + ", dbType=" 103 | + dbType + ", encoding=" + encoding + "]"; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/TemplateUtil.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.net.JarURLConnection; 6 | import java.net.URI; 7 | import java.net.URL; 8 | import java.net.URLConnection; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | import java.nio.file.Paths; 12 | import java.util.Enumeration; 13 | import java.util.jar.JarEntry; 14 | import java.util.jar.JarFile; 15 | 16 | import org.apache.log4j.Logger; 17 | 18 | import com.szmirren.view.AlertUtil; 19 | 20 | /** 21 | * 模板工具 22 | * 23 | * @author Mirren 24 | * 25 | */ 26 | public class TemplateUtil { 27 | private static Logger LOG = Logger.getLogger(TemplateUtil.class); 28 | /** 模板文件夹名称 */ 29 | private static final String TEMPLATE_DIR = Constant.TEMPLATE_DIR_NAME; 30 | 31 | /** 32 | * 查看是否存在模板文件夹,如果不存在则创建 33 | */ 34 | public static void existsTemplate() { 35 | if (Files.notExists(Paths.get(TEMPLATE_DIR))) { 36 | LOG.debug("执行创建模板..."); 37 | try { 38 | Files.createDirectory(Paths.get(TEMPLATE_DIR)); 39 | URL resource = Thread.currentThread().getContextClassLoader().getResource(TEMPLATE_DIR); 40 | URLConnection conn = resource.openConnection(); 41 | if (conn instanceof JarURLConnection) { 42 | LOG.debug("jar"); 43 | jarCreateTemplate((JarURLConnection) conn); 44 | } else { 45 | URI uri = resource.toURI(); 46 | Files.list(Paths.get(uri)).forEach(x -> { 47 | Path out = Paths.get(TEMPLATE_DIR, x.getFileName().toString()); 48 | try { 49 | Files.copy(x, out); 50 | } catch (IOException e) { 51 | LOG.debug("创建模板-->失败:" + e); 52 | AlertUtil.showErrorAlert("创建模板-->失败:" + e); 53 | } 54 | }); 55 | } 56 | 57 | } catch (Exception e) { 58 | LOG.debug("创建模板-->失败:" + e); 59 | AlertUtil.showErrorAlert("创建模板-->失败:" + e); 60 | } 61 | 62 | } 63 | } 64 | 65 | /** 66 | * 将jar里面的文件复制到模板文件夹 67 | * 68 | * @param jarConn 69 | * @return 70 | * @throws IOException 71 | */ 72 | public static void jarCreateTemplate(JarURLConnection jarConn) throws IOException { 73 | try (JarFile jarFile = jarConn.getJarFile()) { 74 | Enumeration entrys = jarFile.entries(); 75 | while (entrys.hasMoreElements()) { 76 | JarEntry entry = entrys.nextElement(); 77 | if (entry.getName().startsWith(jarConn.getEntryName()) && !entry.getName().endsWith("/")) { 78 | String fileName = entry.getName().replace(TEMPLATE_DIR + "/", ""); 79 | InputStream inpt = Thread.currentThread().getContextClassLoader().getResourceAsStream(entry.getName()); 80 | Files.copy(inpt, Paths.get(TEMPLATE_DIR, fileName)); 81 | } 82 | } 83 | } 84 | 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/LanguageUtil.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.net.JarURLConnection; 6 | import java.net.URI; 7 | import java.net.URL; 8 | import java.net.URLConnection; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | import java.nio.file.Paths; 12 | import java.util.Enumeration; 13 | import java.util.jar.JarEntry; 14 | import java.util.jar.JarFile; 15 | 16 | import org.apache.log4j.Logger; 17 | 18 | import com.szmirren.view.AlertUtil; 19 | 20 | /** 21 | * 国际化语言的工具 22 | * 23 | * @author Mirren 24 | * 25 | */ 26 | public class LanguageUtil { 27 | private static Logger LOG = Logger.getLogger(LanguageUtil.class); 28 | /** 模板文件夹名称 */ 29 | private static final String LANGUAGE = "config/" + Constant.LANGUAGE; 30 | 31 | /** 32 | * 查看是否存在模板文件夹,如果不存在则创建 33 | */ 34 | public static void existsTemplate() { 35 | if (Files.notExists(Paths.get(LANGUAGE))) { 36 | LOG.debug("执行创建模板..."); 37 | try { 38 | Files.createDirectory(Paths.get(LANGUAGE)); 39 | URL resource = Thread.currentThread().getContextClassLoader().getResource(LANGUAGE); 40 | URLConnection conn = resource.openConnection(); 41 | if (conn instanceof JarURLConnection) { 42 | LOG.debug("jar"); 43 | jarCreateTemplate((JarURLConnection) conn); 44 | } else { 45 | URI uri = resource.toURI(); 46 | Files.list(Paths.get(uri)).forEach(x -> { 47 | Path out = Paths.get(LANGUAGE, x.getFileName().toString()); 48 | try { 49 | Files.copy(x, out); 50 | } catch (IOException e) { 51 | LOG.debug("创建模板-->失败:" + e); 52 | AlertUtil.showErrorAlert("创建模板-->失败:" + e); 53 | } 54 | }); 55 | } 56 | 57 | } catch (Exception e) { 58 | LOG.debug("创建模板-->失败:" + e); 59 | AlertUtil.showErrorAlert("创建模板-->失败:" + e); 60 | } 61 | 62 | } 63 | } 64 | 65 | /** 66 | * 将jar里面的文件复制到模板文件夹 67 | * 68 | * @param jarConn 69 | * @return 70 | * @throws IOException 71 | */ 72 | public static void jarCreateTemplate(JarURLConnection jarConn) throws IOException { 73 | try (JarFile jarFile = jarConn.getJarFile()) { 74 | Enumeration entrys = jarFile.entries(); 75 | while (entrys.hasMoreElements()) { 76 | JarEntry entry = entrys.nextElement(); 77 | if (entry.getName().startsWith(jarConn.getEntryName()) && !entry.getName().endsWith("/")) { 78 | String fileName = entry.getName().replace(LANGUAGE + "/", ""); 79 | InputStream inpt = Thread.currentThread().getContextClassLoader().getResourceAsStream(entry.getName()); 80 | Files.copy(inpt, Paths.get(LANGUAGE, fileName)); 81 | } 82 | } 83 | } 84 | 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/JDBCType.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | 3 | /** 4 | * jdbc类型 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class JDBCType { 10 | 11 | public static String valiJDBCType(String str) { 12 | /* 13 | * in JDBC enum type have 14 | * 15 | * ARRAY(Types.ARRAY), 16 | * 17 | * BIT(Types.BIT), TINYINT(Types.TINYINT), SMALLINT(Types.SMALLINT), 18 | * INTEGER(Types.INTEGER), 19 | * 20 | * BIGINT(Types.BIGINT), FLOAT(Types.FLOAT), REAL(Types.REAL), 21 | * DOUBLE(Types.DOUBLE), NUMERIC(Types.NUMERIC), 22 | * 23 | * DECIMAL(Types.DECIMAL), CHAR(Types.CHAR), VARCHAR(Types.VARCHAR), 24 | * LONGVARCHAR(Types.LONGVARCHAR), DATE(Types.DATE), 25 | * 26 | * TIME(Types.TIME), TIMESTAMP(Types.TIMESTAMP), BINARY(Types.BINARY), 27 | * VARBINARY(Types.VARBINARY), LONGVARBINARY(Types.LONGVARBINARY), 28 | * 29 | * NULL(Types.NULL), OTHER(Types.OTHER), BLOB(Types.BLOB), 30 | * CLOB(Types.CLOB), BOOLEAN(Types.BOOLEAN), 31 | * 32 | * CURSOR(-10), // Oracle UNDEFINED(Integer.MIN_VALUE + 1000), 33 | * NVARCHAR(Types.NVARCHAR), // JDK6 NCHAR(Types.NCHAR), // JDK6 34 | * NCLOB(Types.NCLOB), // JDK6 35 | * 36 | * STRUCT(Types.STRUCT), JAVA_OBJECT(Types.JAVA_OBJECT), 37 | * DISTINCT(Types.DISTINCT), REF(Types.REF), DATALINK(Types.DATALINK), 38 | * 39 | * ROWID(Types.ROWID), // JDK6 LONGNVARCHAR(Types.LONGNVARCHAR), // JDK6 40 | * SQLXML(Types.SQLXML), // JDK6 DATETIMEOFFSET(-155); // SQL Server 41 | * 2008 42 | * 43 | * 44 | */ 45 | String[] item = { "ARRAY", "BIT", "TINYINT", "SMALLINT", "INTEGER", "BIGINT", "FLOAT", "REAL", "DOUBLE", 46 | "NUMERIC", "DECIMAL", "CHAR", "VARCHAR", "LONGVARCHAR", "DATE", "TIME", "TIMESTAMP", "BINARY", 47 | "VARBINARY", "LONGVARBINARY", "NULL", "OTHER", "BLOB", "CLOB", "BOOLEAN", "CURSOR", "UNDEFINED", 48 | "NVARCHAR", "NCHAR", "NCLOB", "STRUCT", "JAVA_OBJECT", "DISTINCT", "REF", "DATALINK", "ROWID", 49 | "LONGNVARCHAR", "SQLXML", "DATETIMEOFFSET" }; 50 | for (String tmp : item) { 51 | if (str.equals(tmp)) { 52 | return tmp; 53 | } 54 | } 55 | if (str.contains("NUMBER")) { 56 | return "DECIMAL"; 57 | } 58 | if (str.contains("VARCHAR2")) { 59 | return "VARCHAR"; 60 | } 61 | if (str.contains("NVARCHAR2")) { 62 | return "NVARCHAR"; 63 | } 64 | if (str.contains("INT")) { 65 | return "INTEGER"; 66 | } 67 | if (str.contains("DOUBLE")) { 68 | return "DOUBLE"; 69 | } 70 | if (str.contains("FLOAT")) { 71 | return "FLOAT"; 72 | } 73 | if (str.contains("LONG")) { 74 | return "DECIMAL"; 75 | } 76 | if (str.contains("TEXT")) { 77 | return "VARCHAR"; 78 | } 79 | if (str.indexOf("DATETIME") != -1) { 80 | return "DATE"; 81 | } 82 | 83 | return null; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/controller/AboutController.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.controller; 2 | 3 | import java.net.URL; 4 | import java.util.ResourceBundle; 5 | 6 | import com.szmirren.Main; 7 | import com.szmirren.common.LanguageKey; 8 | import com.szmirren.common.SpringGenerator; 9 | 10 | import javafx.fxml.FXML; 11 | import javafx.scene.control.Label; 12 | import javafx.scene.control.TextField; 13 | 14 | /** 15 | * 使用帮助 16 | * 17 | * @author Mirren 18 | * 19 | */ 20 | public class AboutController extends BaseController { 21 | /** 当前版本 */ 22 | @FXML 23 | private Label lblVersion; 24 | /** 当前版本 */ 25 | @FXML 26 | private Label lblNameVersion; 27 | /** 使用说明 */ 28 | @FXML 29 | private Label lblInstructions; 30 | /** 项目地址 */ 31 | @FXML 32 | private Label lblProjectPath; 33 | /** 模板仓库地址 */ 34 | @FXML 35 | private Label lblTemplatePath; 36 | /** QQ交流群 */ 37 | @FXML 38 | private Label lblTalkGroupInQQ; 39 | /** 作者邮箱 */ 40 | @FXML 41 | private Label lblAuthorsEmail; 42 | /** 使用说明 */ 43 | @FXML 44 | private TextField txtInstructions; 45 | /** 项目地址 */ 46 | @FXML 47 | private TextField txtProjectPath; 48 | /** 模板仓库地址 */ 49 | @FXML 50 | private TextField txtTemplatePath; 51 | /** QQ交流群 */ 52 | @FXML 53 | private TextField txtTalkGroupInQQ; 54 | /** 作者邮箱 */ 55 | @FXML 56 | private TextField txtAuthorsEmail; 57 | 58 | @Override 59 | public void initialize(URL arg0, ResourceBundle arg1) { 60 | lblNameVersion.setText(SpringGenerator.NAME_VERSION); 61 | 62 | final int ml = 10;// 左外边距 63 | lblVersion.textProperty().bind(Main.LANGUAGE.get(LanguageKey.INSTRUCTION_LBL_Version)); 64 | lblInstructions.textProperty().bind(Main.LANGUAGE.get(LanguageKey.INSTRUCTION_LBL_INSTRUCTIONS)); 65 | lblInstructions.widthProperty().addListener(w -> txtInstructions.setLayoutX(ml + lblInstructions.getLayoutX() + lblInstructions.getWidth())); 66 | lblProjectPath.textProperty().bind(Main.LANGUAGE.get(LanguageKey.INSTRUCTION_LBL_PROJECT_PATH)); 67 | lblProjectPath.widthProperty().addListener(w -> txtProjectPath.setLayoutX(ml + lblProjectPath.getLayoutX() + lblProjectPath.getWidth())); 68 | lblTemplatePath.textProperty().bind(Main.LANGUAGE.get(LanguageKey.INSTRUCTION_LBL_TEMPLATE_PATH)); 69 | lblTemplatePath.widthProperty().addListener(w -> txtTemplatePath.setLayoutX(ml + lblTemplatePath.getLayoutX() + lblTemplatePath.getWidth())); 70 | lblTalkGroupInQQ.textProperty().bind(Main.LANGUAGE.get(LanguageKey.INSTRUCTION_LBL_TALK_GROUP_IN_QQ)); 71 | lblTalkGroupInQQ.widthProperty().addListener(w -> txtTalkGroupInQQ.setLayoutX(ml + lblTalkGroupInQQ.getLayoutX() + lblTalkGroupInQQ.getWidth())); 72 | lblAuthorsEmail.textProperty().bind(Main.LANGUAGE.get(LanguageKey.INSTRUCTION_LBL_AUTHORS_EMAIL)); 73 | lblAuthorsEmail.widthProperty().addListener(w -> txtAuthorsEmail.setLayoutX(ml + lblAuthorsEmail.getLayoutX() + lblAuthorsEmail.getWidth())); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/resources/FXML/About.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 21 | 26 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 61 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/Main.java: -------------------------------------------------------------------------------- 1 | package com.szmirren; 2 | 3 | import java.net.URL; 4 | import java.util.Enumeration; 5 | import java.util.HashMap; 6 | import java.util.Locale; 7 | import java.util.Map; 8 | import java.util.ResourceBundle; 9 | 10 | import org.apache.log4j.Logger; 11 | import org.apache.log4j.PropertyConfigurator; 12 | 13 | import com.szmirren.common.ConfigUtil; 14 | import com.szmirren.common.SpringGenerator; 15 | import com.szmirren.common.TemplateUtil; 16 | import com.szmirren.controller.IndexController; 17 | 18 | import javafx.application.Application; 19 | import javafx.beans.property.SimpleStringProperty; 20 | import javafx.beans.property.StringProperty; 21 | import javafx.fxml.FXMLLoader; 22 | import javafx.scene.Parent; 23 | import javafx.scene.Scene; 24 | import javafx.scene.image.Image; 25 | import javafx.stage.Stage; 26 | 27 | /** 28 | * 程序的入口 29 | * 30 | * @author Mirren 31 | * 32 | */ 33 | public class Main extends Application { 34 | private static Logger LOG = Logger.getLogger(Main.class.getName()); 35 | /** 国际化控件的文字 */ 36 | public static Map LANGUAGE = new HashMap<>(); 37 | 38 | @Override 39 | public void start(Stage primaryStage) throws Exception { 40 | ConfigUtil.existsConfigDB();// 创建配置文件 41 | // LanguageUtil.existsTemplate();// 国际化文件夹创建 42 | TemplateUtil.existsTemplate();// 创建模板 43 | loadLanguage(Locale.getDefault());// 加载本地语言资源 44 | // loadLanguage(Locale.ENGLISH);// 加载英语资源 45 | 46 | URL url = Thread.currentThread().getContextClassLoader().getResource("FXML/Index.fxml"); 47 | FXMLLoader fxmlLoader = new FXMLLoader(url); 48 | Parent root = fxmlLoader.load(); 49 | primaryStage.setResizable(true); 50 | primaryStage.setTitle(SpringGenerator.NAME_VERSION); 51 | primaryStage.getIcons().add(new Image("image/icon.png")); 52 | primaryStage.setScene(new Scene(root)); 53 | primaryStage.show(); 54 | IndexController controller = fxmlLoader.getController(); 55 | controller.setPrimaryStage(primaryStage); 56 | } 57 | 58 | public static void main(String[] args) { 59 | URL logResource = Thread.currentThread().getContextClassLoader().getResource("config/log4j.properties"); 60 | PropertyConfigurator.configure(logResource); 61 | try { 62 | LOG.debug("运行Spring-Generator..."); 63 | launch(args); 64 | LOG.debug("关闭Spring-Generator!!!"); 65 | } catch (Exception e) { 66 | LOG.error("运行Spring-Generator-->失败:", e); 67 | } 68 | } 69 | 70 | /** 71 | * 根据Locale加载控件文本 72 | * 73 | * @param locale 74 | */ 75 | public static void loadLanguage(Locale locale) { 76 | ResourceBundle resourceBundle = ResourceBundle.getBundle("config/language/language", locale); 77 | Enumeration keys = resourceBundle.getKeys(); 78 | while (keys.hasMoreElements()) { 79 | String key = keys.nextElement(); 80 | if (LANGUAGE.get(key) == null) { 81 | LANGUAGE.put(key, new SimpleStringProperty(resourceBundle.getString(key))); 82 | } else { 83 | LANGUAGE.get(key).set(resourceBundle.getString(key)); 84 | } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/FieldAttribute.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import com.szmirren.models.TableAttributeEntity; 4 | 5 | /** 6 | * 实体类的属性 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class FieldAttribute extends TableColumnsAttribute { 12 | /** 是否创建该属性该属性 */ 13 | private boolean create; 14 | /** 字段 */ 15 | private String field; 16 | /** 字段第一个字母大写 */ 17 | private String fieldPascal; 18 | /** 字段的get方法名,如果变量为boolean 类型为字段的is方法名 */ 19 | private String fget; 20 | /** 字段的set方法名 */ 21 | private String fset; 22 | /** 字段的获取类型的方法名,比如字符串getString */ 23 | private String fgetType; 24 | /** 字段的设置类型的方法名,比如字符串setString */ 25 | private String fsetType; 26 | 27 | /** 28 | * 初始化 29 | */ 30 | public FieldAttribute() { 31 | super(); 32 | } 33 | 34 | /** 35 | * 初始化 36 | */ 37 | public FieldAttribute(TableAttributeEntity entity) { 38 | super(); 39 | super.setJavaType(entity.getTdJavaType().getValue()); 40 | super.setNullable(entity.isNullable()); 41 | super.setColumnName(entity.getTdColumnName()); 42 | super.setColumnDef(entity.getColumnDef()); 43 | super.setRemarks(entity.getRemarks()); 44 | super.setColumnSize(entity.getColumnSize()); 45 | super.setTypeName(entity.getTdJdbcType()); 46 | super.setDecimalDigits(entity.getDecimalDigits()); 47 | super.setOrdinalPosition(entity.getOrdinalPosition()); 48 | this.create = entity.getTdCreate(); 49 | } 50 | 51 | public boolean isCreate() { 52 | return create; 53 | } 54 | 55 | public void setCreate(boolean create) { 56 | this.create = create; 57 | } 58 | 59 | public String getField() { 60 | return field; 61 | } 62 | 63 | public void setField(String field) { 64 | this.field = field; 65 | } 66 | 67 | public String getFieldPascal() { 68 | return fieldPascal; 69 | } 70 | 71 | public void setFieldPascal(String fieldPascal) { 72 | this.fieldPascal = fieldPascal; 73 | } 74 | 75 | public String getFget() { 76 | return fget; 77 | } 78 | 79 | public void setFget(String fget) { 80 | this.fget = fget; 81 | } 82 | 83 | public String getFset() { 84 | return fset; 85 | } 86 | 87 | public void setFset(String fset) { 88 | this.fset = fset; 89 | } 90 | 91 | public String getFgetType() { 92 | return fgetType; 93 | } 94 | 95 | public void setFgetType(String fgetType) { 96 | this.fgetType = fgetType; 97 | } 98 | 99 | public String getFsetType() { 100 | return fsetType; 101 | } 102 | 103 | public void setFsetType(String fsetType) { 104 | this.fsetType = fsetType; 105 | } 106 | 107 | @Override 108 | public String toString() { 109 | return super.toString() + "\nFieldAttribute [create=" + create + ", field=" + field + ", fieldPascal=" + fieldPascal + ", fget=" + fget 110 | + ", fset=" + fset + ", fgetType=" + fgetType + ", fsetType=" + fsetType + "]"; 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/SqlAssistConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.common.Constant; 7 | import com.szmirren.models.TableAttributeKeyValue; 8 | 9 | import javafx.collections.ObservableList; 10 | 11 | /** 12 | * SqlAssist属性的配置文件 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public class SqlAssistConfig { 18 | /** 设置的tableItem */ 19 | private List tableItem = new ArrayList<>(); 20 | /** 生成模板的名字 */ 21 | private String templateName = Constant.TEMPLATE_NAME_SQL_ASSIST; 22 | /** 是否覆盖原文件 */ 23 | private boolean overrideFile; 24 | 25 | /** 26 | * 初始化 27 | */ 28 | public SqlAssistConfig() { 29 | super(); 30 | } 31 | 32 | /** 33 | * 通过 ObservableList初始化 34 | * 35 | * @param tableItem 36 | */ 37 | public SqlAssistConfig(ObservableList item) { 38 | super(); 39 | if (item != null && !item.isEmpty()) { 40 | tableItem.addAll(item); 41 | } 42 | } 43 | 44 | /** 45 | * 通过 ObservableList初始化 46 | * 47 | * @param tableItem 48 | */ 49 | public SqlAssistConfig(ObservableList item, String templateName, boolean overrideFile) { 50 | super(); 51 | if (item != null && !item.isEmpty()) { 52 | tableItem.addAll(item); 53 | } 54 | this.templateName = templateName; 55 | this.overrideFile = overrideFile; 56 | } 57 | 58 | /** 59 | * 初始化默认参数 60 | * 61 | * @return 62 | */ 63 | public SqlAssistConfig initDefaultValue() { 64 | return this; 65 | } 66 | 67 | /** 68 | * 设置属性集合 69 | * 70 | * @return 71 | */ 72 | public List getTableItem() { 73 | return tableItem; 74 | } 75 | 76 | /** 77 | * 获取属性集合 78 | * 79 | * @param tableItem 80 | */ 81 | public void setTableItem(List tableItem) { 82 | this.tableItem = tableItem; 83 | } 84 | 85 | /** 86 | * 获得模板的名称 87 | * 88 | * @return 89 | */ 90 | public String getTemplateName() { 91 | return templateName; 92 | } 93 | 94 | /** 95 | * 设置模板的名称 96 | * 97 | * @param templateName 98 | */ 99 | public void setTemplateName(String templateName) { 100 | this.templateName = templateName; 101 | } 102 | 103 | /** 104 | * 获取是否覆盖原文件 105 | * 106 | * @return 107 | */ 108 | public boolean isOverrideFile() { 109 | return overrideFile; 110 | } 111 | 112 | /** 113 | * 设置是否覆盖原文件 114 | * 115 | * @param overrideFile 116 | */ 117 | public void setOverrideFile(boolean overrideFile) { 118 | this.overrideFile = overrideFile; 119 | } 120 | 121 | @Override 122 | public String toString() { 123 | return "SqlAssistConfig [tableItem=" + tableItem + ", templateName=" + templateName + ", overrideFile=" + overrideFile + "]"; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.szmirren 7 | Spring-generator 8 | 1.0.9 9 | jar 10 | 11 | Spring-generator 12 | http://maven.apache.org 13 | 14 | 15 | UTF-8 16 | 17 | 18 | 19 | 20 | junit 21 | junit 22 | 4.13.1 23 | test 24 | 25 | 26 | 27 | org.slf4j 28 | slf4j-log4j12 29 | 1.7.25 30 | 31 | 32 | 33 | org.xerial 34 | sqlite-jdbc 35 | 3.8.11.2 36 | 37 | 38 | 39 | com.alibaba 40 | fastjson 41 | 1.2.58 42 | 43 | 44 | org.freemarker 45 | freemarker 46 | 2.3.23 47 | 48 | 49 | 50 | 51 | com.jslsolucoes 52 | ojdbc6 53 | 11.2.0.1.0 54 | 55 | 56 | 57 | com.microsoft.sqlserver 58 | mssql-jdbc 59 | 6.4.0.jre8 60 | 61 | 62 | 63 | org.postgresql 64 | postgresql 65 | 42.0.0 66 | 67 | 68 | 69 | mysql 70 | mysql-connector-java 71 | 8.0.16 72 | 73 | 74 | 75 | 76 | 77 | maven-compiler-plugin 78 | 3.1 79 | 80 | 1.8 81 | 1.8 82 | 83 | 84 | 85 | com.zenjava 86 | javafx-maven-plugin 87 | 8.8.3 88 | 89 | com.szmirren.Main 90 | Spring-Generator 91 | false 92 | Spring-Generator.jar 93 | 94 | 95 | 96 | Spring-Generator 97 | 98 | -------------------------------------------------------------------------------- /src/main/resources/template/Entity.ftl: -------------------------------------------------------------------------------- 1 | package ${content.entity.classPackage}; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | /** 6 | * ${content.entity.tableName}实体类 7 | * 8 | * @author 9 | * 10 | */ 11 | public class ${content.entity.className} { 12 | <#list content.entity.attrs as item> 13 | /**${item.remarks!}*/ 14 | private ${item.javaType} ${item.field}; 15 | 16 | /** 17 | * 实例化 18 | */ 19 | public ${content.entity.className!}() { 20 | super(); 21 | } 22 | /** 23 | * 实例化 24 | * 25 | * @param obj 26 | */ 27 | public ${content.entity.className!}(JSONObject obj) { 28 | this(); 29 | <#list content.entity.attrs as item> 30 | <#if item.javaType == "String"> 31 | if (obj.get("${item.field}") instanceof String) { 32 | this.${item.fset}((String) obj.get("${item.field}")); 33 | } 34 | <#elseif item.javaType == "Integer" || item.javaType == "int"> 35 | if (obj.get("${item.field}") instanceof Number) { 36 | this.${item.fset}(((Number) obj.get("${item.field}")).intValue()); 37 | } 38 | <#elseif item.javaType == "Long" || item.javaType == "long"> 39 | if (obj.get("${item.field}") instanceof Number) { 40 | this.${item.fset}(((Number) obj.get("${item.field}")).longValue()); 41 | } 42 | <#elseif item.javaType == "Double" || item.javaType == "double"> 43 | if (obj.get("${item.field}") instanceof Number) { 44 | this.${item.fset}(((Number) obj.get("${item.field}")).doubleValue()); 45 | } 46 | <#elseif item.javaType == "JsonObject"> 47 | if (obj.get("${item.field}") instanceof JsonObject) { 48 | this.${item.fset}((JsonObject) obj.get("${item.field}")); 49 | } 50 | <#else> 51 | this.${item.fset}(obj.get("${item.field}")); 52 | 53 | 54 | } 55 | 56 | /** 57 | * 将当前对象转换为JsonObject 58 | * 59 | * @return 60 | */ 61 | public JSONObject toJson() { 62 | JSONObject result = new JSONObject(); 63 | <#list content.entity.attrs as item> 64 | <#if item.javaType == "int" || item.javaType == "double" || item.javaType == "char" || item.javaType == "long" || item.javaType == "boolean" > 65 | result.put("${item.field}",this.${item.fget}()); 66 | <#else> 67 | if (this.${item.fget}() != null) { 68 | result.put("${item.field}",this.${item.fget}()); 69 | } 70 | 71 | 72 | return result; 73 | } 74 | 75 | <#list content.entity.attrs as item> 76 | 77 | /** 78 | * 获取${item.field} 79 | * 80 | * @return 81 | */ 82 | public ${item.javaType} ${item.fget}() { 83 | return ${item.field}; 84 | } 85 | 86 | /** 87 | * 设置${item.field} 88 | * 89 | * @param ${item.field} 90 | */ 91 | public void ${item.fset}(${item.javaType} ${item.field}) { 92 | this.${item.field} = ${item.field}; 93 | } 94 | 95 | 96 | @Override 97 | public String toString() { 98 | return "${content.entity.className!} [<#list content.entity.attrs as item>${item.field}=" + ${item.field} + " <#if item?has_next>, ]"; 99 | 100 | } 101 | 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/resources/template/UnitTest.ftl: -------------------------------------------------------------------------------- 1 | package ${content.unitTest.classPackage}; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | import org.springframework.test.web.servlet.MockMvc; 10 | import org.springframework.test.web.servlet.ResultActions; 11 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 12 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers; 13 | 14 | /** 15 | * ${content.entity.className}的测试 16 | * 17 | * @author 18 | * 19 | */ 20 | @RunWith(SpringRunner.class) 21 | @SpringBootTest 22 | @AutoConfigureMockMvc 23 | public class ${content.unitTest.className} { 24 | @Autowired 25 | private MockMvc mvc; 26 | 27 | /** 28 | * 单元测试:${content.controller.item.f_find.describe!} 29 | * @throws Exception 30 | */ 31 | @Test 32 | public void ${content.controller.item.f_find.value!}Test() throws Exception { 33 | ResultActions action = mvc.perform(MockMvcRequestBuilders.get("${content.controller.item.r_find.value}")).andExpect(MockMvcResultMatchers.status().isOk()); 34 | // TODO 当你看到这个后你应该自己修改模板编写测试内容规则 35 | } 36 | 37 | <#if content.entity.primaryKeyAttr??> 38 | /** 39 | * 单元测试:${content.controller.item.f_getById.describe!} 40 | * @throws Exception 41 | */ 42 | @Test 43 | public void ${content.controller.item.f_getById.value!}Test() throws Exception { 44 | ResultActions action = mvc.perform(MockMvcRequestBuilders.get("${content.controller.item.r_getById.value}")).andExpect(MockMvcResultMatchers.status().isOk()); 45 | // TODO 当你看到这个后你应该自己修改模板编写测试内容规则 46 | } 47 | 48 | 49 | /** 50 | * 单元测试:${content.controller.item.f_saveNotNull.describe!} 51 | * @throws Exception 52 | */ 53 | @Test 54 | public void ${content.controller.item.f_saveNotNull.value!}Test() throws Exception { 55 | ResultActions action = mvc.perform(MockMvcRequestBuilders.post("${content.controller.item.r_saveNotNull.value}")).andExpect(MockMvcResultMatchers.status().isOk()); 56 | // TODO 当你看到这个后你应该自己修改模板编写测试内容规则 57 | } 58 | 59 | /** 60 | * 单元测试:${content.controller.item.f_updateNotNull.describe!} 61 | * @throws Exception 62 | */ 63 | @Test 64 | public void ${content.controller.item.f_updateNotNull.value!}Test() throws Exception { 65 | ResultActions action = mvc.perform(MockMvcRequestBuilders.put("${content.controller.item.r_updateNotNull.value}")).andExpect(MockMvcResultMatchers.status().isOk()); 66 | // TODO 当你看到这个后你应该自己修改模板编写测试内容规则 67 | } 68 | 69 | <#if content.entity.primaryKeyAttr??> 70 | /** 71 | * 单元测试:${content.controller.item.f_deleteById.describe!} 72 | * @throws Exception 73 | */ 74 | @Test 75 | public void ${content.controller.item.f_deleteById.value!}Test() throws Exception { 76 | ResultActions action = mvc.perform(MockMvcRequestBuilders.delete("${content.controller.item.r_deleteById.value}")).andExpect(MockMvcResultMatchers.status().isOk()); 77 | // TODO 当你看到这个后你应该自己修改模板编写测试内容规则 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/EntityConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.szmirren.common.Constant; 5 | import com.szmirren.models.TableAttributeEntity; 6 | 7 | import javafx.collections.ObservableList; 8 | 9 | /** 10 | * 实体类的配置文件 11 | * 12 | * @author Mirren 13 | * 14 | */ 15 | public class EntityConfig { 16 | /** 生成模板的名字 */ 17 | private String templateName = Constant.TEMPLATE_NAME_ENTITY; 18 | /** 字段使用驼峰命名 */ 19 | private boolean fieldCamel = true; 20 | /** 是否覆盖原文件 */ 21 | private boolean overrideFile = true; 22 | 23 | // -----------------不在保存配置范围的属性----------------------- 24 | /** 存储信息table里面的所有属性 */ 25 | private ObservableList tblPropertyValues; 26 | /** 表的别名 */ 27 | private String tableAlias; 28 | /** 主键名称 */ 29 | private String primaryKey; 30 | 31 | /** 32 | * 实例化 33 | */ 34 | public EntityConfig() { 35 | super(); 36 | } 37 | /** 38 | * 实例化 39 | * 40 | * @param obj 41 | */ 42 | public EntityConfig(JSONObject obj) { 43 | super(); 44 | this.templateName = obj.getString("templateName"); 45 | this.fieldCamel = obj.getBoolean("fieldCamel"); 46 | this.overrideFile = obj.getBoolean("overrideFile"); 47 | } 48 | 49 | /** 50 | * 将对象转换为JSONObject 51 | * 52 | * @return 53 | */ 54 | public JSONObject toJson() { 55 | JSONObject result = new JSONObject(); 56 | result.put("templateName", templateName); 57 | result.put("fieldCamel", fieldCamel); 58 | result.put("overrideFile", overrideFile); 59 | return result; 60 | } 61 | /** 62 | * 将当前对象转换为Json字符串 63 | * 64 | * @return 65 | */ 66 | public String toJsonString() { 67 | return toJson().toJSONString(); 68 | } 69 | 70 | public String getTemplateName() { 71 | return templateName; 72 | } 73 | 74 | public void setTemplateName(String templateName) { 75 | this.templateName = templateName; 76 | } 77 | 78 | public boolean isFieldCamel() { 79 | return fieldCamel; 80 | } 81 | 82 | public void setFieldCamel(boolean fieldCamel) { 83 | this.fieldCamel = fieldCamel; 84 | } 85 | 86 | public boolean isOverrideFile() { 87 | return overrideFile; 88 | } 89 | 90 | public void setOverrideFile(boolean overrideFile) { 91 | this.overrideFile = overrideFile; 92 | } 93 | public ObservableList getTblPropertyValues() { 94 | return tblPropertyValues; 95 | } 96 | public void setTblPropertyValues(ObservableList tblPropertyValues) { 97 | this.tblPropertyValues = tblPropertyValues; 98 | } 99 | public String getTableAlias() { 100 | return tableAlias; 101 | } 102 | public void setTableAlias(String tableAlias) { 103 | this.tableAlias = tableAlias; 104 | } 105 | public String getPrimaryKey() { 106 | return primaryKey; 107 | } 108 | public void setPrimaryKey(String primaryKey) { 109 | this.primaryKey = primaryKey; 110 | } 111 | @Override 112 | public String toString() { 113 | return "EntityConfig [templateName=" + templateName + ", fieldCamel=" + fieldCamel + ", overrideFile=" + overrideFile 114 | + ", tblPropertyValues=" + tblPropertyValues + ", tableAlias=" + tableAlias + ", primaryKey=" + primaryKey + "]"; 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/MapperConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.common.Constant; 7 | import com.szmirren.models.TableAttributeKeyValue; 8 | 9 | import javafx.collections.ObservableList; 10 | 11 | /** 12 | * Sql属性的配置文件 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public class MapperConfig { 18 | /** 设置的tableItem */ 19 | private List tableItem = new ArrayList<>(); 20 | /** 生成模板的名字 */ 21 | private String templateName = Constant.TEMPLATE_NAME_MAPPER; 22 | /** 是否覆盖原文件 */ 23 | private boolean overrideFile = true; 24 | 25 | /** 26 | * 初始化 27 | */ 28 | public MapperConfig() { 29 | super(); 30 | } 31 | 32 | /** 33 | * 通过 ObservableList初始化 34 | * 35 | * @param tableItem 36 | */ 37 | public MapperConfig(ObservableList item) { 38 | super(); 39 | if (item != null && !item.isEmpty()) { 40 | tableItem.addAll(item); 41 | } 42 | } 43 | 44 | /** 45 | * 通过 ObservableList初始化 46 | * 47 | * @param tableItem 48 | */ 49 | public MapperConfig(ObservableList item, String templateName, boolean overrideFile) { 50 | super(); 51 | if (item != null && !item.isEmpty()) { 52 | tableItem.addAll(item); 53 | } 54 | this.templateName = templateName; 55 | this.overrideFile = overrideFile; 56 | } 57 | 58 | /** 59 | * 初始化默认参数 60 | * 61 | * @return 62 | */ 63 | public MapperConfig initDefaultValue() { 64 | tableItem.add(new TableAttributeKeyValue("resultMap", "result_{C}_Map", "返回列")); 65 | tableItem.add(new TableAttributeKeyValue("assist", "assist", "查询辅助工具类,该模块查询时使用")); 66 | tableItem.add(new TableAttributeKeyValue("updateAssist", "updateAssist", "查询辅助工具类,模块用于做修改时使用")); 67 | return this; 68 | } 69 | 70 | /** 71 | * 设置属性集合 72 | * 73 | * @return 74 | */ 75 | public List getTableItem() { 76 | return tableItem; 77 | } 78 | 79 | /** 80 | * 获取属性集合 81 | * 82 | * @param tableItem 83 | */ 84 | public void setTableItem(List tableItem) { 85 | this.tableItem = tableItem; 86 | } 87 | 88 | /** 89 | * 获得模板的名称 90 | * 91 | * @return 92 | */ 93 | public String getTemplateName() { 94 | return templateName; 95 | } 96 | 97 | /** 98 | * 设置模板的名称 99 | * 100 | * @param templateName 101 | */ 102 | public void setTemplateName(String templateName) { 103 | this.templateName = templateName; 104 | } 105 | 106 | /** 107 | * 获取是否覆盖原文件 108 | * 109 | * @return 110 | */ 111 | public boolean isOverrideFile() { 112 | return overrideFile; 113 | } 114 | 115 | /** 116 | * 设置是否覆盖原文件 117 | * 118 | * @param overrideFile 119 | */ 120 | public void setOverrideFile(boolean overrideFile) { 121 | this.overrideFile = overrideFile; 122 | } 123 | 124 | @Override 125 | public String toString() { 126 | return "SqlConfig [tableItem=" + tableItem + ", templateName=" + templateName + ", overrideFile=" + overrideFile + "]"; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/CustomConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.alibaba.fastjson.JSONArray; 7 | import com.alibaba.fastjson.JSONObject; 8 | import com.szmirren.models.TableAttributeKeyValueTemplate; 9 | 10 | import javafx.collections.ObservableList; 11 | 12 | /** 13 | * 自定义包类的配置文件 14 | * 15 | * @author Mirren 16 | * 17 | */ 18 | public class CustomConfig { 19 | /** 设置的tableItem */ 20 | private List tableItem = new ArrayList<>(); 21 | /** 是否覆盖原文件 */ 22 | private boolean overrideFile = true; 23 | 24 | /** 25 | * 初始化 26 | */ 27 | public CustomConfig() { 28 | super(); 29 | } 30 | 31 | /** 32 | * 初始化 33 | * 34 | * @param item 35 | */ 36 | public CustomConfig(ObservableList item) { 37 | super(); 38 | if (item != null && !item.isEmpty()) { 39 | tableItem.addAll(item); 40 | } 41 | } 42 | 43 | /** 44 | * 初始化 45 | * 46 | * @param item 47 | * @param templateName 48 | * @param overrideFile 49 | */ 50 | public CustomConfig(ObservableList item, boolean overrideFile) { 51 | super(); 52 | if (item != null && !item.isEmpty()) { 53 | tableItem.addAll(item); 54 | } 55 | this.overrideFile = overrideFile; 56 | } 57 | 58 | /** 59 | * 初始化 60 | */ 61 | public CustomConfig(JSONObject object) { 62 | super(); 63 | this.overrideFile = object.getBoolean("overrideFile"); 64 | JSONArray array = object.getJSONArray("tableItem"); 65 | if (array != null) { 66 | array.forEach(v -> { 67 | tableItem.add(new TableAttributeKeyValueTemplate((JSONObject) v)); 68 | }); 69 | } 70 | } 71 | 72 | /** 73 | * 通过JSONObject 实例化一个对象 74 | * 75 | * @param object 76 | * @return 77 | */ 78 | public static CustomConfig fromJson(JSONObject object) { 79 | return new CustomConfig(object); 80 | } 81 | 82 | /** 83 | * 将当前对象转换为JSONObject 84 | * 85 | * @return 86 | */ 87 | public JSONObject toJson() { 88 | JSONObject result = new JSONObject(); 89 | result.put("overrideFile", overrideFile); 90 | JSONArray array = new JSONArray(); 91 | tableItem.forEach(v -> { 92 | array.add(v.toJson()); 93 | }); 94 | result.put("tableItem", array); 95 | return result; 96 | } 97 | 98 | /** 99 | * 初始化默认参数 100 | * 101 | * @return 102 | */ 103 | public CustomConfig initDefaultValue() { 104 | return this; 105 | } 106 | 107 | /** 108 | * 将当期对象转换为Json字符串 109 | * 110 | * @return 111 | */ 112 | public String toJsonString() { 113 | return toJson().toJSONString(); 114 | } 115 | 116 | public List getTableItem() { 117 | return tableItem; 118 | } 119 | 120 | public void setTableItem(List tableItem) { 121 | this.tableItem = tableItem; 122 | } 123 | 124 | public boolean isOverrideFile() { 125 | return overrideFile; 126 | } 127 | 128 | public void setOverrideFile(boolean overrideFile) { 129 | this.overrideFile = overrideFile; 130 | } 131 | 132 | @Override 133 | public String toString() { 134 | return "CustomConfig [tableItem=" + tableItem + ", overrideFile=" + overrideFile + "]"; 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/resources/template/Controller.ftl: -------------------------------------------------------------------------------- 1 | package ${content.controller.classPackage}; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.DeleteMapping; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.PutMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import ${content.service.classPackage}.${content.service.className}; 12 | import ${content.entity.classPackage}.${content.entity.className}; 13 | 14 | /** 15 | * ${content.entity.className}的路由接口服务 16 | * 17 | * @author 18 | * 19 | */ 20 | @RestController 21 | public class ${content.controller.className} { 22 | 23 | /** ${content.entity.className}Service服务 */ 24 | @Autowired 25 | private ${content.service.className} ${content.service.className?uncap_first}; 26 | 27 | /** 28 | * ${content.controller.item.f_find.describe!} 29 | * @param value 30 | * @return 31 | */ 32 | @GetMapping(value = "${content.controller.item.r_find.value}", produces = {"application/json;charset=UTF-8"}) 33 | public String ${content.controller.item.f_find.value}(${content.entity.className} value) { 34 | return ${content.service.className?uncap_first}.${content.service.item.select.value}(value); 35 | } 36 | 37 | <#if content.entity.primaryKeyAttr??> 38 | /** 39 | * ${content.controller.item.f_getById.describe!} 40 | * @param id 41 | * @return 42 | */ 43 | @GetMapping(value = "${content.controller.item.r_getById.value}", produces = {"application/json;charset=UTF-8"}) 44 | public String ${content.controller.item.f_getById.value}(@PathVariable(name="id") ${content.entity.primaryKeyAttr.javaType} id) { 45 | return ${content.service.className?uncap_first}.${content.service.item.selectById.value!}(id); 46 | } 47 | 48 | 49 | /** 50 | * ${content.controller.item.f_saveNotNull.describe!} 51 | * @param id 52 | * @return 53 | */ 54 | @PostMapping(value = "${content.controller.item.r_saveNotNull.value!}", produces = {"application/json;charset=UTF-8"}) 55 | public String ${content.controller.item.f_saveNotNull.value!}(${content.entity.className} value) { 56 | return ${content.service.className?uncap_first}.${content.service.item.insertNotNull.value!}(value); 57 | } 58 | 59 | <#if content.entity.primaryKeyAttr??> 60 | /** 61 | * ${content.controller.item.f_updateNotNull.describe!} 62 | * @param id 63 | * @return 64 | */ 65 | @PutMapping(value = "${content.controller.item.r_updateNotNull.value!}", produces = {"application/json;charset=UTF-8"}) 66 | public String ${content.controller.item.f_updateNotNull.value!}(${content.entity.className} value) { 67 | return ${content.service.className?uncap_first}.${content.service.item.updateNotNull.value!}(value); 68 | } 69 | 70 | /** 71 | * ${content.controller.item.f_deleteById.describe!} 72 | * @param id 73 | * @return 74 | */ 75 | @DeleteMapping(value = "${content.controller.item.r_deleteById.value!}", produces = {"application/json;charset=UTF-8"}) 76 | public String ${content.controller.item.f_deleteById.value!}(@PathVariable(name="id") ${content.entity.primaryKeyAttr.javaType} id) { 77 | return ${content.service.className?uncap_first}.${content.service.item.deleteById.value!}(id); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/UnitTestConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.common.Constant; 7 | import com.szmirren.models.TableAttributeKeyValue; 8 | 9 | import javafx.collections.ObservableList; 10 | 11 | /** 12 | * 单元测试属性的配置文件 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public class UnitTestConfig { 18 | /** 设置的tableItem */ 19 | private List tableItem = new ArrayList<>(); 20 | /** 生成模板的名字 */ 21 | private String templateName = Constant.TEMPLATE_NAME_UNIT_TEST; 22 | /** 是否覆盖原文件 */ 23 | private boolean overrideFile = true; 24 | 25 | /** 26 | * 初始化 27 | */ 28 | public UnitTestConfig() { 29 | super(); 30 | } 31 | 32 | /** 33 | * 通过 ObservableList初始化 34 | * 35 | * @param tableItem 36 | */ 37 | public UnitTestConfig(ObservableList item) { 38 | super(); 39 | if (item != null && !item.isEmpty()) { 40 | tableItem.addAll(item); 41 | } 42 | } 43 | 44 | /** 45 | * 通过 ObservableList初始化 46 | * 47 | * @param tableItem 48 | */ 49 | public UnitTestConfig(ObservableList item, String templateName, boolean overrideFile) { 50 | super(); 51 | if (item != null && !item.isEmpty()) { 52 | tableItem.addAll(item); 53 | } 54 | this.templateName = templateName; 55 | this.overrideFile = overrideFile; 56 | } 57 | 58 | /** 59 | * 初始化默认数据 60 | */ 61 | public UnitTestConfig initDefaultValue() { 62 | tableItem.add(new TableAttributeKeyValue("select", "find{C}", "查询所有数据")); 63 | tableItem.add(new TableAttributeKeyValue("selectById", "get{C}ById", "通过id查询数据")); 64 | tableItem.add(new TableAttributeKeyValue("insertNotNull", "saveNotNull{C}", "插入不为空的数据")); 65 | tableItem.add(new TableAttributeKeyValue("updateNotNull", "updateNotNull{C}", "更新不为空的数据")); 66 | tableItem.add(new TableAttributeKeyValue("deleteById", "delete{C}ById", "通过id删除数据")); 67 | return this; 68 | } 69 | 70 | /** 71 | * 设置属性集合 72 | * 73 | * @return 74 | */ 75 | public List getTableItem() { 76 | return tableItem; 77 | } 78 | 79 | /** 80 | * 获取属性集合 81 | * 82 | * @param tableItem 83 | */ 84 | public void setTableItem(List tableItem) { 85 | this.tableItem = tableItem; 86 | } 87 | 88 | /** 89 | * 获得模板的名称 90 | * 91 | * @return 92 | */ 93 | public String getTemplateName() { 94 | return templateName; 95 | } 96 | 97 | /** 98 | * 设置模板的名称 99 | * 100 | * @param templateName 101 | */ 102 | public void setTemplateName(String templateName) { 103 | this.templateName = templateName; 104 | } 105 | 106 | /** 107 | * 获取是否覆盖原文件 108 | * 109 | * @return 110 | */ 111 | public boolean isOverrideFile() { 112 | return overrideFile; 113 | } 114 | 115 | /** 116 | * 设置是否覆盖原文件 117 | * 118 | * @param overrideFile 119 | */ 120 | public void setOverrideFile(boolean overrideFile) { 121 | this.overrideFile = overrideFile; 122 | } 123 | 124 | @Override 125 | public String toString() { 126 | return "UnitTestConfig [tableItem=" + tableItem + ", templateName=" + templateName + ", overrideFile=" + overrideFile + "]"; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/controller/BaseController.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.controller; 2 | 3 | import java.io.IOException; 4 | import java.lang.ref.SoftReference; 5 | import java.net.URL; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import com.szmirren.view.AlertUtil; 10 | 11 | import javafx.fxml.FXMLLoader; 12 | import javafx.fxml.Initializable; 13 | import javafx.scene.Parent; 14 | import javafx.scene.Scene; 15 | import javafx.scene.image.Image; 16 | import javafx.stage.Modality; 17 | import javafx.stage.Stage; 18 | 19 | public abstract class BaseController implements Initializable { 20 | 21 | private Stage primaryStage; 22 | private Stage dialogStage; 23 | 24 | private static Map> cacheNodeMap = new HashMap<>(); 25 | 26 | /** 27 | * 加载一个页面 28 | * 29 | * @param title 30 | * 页面标题 31 | * @param fxmlPage 32 | * 页面FXML路径 33 | * @param cache 34 | * 是否换缓存 35 | * @return 36 | */ 37 | public BaseController loadFXMLPage(String title, FXMLPage fxmlPage, boolean cache) { 38 | return loadFXMLPage(title, fxmlPage, true, cache); 39 | } 40 | 41 | /** 42 | * 加载一个页面 43 | * 44 | * @param title 45 | * 页面标题 46 | * @param fxmlPage 47 | * 页面FXML路径 48 | * @param resize 49 | * 是否可以窗口最大化 50 | * @param cache 51 | * 是否换缓存 52 | * @return 53 | */ 54 | public BaseController loadFXMLPage(String title, FXMLPage fxmlPage, boolean resize, boolean cache) { 55 | SoftReference parentNodeRef = cacheNodeMap.get(fxmlPage); 56 | if (cache && parentNodeRef != null) { 57 | return parentNodeRef.get(); 58 | } 59 | URL skeletonResource = Thread.currentThread().getContextClassLoader().getResource(fxmlPage.getFxml()); 60 | 61 | FXMLLoader loader = new FXMLLoader(skeletonResource); 62 | 63 | Parent loginNode; 64 | try { 65 | loginNode = loader.load(); 66 | BaseController controller = loader.getController(); 67 | dialogStage = new Stage(); 68 | dialogStage.setTitle(title); 69 | dialogStage.getIcons().add(new Image("image/icon.png")); 70 | dialogStage.initModality(Modality.APPLICATION_MODAL); 71 | dialogStage.initOwner(getPrimaryStage()); 72 | dialogStage.setScene(new Scene(loginNode)); 73 | dialogStage.setMaximized(false); 74 | dialogStage.setResizable(resize); 75 | dialogStage.show(); 76 | controller.setDialogStage(dialogStage); 77 | SoftReference softReference = new SoftReference<>(controller); 78 | cacheNodeMap.put(fxmlPage, softReference); 79 | return controller; 80 | } catch (IOException e) { 81 | AlertUtil.showErrorAlert(e.getMessage()); 82 | } 83 | return null; 84 | 85 | } 86 | 87 | public Stage getPrimaryStage() { 88 | return primaryStage; 89 | } 90 | 91 | public void setPrimaryStage(Stage primaryStage) { 92 | this.primaryStage = primaryStage; 93 | } 94 | 95 | public Stage getDialogStage() { 96 | return dialogStage; 97 | } 98 | 99 | public void setDialogStage(Stage dialogStage) { 100 | this.dialogStage = dialogStage; 101 | } 102 | 103 | public void showDialogStage() { 104 | if (dialogStage != null) { 105 | dialogStage.show(); 106 | } 107 | } 108 | 109 | public void closeDialogStage() { 110 | if (dialogStage != null) { 111 | dialogStage.close(); 112 | } 113 | } 114 | 115 | public void closeDialogStageByMap(FXMLPage fxmlPage) { 116 | if (cacheNodeMap.get(fxmlPage).get().getDialogStage() != null) { 117 | cacheNodeMap.get(fxmlPage).get().getDialogStage().close(); 118 | } 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/ServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.common.Constant; 7 | import com.szmirren.models.TableAttributeKeyValue; 8 | 9 | import javafx.collections.ObservableList; 10 | 11 | /** 12 | * Service属性的配置文件 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public class ServiceConfig { 18 | /** 设置的tableItem */ 19 | private List tableItem = new ArrayList<>(); 20 | /** 生成模板的名字 */ 21 | private String templateName = Constant.TEMPLATE_NAME_SERVICE; 22 | /** 是否覆盖原文件 */ 23 | private boolean overrideFile = true; 24 | 25 | /** 26 | * 初始化 27 | */ 28 | public ServiceConfig() { 29 | super(); 30 | } 31 | 32 | /** 33 | * 通过 ObservableList初始化 34 | * 35 | * @param tableItem 36 | */ 37 | public ServiceConfig(ObservableList item) { 38 | super(); 39 | if (item != null && !item.isEmpty()) { 40 | tableItem.addAll(item); 41 | } 42 | } 43 | 44 | /** 45 | * 通过 ObservableList初始化 46 | * 47 | * @param tableItem 48 | */ 49 | public ServiceConfig(ObservableList item, String templateName, boolean overrideFile) { 50 | super(); 51 | if (item != null && !item.isEmpty()) { 52 | tableItem.addAll(item); 53 | } 54 | this.templateName = templateName; 55 | this.overrideFile = overrideFile; 56 | } 57 | 58 | /** 59 | * 初始化默认数据 60 | */ 61 | public ServiceConfig initDefaultValue() { 62 | tableItem.add(new TableAttributeKeyValue("select", "find", "查询所有数据")); 63 | tableItem.add(new TableAttributeKeyValue("selectById", "findOne", "通过id查询数据")); 64 | tableItem.add(new TableAttributeKeyValue("insertNotNull", "saveNotNull", "插入不为空的数据")); 65 | tableItem.add(new TableAttributeKeyValue("updateNotNull", "updateNotNullById", "更新不为空的数据")); 66 | tableItem.add(new TableAttributeKeyValue("updateNotNullByAssist", "updateNotNullByAssist", "Assist更新不为空的数据")); 67 | tableItem.add(new TableAttributeKeyValue("deleteById", "deleteById", "通过id删除数据")); 68 | tableItem.add(new TableAttributeKeyValue("deleteByAssist", "deleteByAssist", "通过Assist删除数据")); 69 | return this; 70 | } 71 | 72 | /** 73 | * 设置属性集合 74 | * 75 | * @return 76 | */ 77 | public List getTableItem() { 78 | return tableItem; 79 | } 80 | 81 | /** 82 | * 获取属性集合 83 | * 84 | * @param tableItem 85 | */ 86 | public void setTableItem(List tableItem) { 87 | this.tableItem = tableItem; 88 | } 89 | 90 | /** 91 | * 获得模板的名称 92 | * 93 | * @return 94 | */ 95 | public String getTemplateName() { 96 | return templateName; 97 | } 98 | 99 | /** 100 | * 设置模板的名称 101 | * 102 | * @param templateName 103 | */ 104 | public void setTemplateName(String templateName) { 105 | this.templateName = templateName; 106 | } 107 | 108 | /** 109 | * 获取是否覆盖原文件 110 | * 111 | * @return 112 | */ 113 | public boolean isOverrideFile() { 114 | return overrideFile; 115 | } 116 | 117 | /** 118 | * 设置是否覆盖原文件 119 | * 120 | * @param overrideFile 121 | */ 122 | public void setOverrideFile(boolean overrideFile) { 123 | this.overrideFile = overrideFile; 124 | } 125 | 126 | @Override 127 | public String toString() { 128 | return "ServiceConfig [tableItem=" + tableItem + ", templateName=" + templateName + ", overrideFile=" + overrideFile + "]"; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/GeneratorContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | /** 4 | * 生成文件的上下文 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class GeneratorContent { 10 | 11 | /** 数据库配置文件 */ 12 | private DatabaseContent database; 13 | /** 实体类配置信息 */ 14 | private EntityContent entity; 15 | /** 数据库表的属性 */ 16 | private TableContent table; 17 | /** 实体类配置信息 */ 18 | private ServiceContent service; 19 | /** 实体类配置信息 */ 20 | private ServiceImplContent serviceImpl; 21 | /** 实体类配置信息 */ 22 | private DaoContent dao; 23 | /** 实体类配置信息 */ 24 | private MapperContent mapper; 25 | /** 实体类配置信息 */ 26 | private ControllerContent controller; 27 | /** 实体类配置信息 */ 28 | private UnitTestContent unitTest; 29 | /** 实体类配置信息 */ 30 | private SqlAssistContent assist; 31 | /** 实体类配置信息 */ 32 | private CustomContent custom; 33 | /** 实体类配置信息 */ 34 | private CustomPropertyContent customProperty; 35 | 36 | public TableContent getTable() { 37 | return table; 38 | } 39 | 40 | public void setTable(TableContent table) { 41 | this.table = table; 42 | } 43 | 44 | public EntityContent getEntity() { 45 | return entity; 46 | } 47 | 48 | public DatabaseContent getDatabase() { 49 | return database; 50 | } 51 | 52 | public void setDatabase(DatabaseContent database) { 53 | this.database = database; 54 | } 55 | 56 | public void setEntity(EntityContent entity) { 57 | this.entity = entity; 58 | } 59 | public ServiceContent getService() { 60 | return service; 61 | } 62 | public void setService(ServiceContent service) { 63 | this.service = service; 64 | } 65 | public ServiceImplContent getServiceImpl() { 66 | return serviceImpl; 67 | } 68 | public void setServiceImpl(ServiceImplContent serviceImpl) { 69 | this.serviceImpl = serviceImpl; 70 | } 71 | 72 | public DaoContent getDao() { 73 | return dao; 74 | } 75 | 76 | public void setDao(DaoContent dao) { 77 | this.dao = dao; 78 | } 79 | 80 | public MapperContent getMapper() { 81 | return mapper; 82 | } 83 | 84 | public void setMapper(MapperContent mapper) { 85 | this.mapper = mapper; 86 | } 87 | 88 | public ControllerContent getController() { 89 | return controller; 90 | } 91 | 92 | public void setController(ControllerContent controller) { 93 | this.controller = controller; 94 | } 95 | 96 | public UnitTestContent getUnitTest() { 97 | return unitTest; 98 | } 99 | 100 | public void setUnitTest(UnitTestContent unitTest) { 101 | this.unitTest = unitTest; 102 | } 103 | 104 | public SqlAssistContent getAssist() { 105 | return assist; 106 | } 107 | 108 | public void setAssist(SqlAssistContent assist) { 109 | this.assist = assist; 110 | } 111 | 112 | public CustomContent getCustom() { 113 | return custom; 114 | } 115 | 116 | public void setCustom(CustomContent custom) { 117 | this.custom = custom; 118 | } 119 | 120 | public CustomPropertyContent getCustomProperty() { 121 | return customProperty; 122 | } 123 | 124 | public void setCustomProperty(CustomPropertyContent customProperty) { 125 | this.customProperty = customProperty; 126 | } 127 | 128 | @Override 129 | public String toString() { 130 | return "GeneratorContent [database=" + database + ", entity=" + entity + ", service=" + service + ", serviceImpl=" + serviceImpl 131 | + ", dao=" + dao + ", mapper=" + mapper + ", controller=" + controller + ", unitTest=" + unitTest + ", assist=" + assist 132 | + ", custom=" + custom + ", customProperty=" + customProperty + "]"; 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/ServiceImplConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.common.Constant; 7 | import com.szmirren.models.TableAttributeKeyValue; 8 | 9 | import javafx.collections.ObservableList; 10 | 11 | /** 12 | * ServiceImpl属性的配置文件 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public class ServiceImplConfig { 18 | /** 设置的tableItem */ 19 | private List tableItem = new ArrayList<>(); 20 | /** 生成模板的名字 */ 21 | private String templateName = Constant.TEMPLATE_NAME_SERVICE_IMPL; 22 | /** 是否覆盖原文件 */ 23 | private boolean overrideFile = true; 24 | 25 | /** 26 | * 初始化 27 | */ 28 | public ServiceImplConfig() { 29 | super(); 30 | } 31 | 32 | /** 33 | * 通过 ObservableList初始化 34 | * 35 | * @param tableItem 36 | */ 37 | public ServiceImplConfig(ObservableList item) { 38 | super(); 39 | if (item != null && !item.isEmpty()) { 40 | tableItem.addAll(item); 41 | } 42 | } 43 | 44 | /** 45 | * 通过 ObservableList初始化 46 | * 47 | * @param tableItem 48 | */ 49 | public ServiceImplConfig(ObservableList item, String templateName, boolean overrideFile) { 50 | super(); 51 | if (item != null && !item.isEmpty()) { 52 | tableItem.addAll(item); 53 | } 54 | this.templateName = templateName; 55 | this.overrideFile = overrideFile; 56 | } 57 | 58 | /** 59 | * 初始化默认数据 60 | */ 61 | public ServiceImplConfig initDefaultValue() { 62 | tableItem.add(new TableAttributeKeyValue("select", "find", "查询所有数据")); 63 | tableItem.add(new TableAttributeKeyValue("selectById", "findOne", "通过id查询数据")); 64 | tableItem.add(new TableAttributeKeyValue("insertNotNull", "saveNotNull", "插入不为空的数据")); 65 | tableItem.add(new TableAttributeKeyValue("updateNotNull", "updateNotNullById", "更新不为空的数据")); 66 | tableItem.add(new TableAttributeKeyValue("updateNotNullByAssist", "updateNotNullByAssist", "Assist更新不为空的数据")); 67 | tableItem.add(new TableAttributeKeyValue("deleteById", "deleteById", "通过id删除数据")); 68 | tableItem.add(new TableAttributeKeyValue("deleteByAssist", "deleteByAssist", "通过Assist删除数据")); 69 | return this; 70 | } 71 | 72 | /** 73 | * 设置属性集合 74 | * 75 | * @return 76 | */ 77 | public List getTableItem() { 78 | return tableItem; 79 | } 80 | 81 | /** 82 | * 获取属性集合 83 | * 84 | * @param tableItem 85 | */ 86 | public void setTableItem(List tableItem) { 87 | this.tableItem = tableItem; 88 | } 89 | 90 | /** 91 | * 获得模板的名称 92 | * 93 | * @return 94 | */ 95 | public String getTemplateName() { 96 | return templateName; 97 | } 98 | 99 | /** 100 | * 设置模板的名称 101 | * 102 | * @param templateName 103 | */ 104 | public void setTemplateName(String templateName) { 105 | this.templateName = templateName; 106 | } 107 | 108 | /** 109 | * 获取是否覆盖原文件 110 | * 111 | * @return 112 | */ 113 | public boolean isOverrideFile() { 114 | return overrideFile; 115 | } 116 | 117 | /** 118 | * 设置是否覆盖原文件 119 | * 120 | * @param overrideFile 121 | */ 122 | public void setOverrideFile(boolean overrideFile) { 123 | this.overrideFile = overrideFile; 124 | } 125 | 126 | @Override 127 | public String toString() { 128 | return "ServiceImplConfig [tableItem=" + tableItem + ", templateName=" + templateName + ", overrideFile=" + overrideFile + "]"; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/TableContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | /** 3 | * 表的属性 4 | * 5 | * @author Mirren 6 | * 7 | */ 8 | public class TableContent { 9 | /** 表类别(可为 null) */ 10 | private String tableCat; 11 | /** 表模式(可为 null) */ 12 | private String tableSchem; 13 | /** 表名称 */ 14 | private String tableName; 15 | /** 16 | * 表类型。典型的类型是 "TABLE"、"VIEW"、"SYSTEM TABLE"、"GLOBAL TEMPORARY"、"LOCAL 17 | * TEMPORARY"、"ALIAS" 和 "SYNONYM 18 | */ 19 | private String tableType; 20 | /** 表的解释性注释 */ 21 | private String remarks; 22 | /** 类型的类别(可为 null) */ 23 | private String typeCat; 24 | /** 类型模式(可为 null) */ 25 | private String typeSchem; 26 | /** 类型名称(可为 null) */ 27 | private String typeName; 28 | /** 有类型表的指定 "identifier" 列的名称(可为 null) */ 29 | private String selfReferencingColName; 30 | /** 31 | * 指定在 SELF_REFERENCING_COL_NAME 中创建值的方式。这些值为 "SYSTEM"、"USER" 和 "DERIVED"。(可能为 32 | * null) 33 | */ 34 | private String refGeneration; 35 | 36 | public TableContent() { 37 | super(); 38 | } 39 | public TableContent(String tableCat, String tableSchem, String tableName, String tableType, String remarks, String typeCat, 40 | String typeSchem, String typeName, String selfReferencingColName, String refGeneration) { 41 | super(); 42 | this.tableCat = tableCat; 43 | this.tableSchem = tableSchem; 44 | this.tableName = tableName; 45 | this.tableType = tableType; 46 | this.remarks = remarks; 47 | this.typeCat = typeCat; 48 | this.typeSchem = typeSchem; 49 | this.typeName = typeName; 50 | this.selfReferencingColName = selfReferencingColName; 51 | this.refGeneration = refGeneration; 52 | } 53 | public String getTableCat() { 54 | return tableCat; 55 | } 56 | public void setTableCat(String tableCat) { 57 | this.tableCat = tableCat; 58 | } 59 | public String getTableSchem() { 60 | return tableSchem; 61 | } 62 | public void setTableSchem(String tableSchem) { 63 | this.tableSchem = tableSchem; 64 | } 65 | public String getTableName() { 66 | return tableName; 67 | } 68 | public void setTableName(String tableName) { 69 | this.tableName = tableName; 70 | } 71 | public String getTableType() { 72 | return tableType; 73 | } 74 | public void setTableType(String tableType) { 75 | this.tableType = tableType; 76 | } 77 | public String getRemarks() { 78 | return remarks; 79 | } 80 | public void setRemarks(String remarks) { 81 | this.remarks = remarks; 82 | } 83 | public String getTypeCat() { 84 | return typeCat; 85 | } 86 | public void setTypeCat(String typeCat) { 87 | this.typeCat = typeCat; 88 | } 89 | public String getTypeSchem() { 90 | return typeSchem; 91 | } 92 | public void setTypeSchem(String typeSchem) { 93 | this.typeSchem = typeSchem; 94 | } 95 | public String getTypeName() { 96 | return typeName; 97 | } 98 | public void setTypeName(String typeName) { 99 | this.typeName = typeName; 100 | } 101 | public String getSelfReferencingColName() { 102 | return selfReferencingColName; 103 | } 104 | public void setSelfReferencingColName(String selfReferencingColName) { 105 | this.selfReferencingColName = selfReferencingColName; 106 | } 107 | public String getRefGeneration() { 108 | return refGeneration; 109 | } 110 | public void setRefGeneration(String refGeneration) { 111 | this.refGeneration = refGeneration; 112 | } 113 | @Override 114 | public String toString() { 115 | return "TableContent [tableCat=" + tableCat + ", tableSchem=" + tableSchem + ", tableName=" + tableName + ", tableType=" + tableType 116 | + ", remarks=" + remarks + ", typeCat=" + typeCat + ", typeSchem=" + typeSchem + ", typeName=" + typeName 117 | + ", selfReferencingColName=" + selfReferencingColName + ", refGeneration=" + refGeneration + "]"; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/JavaType.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | 3 | /** 4 | * java类型 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class JavaType { 10 | 11 | /** 12 | * 将JDBC类型转换为java数据类型 13 | * 14 | * @param str 15 | * @return 16 | */ 17 | public static String jdbcTypeToJavaType(String str) { 18 | if (str == null) { 19 | return ""; 20 | } 21 | 22 | if (isDate(str)) { 23 | return "java.time.Instant"; 24 | } else if (isInteger(str)) { 25 | return "Integer"; 26 | } else if (isLong(str)) { 27 | return "Long"; 28 | } else if (isDouble(str)) { 29 | return "Double"; 30 | } else if (isString(str)) { 31 | return "String"; 32 | } else if (isJson(str)) { 33 | return "JsonObject"; 34 | } else { 35 | return "Object"; 36 | } 37 | } 38 | 39 | /** 40 | * 判断是否为事件 41 | * 42 | * @param str 43 | * @return 44 | */ 45 | public static boolean isDate(String str) { 46 | if (str.equalsIgnoreCase("DATE") || str.equalsIgnoreCase("DATETIME") || str.equalsIgnoreCase("TIMESTAMP") 47 | || str.equalsIgnoreCase("INTERVAL") || str.equalsIgnoreCase("TIME") || str.equalsIgnoreCase("DATETIME2")) { 48 | return true; 49 | } else { 50 | return false; 51 | } 52 | } 53 | 54 | /** 55 | * 判断是否可为String类型 56 | * 57 | * @param str 58 | * @return 59 | */ 60 | public static boolean isString(String str) { 61 | if (str.equalsIgnoreCase("NCHAR") || str.equalsIgnoreCase("CHAR") || str.equalsIgnoreCase("NVARCHAR2") 62 | || str.equalsIgnoreCase("VARCHAR2") || str.equalsIgnoreCase("NVARCHAR") || str.equalsIgnoreCase("VARCHAR") 63 | || str.equalsIgnoreCase("MEDIUMBLOB") || str.equalsIgnoreCase("MEDIUMTEXT") || str.equalsIgnoreCase("CLOB") 64 | || str.equalsIgnoreCase("NCLOB") || str.equalsIgnoreCase("BLOB") || str.equalsIgnoreCase("NBLOB") || str.equalsIgnoreCase("BFILE") 65 | || str.equalsIgnoreCase("XML") || str.equalsIgnoreCase("IMAGE") || str.equalsIgnoreCase("TEXT")) { 66 | return true; 67 | } else { 68 | return false; 69 | } 70 | } 71 | 72 | /** 73 | * 判断类型是否为JSON格式 74 | * 75 | * @param str 76 | * @return 77 | */ 78 | public static boolean isJson(String str) { 79 | if (str.equals("JSON")) { 80 | return true; 81 | } 82 | return false; 83 | } 84 | 85 | /** 86 | * 判断是否为Integer类型 87 | * 88 | * @param str 89 | * @return 90 | */ 91 | public static boolean isInteger(String str) { 92 | if (str.equalsIgnoreCase("NUMBER") || str.equalsIgnoreCase("INTEGER") || str.equalsIgnoreCase("INT") || str.equalsIgnoreCase("TINYINT") 93 | || str.equalsIgnoreCase("SMALLINT") || str.equalsIgnoreCase("BIT") || str.equalsIgnoreCase("Int UNSIGNED") 94 | || str.equalsIgnoreCase("TINYINT UNSIGNED")) { 95 | return true; 96 | } else { 97 | return false; 98 | } 99 | } 100 | 101 | /** 102 | * 判断是否为Long类型 103 | * 104 | * @param str 105 | * @return 106 | */ 107 | public static boolean isLong(String str) { 108 | if (str.equalsIgnoreCase("Long") || str.equalsIgnoreCase("LONG UNSIGNED") || str.equalsIgnoreCase("BIGINT") 109 | || str.equalsIgnoreCase("unsigned") || str.equalsIgnoreCase("BIGINT UNSIGNED")) { 110 | return true; 111 | } else { 112 | return false; 113 | } 114 | } 115 | 116 | /** 117 | * 判断是否为Double类型 118 | * 119 | * @param str 120 | * @return 121 | */ 122 | public static boolean isDouble(String str) { 123 | if (str.equalsIgnoreCase("BINARY_DOUBLE") || str.equalsIgnoreCase("BINARY_FLOAT") || str.equalsIgnoreCase("FLOAT") 124 | || str.equalsIgnoreCase("DECIMAL") || str.equalsIgnoreCase("MONEY") || str.equalsIgnoreCase("NUMERIC") 125 | || str.equalsIgnoreCase("REAL") || str.equalsIgnoreCase("DOUBLE")) { 126 | return true; 127 | } else { 128 | return false; 129 | } 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/ControllerConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.common.Constant; 7 | import com.szmirren.models.TableAttributeKeyValue; 8 | 9 | import javafx.collections.ObservableList; 10 | 11 | /** 12 | * Router属性的配置文件 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public class ControllerConfig { 18 | /** 设置的tableItem */ 19 | private List tableItem = new ArrayList<>(); 20 | /** 生成模板的名字 */ 21 | private String templateName = Constant.TEMPLATE_NAME_ROUTER; 22 | /** 是否覆盖原文件 */ 23 | private boolean overrideFile = true; 24 | 25 | /** 26 | * 初始化 27 | */ 28 | public ControllerConfig() { 29 | super(); 30 | } 31 | 32 | /** 33 | * 通过 ObservableList初始化 34 | * 35 | * @param tableItem 36 | */ 37 | public ControllerConfig(ObservableList item) { 38 | super(); 39 | if (item != null && !item.isEmpty()) { 40 | tableItem.addAll(item); 41 | } 42 | } 43 | 44 | /** 45 | * 通过 ObservableList初始化 46 | * 47 | * @param tableItem 48 | */ 49 | public ControllerConfig(ObservableList item, String templateName, boolean overrideFile) { 50 | super(); 51 | if (item != null && !item.isEmpty()) { 52 | tableItem.addAll(item); 53 | } 54 | this.templateName = templateName; 55 | this.overrideFile = overrideFile; 56 | } 57 | 58 | /** 59 | * 初始化默认数据 60 | */ 61 | public ControllerConfig initDefaultValue() { 62 | tableItem.add(new TableAttributeKeyValue("f_find", "find", "查询所有{C}数据的方法")); 63 | tableItem.add(new TableAttributeKeyValue("f_getById", "findOne", "通过id查询{C}数据的方法")); 64 | tableItem.add(new TableAttributeKeyValue("f_saveNotNull", "save", "插入{C}属性不为空的数据方法")); 65 | tableItem.add(new TableAttributeKeyValue("f_updateNotNull", "update", "更新{C}属性不为空的数据方法")); 66 | tableItem.add(new TableAttributeKeyValue("f_deleteById", "delete", "通过id删除{C}数据方法")); 67 | 68 | tableItem.add(new TableAttributeKeyValue("r_find", "/{C}", "查询所有数据的路由地址")); 69 | tableItem.add(new TableAttributeKeyValue("r_getById", "/{C}/{id}", "通过id查询数据的路由地址")); 70 | tableItem.add(new TableAttributeKeyValue("r_saveNotNull", "/{C}", "插入不为空的数据的路由地址")); 71 | tableItem.add(new TableAttributeKeyValue("r_updateNotNull", "/{C}", "更新不为空的数据的路由地址")); 72 | tableItem.add(new TableAttributeKeyValue("r_deleteById", "/{C}/{id}", "通过id删除数据的路由地址")); 73 | 74 | return this; 75 | } 76 | 77 | /** 78 | * 设置属性集合 79 | * 80 | * @return 81 | */ 82 | public List getTableItem() { 83 | return tableItem; 84 | } 85 | 86 | /** 87 | * 获取属性集合 88 | * 89 | * @param tableItem 90 | */ 91 | public void setTableItem(List tableItem) { 92 | this.tableItem = tableItem; 93 | } 94 | 95 | /** 96 | * 获得模板的名称 97 | * 98 | * @return 99 | */ 100 | public String getTemplateName() { 101 | return templateName; 102 | } 103 | 104 | /** 105 | * 设置模板的名称 106 | * 107 | * @param templateName 108 | */ 109 | public void setTemplateName(String templateName) { 110 | this.templateName = templateName; 111 | } 112 | 113 | /** 114 | * 获取是否覆盖原文件 115 | * 116 | * @return 117 | */ 118 | public boolean isOverrideFile() { 119 | return overrideFile; 120 | } 121 | 122 | /** 123 | * 设置是否覆盖原文件 124 | * 125 | * @param overrideFile 126 | */ 127 | public void setOverrideFile(boolean overrideFile) { 128 | this.overrideFile = overrideFile; 129 | } 130 | 131 | @Override 132 | public String toString() { 133 | return "RouterConfig [tableItem=" + tableItem + ", templateName=" + templateName + ", overrideFile=" + overrideFile + "]"; 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/main/resources/template/Dao.ftl: -------------------------------------------------------------------------------- 1 | package ${content.dao.classPackage}; 2 | import java.util.List; 3 | 4 | import ${content.assist.classPackage}.${content.assist.className}; 5 | import ${content.entity.classPackage}.${content.entity.className}; 6 | 7 | import org.apache.ibatis.annotations.Param; 8 | /** 9 | * ${content.entity.className}的Dao接口 10 | * 11 | * @author 12 | * 13 | */ 14 | public interface ${content.dao.className} { 15 | 16 | /** 17 | * 获得${content.entity.className}数据的总行数,可以通过辅助工具Assist进行条件查询,如果没有条件则传入null 18 | * 19 | * @param assist 20 | * @return 21 | */ 22 | long ${content.dao.item.count.value!}(Assist assist); 23 | 24 | /** 25 | * 获得${content.entity.className}数据集合,可以通过辅助工具Assist进行条件查询,如果没有条件则传入null 26 | * 27 | * @param assist 28 | * @return 29 | */ 30 | List<${content.entity.className}> ${content.dao.item.select.value!}(Assist assist); 31 | <#if content.entity.primaryKeyAttr??> 32 | /** 33 | * 通过${content.entity.className}的id获得${content.entity.className}对象 34 | * 35 | * @param id 36 | * @return 37 | */ 38 | ${content.entity.className} ${content.dao.item.selectById.value!}(${content.entity.primaryKeyAttr.javaType} id); 39 | 40 | 41 | /** 42 | * 获得一个${content.entity.className}对象,以参数${content.entity.className}对象中不为空的属性作为条件进行查询,返回符合条件的第一条 43 | * 44 | * @param obj 45 | * @return 46 | */ 47 | ${content.entity.className} ${content.dao.item.selectByObjSingle.value!}(${content.entity.className} obj); 48 | 49 | /** 50 | * 获得一个${content.entity.className}对象,以参数${content.entity.className}对象中不为空的属性作为条件进行查询 51 | * 52 | * @param obj 53 | * @return 54 | */ 55 | List<${content.entity.className}> ${content.dao.item.selectByObj.value!}(${content.entity.className} obj); 56 | 57 | /** 58 | * 插入${content.entity.className}到数据库,包括null值 59 | * 60 | * @param value 61 | * @return 62 | */ 63 | int ${content.dao.item.insertAll.value!}(${content.entity.className} value); 64 | 65 | /** 66 | * 插入${content.entity.className}中属性值不为null的数据到数据库 67 | * 68 | * @param value 69 | * @return 70 | */ 71 | int ${content.dao.item.insertNotNull.value!}(${content.entity.className} value); 72 | 73 | /** 74 | * 批量插入${content.entity.className}到数据库,包括null值 75 | * 76 | * @param value 77 | * @return 78 | */ 79 | int ${content.dao.item.insertBatch.value!}(List<${content.entity.className}> value); 80 | <#if content.entity.primaryKeyAttr??> 81 | /** 82 | * 通过${content.entity.className}的id删除${content.entity.className} 83 | * 84 | * @param id 85 | * @return 86 | */ 87 | int ${content.dao.item.deleteById.value!}(${content.entity.primaryKeyAttr.javaType} id); 88 | 89 | 90 | /** 91 | * 通过辅助工具Assist的条件删除${content.entity.className} 92 | * 93 | * @param assist 94 | * @return 95 | */ 96 | int ${content.dao.item.deleteByAssist.value!}(Assist assist); 97 | 98 | <#if content.entity.primaryKeyAttr??> 99 | /** 100 | * 通过${content.entity.className}的id更新${content.entity.className}中的数据,包括null值 101 | * 102 | * @param enti 103 | * @return 104 | */ 105 | int ${content.dao.item.updateAllById.value!}(${content.entity.className} enti); 106 | 107 | /** 108 | * 通过${content.entity.className}的id更新${content.entity.className}中属性不为null的数据 109 | * 110 | * @param enti 111 | * @return 112 | */ 113 | int ${content.dao.item.updateNotNullById.value!}(${content.entity.className} enti); 114 | 115 | 116 | /** 117 | * 通过辅助工具Assist的条件更新${content.entity.className}中的数据,包括null值 118 | * 119 | * @param value 120 | * @param assist 121 | * @return 122 | */ 123 | int ${content.dao.item.updateAllByAssist.value!}(@Param("enti") ${content.entity.className} value, @Param("assist") Assist assist); 124 | 125 | /** 126 | * 通过辅助工具Assist的条件更新${content.entity.className}中属性不为null的数据 127 | * 128 | * @param value 129 | * @param assist 130 | * @return 131 | */ 132 | int ${content.dao.item.updateNotNullByAssist.value!}(@Param("enti") ${content.entity.className} value, @Param("assist") Assist assist); 133 | } -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/EntityContent.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | import java.util.List; 4 | 5 | import com.szmirren.common.StrUtil; 6 | 7 | /** 8 | * 实体类的上下文 9 | * 10 | * @author Mirren 11 | * 12 | */ 13 | public class EntityContent { 14 | /** 实体类的包名 */ 15 | private String classPackage; 16 | /** 实体类的名字 */ 17 | private String className; 18 | /** 实体类的名字,首字母小写 */ 19 | private String classNameLower; 20 | /** 数据库表的名字 */ 21 | private String tableName; 22 | /** 表的别名 */ 23 | private String tableAlias; 24 | /** 数据库表的主键名字 */ 25 | private String primaryKey; 26 | /** 数据库表的主键jdbc数据类型 */ 27 | private String primaryKeyJdbcType; 28 | /** 数据库表的主键java数据类型 */ 29 | private String primaryKeyJavaType; 30 | 31 | /** 实体类的属性信息 */ 32 | private List attrs; 33 | 34 | /** 主键属性 */ 35 | private FieldAttribute primaryKeyAttr; 36 | /** 不能为空的属性 */ 37 | private List cantNullAttrs; 38 | /** 其他属性 */ 39 | private List otherAttrs; 40 | 41 | /** 42 | * 初始化 43 | */ 44 | public EntityContent() { 45 | super(); 46 | } 47 | /** 48 | * 初始化 49 | * 50 | * @param classPackage 51 | * 包名 52 | * @param className 53 | * 类名 54 | * @param tableName 55 | * 表名 56 | */ 57 | public EntityContent(String classPackage, String className, String tableName) { 58 | super(); 59 | this.classPackage = classPackage; 60 | this.className = className; 61 | this.classNameLower = StrUtil.fristToLoCase(className); 62 | this.tableName = tableName; 63 | } 64 | 65 | public String getClassPackage() { 66 | return classPackage; 67 | } 68 | public void setClassPackage(String classPackage) { 69 | this.classPackage = classPackage; 70 | } 71 | public String getClassName() { 72 | return className; 73 | } 74 | public void setClassName(String className) { 75 | this.className = className; 76 | this.classNameLower = StrUtil.fristToLoCase(className); 77 | } 78 | public String getClassNameLower() { 79 | return classNameLower; 80 | } 81 | public String getTableName() { 82 | return tableName; 83 | } 84 | public void setTableName(String tableName) { 85 | this.tableName = tableName; 86 | } 87 | public String getTableAlias() { 88 | return tableAlias; 89 | } 90 | public void setTableAlias(String tableAlias) { 91 | this.tableAlias = tableAlias; 92 | } 93 | public String getPrimaryKey() { 94 | return primaryKey; 95 | } 96 | public void setPrimaryKey(String primaryKey) { 97 | this.primaryKey = primaryKey; 98 | } 99 | public List getAttrs() { 100 | return attrs; 101 | } 102 | public void setAttrs(List attrs) { 103 | this.attrs = attrs; 104 | } 105 | public String getPrimaryKeyJdbcType() { 106 | return primaryKeyJdbcType; 107 | } 108 | public void setPrimaryKeyJdbcType(String primaryKeyJdbcType) { 109 | this.primaryKeyJdbcType = primaryKeyJdbcType; 110 | } 111 | public String getPrimaryKeyJavaType() { 112 | return primaryKeyJavaType; 113 | } 114 | public void setPrimaryKeyJavaType(String primaryKeyJavaType) { 115 | this.primaryKeyJavaType = primaryKeyJavaType; 116 | } 117 | 118 | public FieldAttribute getPrimaryKeyAttr() { 119 | return primaryKeyAttr; 120 | } 121 | public void setPrimaryKeyAttr(FieldAttribute primaryKeyAttr) { 122 | this.primaryKeyAttr = primaryKeyAttr; 123 | } 124 | public List getCantNullAttrs() { 125 | return cantNullAttrs; 126 | } 127 | public void setCantNullAttrs(List cantNullAttrs) { 128 | this.cantNullAttrs = cantNullAttrs; 129 | } 130 | public List getOtherAttrs() { 131 | return otherAttrs; 132 | } 133 | public void setOtherAttrs(List otherAttrs) { 134 | this.otherAttrs = otherAttrs; 135 | } 136 | @Override 137 | public String toString() { 138 | return "EntityContent [classPackage=" + classPackage + ", className=" + className + ", classNameLower=" + classNameLower 139 | + ", tableName=" + tableName + ", tableAlias=" + tableAlias + ", primaryKey=" + primaryKey + ", primaryKeyJdbcType=" 140 | + primaryKeyJdbcType + ", primaryKeyJavaType=" + primaryKeyJavaType + ", attrs=" + attrs + "]"; 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/options/DaoConfig.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.options; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.szmirren.common.Constant; 7 | import com.szmirren.models.TableAttributeKeyValue; 8 | 9 | import javafx.collections.ObservableList; 10 | 11 | /** 12 | * Sql属性的配置文件 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public class DaoConfig { 18 | /** 设置的tableItem */ 19 | private List tableItem = new ArrayList<>(); 20 | /** 生成模板的名字 */ 21 | private String templateName = Constant.TEMPLATE_NAME_DAO; 22 | /** 是否覆盖原文件 */ 23 | private boolean overrideFile = true; 24 | 25 | /** 26 | * 初始化 27 | */ 28 | public DaoConfig() { 29 | super(); 30 | } 31 | 32 | /** 33 | * 通过 ObservableList初始化 34 | * 35 | * @param tableItem 36 | */ 37 | public DaoConfig(ObservableList item) { 38 | super(); 39 | if (item != null && !item.isEmpty()) { 40 | tableItem.addAll(item); 41 | } 42 | } 43 | 44 | /** 45 | * 通过 ObservableList初始化 46 | * 47 | * @param tableItem 48 | */ 49 | public DaoConfig(ObservableList item, String templateName, boolean overrideFile) { 50 | super(); 51 | if (item != null && !item.isEmpty()) { 52 | tableItem.addAll(item); 53 | } 54 | this.templateName = templateName; 55 | this.overrideFile = overrideFile; 56 | } 57 | 58 | /** 59 | * 初始化默认参数 60 | * 61 | * @return 62 | */ 63 | public DaoConfig initDefaultValue() { 64 | tableItem.add(new TableAttributeKeyValue("count", "get{C}RowCount", "查询{C}数据总行数,不需要条件时传null")); 65 | tableItem.add(new TableAttributeKeyValue("select", "select{C}", "查询所有{C}数据,不需要条件时传null")); 66 | tableItem.add(new TableAttributeKeyValue("selectById", "select{C}ById", "通过id查询{C}数据")); 67 | tableItem.add(new TableAttributeKeyValue("selectByObjSingle", "select{C}ObjSingle", "通过{C}对象中不为null的属性作为条件,查询出符合条件的第一个{C}数据")); 68 | tableItem.add(new TableAttributeKeyValue("selectByObj", "select{C}ByObj", "通过{C}对象中不为null的属性作为条件,查询出符合条件的所有{C}数据")); 69 | tableItem.add(new TableAttributeKeyValue("insertAll", "insert{C}", "将{C}保存到数据库中,包括null值")); 70 | tableItem.add(new TableAttributeKeyValue("insertNotNull", "insertNotNull{C}", "将{C}中属性不为null的数据保存到数据库中")); 71 | tableItem.add(new TableAttributeKeyValue("insertBatch", "insert{C}ByBatch", "将{C}保存到数据库中,包括null值")); 72 | tableItem.add(new TableAttributeKeyValue("deleteById", "delete{C}ById", "通过id删除{C}数据")); 73 | tableItem.add(new TableAttributeKeyValue("deleteByAssist", "delete{C}ByAssist", "通过Assis删除{C}数据")); 74 | tableItem.add(new TableAttributeKeyValue("updateAllById", "update{C}ById", "更新{C}到数据库中,包括null值,条件为对象中的主键属性")); 75 | tableItem.add(new TableAttributeKeyValue("updateNotNullById", "updateNotNull{C}ById", "更新{C}中属性不为null的数据到数据库中,条件为对象中的主键属性")); 76 | tableItem.add(new TableAttributeKeyValue("updateAllByAssist", "update{C}", "更新{C}到数据库中,包括null值,条件为Assist设置的条件")); 77 | tableItem.add(new TableAttributeKeyValue("updateNotNullByAssist", "updateNotNull{C}", "更新{C}中属性不为null的数据到数据库中,条件为Assist设置的条件")); 78 | return this; 79 | } 80 | 81 | /** 82 | * 设置属性集合 83 | * 84 | * @return 85 | */ 86 | public List getTableItem() { 87 | return tableItem; 88 | } 89 | 90 | /** 91 | * 获取属性集合 92 | * 93 | * @param tableItem 94 | */ 95 | public void setTableItem(List tableItem) { 96 | this.tableItem = tableItem; 97 | } 98 | 99 | /** 100 | * 获得模板的名称 101 | * 102 | * @return 103 | */ 104 | public String getTemplateName() { 105 | return templateName; 106 | } 107 | 108 | /** 109 | * 设置模板的名称 110 | * 111 | * @param templateName 112 | */ 113 | public void setTemplateName(String templateName) { 114 | this.templateName = templateName; 115 | } 116 | 117 | /** 118 | * 获取是否覆盖原文件 119 | * 120 | * @return 121 | */ 122 | public boolean isOverrideFile() { 123 | return overrideFile; 124 | } 125 | 126 | /** 127 | * 设置是否覆盖原文件 128 | * 129 | * @param overrideFile 130 | */ 131 | public void setOverrideFile(boolean overrideFile) { 132 | this.overrideFile = overrideFile; 133 | } 134 | 135 | @Override 136 | public String toString() { 137 | return "SqlConfig [tableItem=" + tableItem + ", templateName=" + templateName + ", overrideFile=" + overrideFile + "]"; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/entity/TableColumnsAttribute.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.entity; 2 | 3 | /** 4 | * 数据库列的属性 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class TableColumnsAttribute implements Comparable { 10 | 11 | // --------------------自定义属性-------------------------------- 12 | /** 字段java的数据类型 */ 13 | private String javaType; 14 | /** 15 | * 是否允许使用 NULL值
16 | * true = 明确允许使用 NULL值
17 | * false = 可能不允许使用 NULL值(不明确是否允许使用NULL值)
18 | */ 19 | private boolean nullable; 20 | 21 | // ----------------java.sql.DatabaseMetaData.getColumns自带的属性---------------------- 22 | /** 列的名称 */ 23 | private String columnName; 24 | /** 默认值 */ 25 | private String columnDef; 26 | /** 描述列的注释 */ 27 | private String remarks; 28 | /** 列的大小,对于 字符串 或 date 类型,列的大小是最大字符数,对于 numeric 和 decimal 类型,列的大小就是精度 */ 29 | private int columnSize; 30 | /** 数据库数据类型名称,对于 UDT,该类型名称是完全限定的 */ 31 | private String typeName; 32 | /** 小数部分的位数 */ 33 | private int decimalDigits; 34 | /** 表中的列的顺序(从 1 开始) */ 35 | private int ordinalPosition; 36 | 37 | /** 38 | * 初始化 39 | */ 40 | public TableColumnsAttribute() { 41 | super(); 42 | } 43 | 44 | /** 45 | * 初始化 46 | * 47 | * @param javaType 48 | * java类型 49 | * @param columnName 50 | * 列的名字 51 | * @param columnDef 52 | * 默认值 53 | * @param remarks 54 | * 备注信息 55 | * @param columnSize 56 | * 列的长度 57 | * @param typeName 58 | * JDBC数据类型 59 | * @param decimalDigits 60 | * 小数点的位数 61 | * @param nullable 62 | * 是否允许为空值,true允许为空值,false不允许为空值(不明确是否允许使用NULL值) 63 | * @param ordinalPosition 64 | * 列在表中的顺序 65 | */ 66 | public TableColumnsAttribute(String javaType, String columnName, String columnDef, String remarks, int columnSize, String typeName, 67 | int decimalDigits, boolean nullable, int ordinalPosition) { 68 | super(); 69 | this.javaType = javaType; 70 | this.columnName = columnName; 71 | this.columnDef = columnDef; 72 | this.remarks = remarks; 73 | this.columnSize = columnSize; 74 | this.typeName = typeName; 75 | this.decimalDigits = decimalDigits; 76 | this.nullable = nullable; 77 | this.ordinalPosition = ordinalPosition; 78 | } 79 | 80 | public String getJavaType() { 81 | return javaType; 82 | } 83 | 84 | public void setJavaType(String javaType) { 85 | this.javaType = javaType; 86 | } 87 | 88 | public String getColumnName() { 89 | return columnName; 90 | } 91 | 92 | public void setColumnName(String columnName) { 93 | this.columnName = columnName; 94 | } 95 | 96 | public String getColumnDef() { 97 | return columnDef; 98 | } 99 | 100 | public void setColumnDef(String columnDef) { 101 | this.columnDef = columnDef; 102 | } 103 | 104 | public String getRemarks() { 105 | return remarks; 106 | } 107 | 108 | public void setRemarks(String remarks) { 109 | this.remarks = remarks; 110 | } 111 | 112 | public int getColumnSize() { 113 | return columnSize; 114 | } 115 | 116 | public void setColumnSize(int columnSize) { 117 | this.columnSize = columnSize; 118 | } 119 | 120 | public String getTypeName() { 121 | return typeName; 122 | } 123 | 124 | public void setTypeName(String typeName) { 125 | this.typeName = typeName; 126 | } 127 | 128 | public int getDecimalDigits() { 129 | return decimalDigits; 130 | } 131 | 132 | public void setDecimalDigits(int decimalDigits) { 133 | this.decimalDigits = decimalDigits; 134 | } 135 | 136 | public boolean isNullable() { 137 | return nullable; 138 | } 139 | 140 | public void setNullable(boolean nullable) { 141 | this.nullable = nullable; 142 | } 143 | 144 | public int getOrdinalPosition() { 145 | return ordinalPosition; 146 | } 147 | 148 | public void setOrdinalPosition(int ordinalPosition) { 149 | this.ordinalPosition = ordinalPosition; 150 | } 151 | 152 | @Override 153 | public String toString() { 154 | return "TableColumnsAttribute [javaType=" + javaType + ", columnName=" + columnName + ", columnDef=" + columnDef + ", remarks=" 155 | + remarks + ", columnSize=" + columnSize + ", typeName=" + typeName + ", decimalDigits=" + decimalDigits + ", nullable=" + nullable 156 | + ", ordinalPosition=" + ordinalPosition + "]"; 157 | } 158 | 159 | @Override 160 | public int compareTo(TableColumnsAttribute obj) { 161 | return ordinalPosition > obj.getOrdinalPosition() ? 1 : (ordinalPosition == obj.getOrdinalPosition() ? 0 : -1); 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /src/main/resources/template/ServiceImpl.ftl: -------------------------------------------------------------------------------- 1 | package ${content.serviceImpl.classPackage}; 2 | import java.util.List; 3 | 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Logger; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.alibaba.fastjson.JSONObject; 10 | import ${content.service.classPackage}.${content.service.className}; 11 | import ${content.dao.classPackage}.${content.dao.className}; 12 | import ${content.assist.classPackage}.${content.assist.className}; 13 | import ${content.entity.classPackage}.${content.entity.className}; 14 | /** 15 | * ${content.entity.className}的服务接口的实现类 16 | * 17 | * @author 18 | * 19 | */ 20 | @Service 21 | public class ${content.serviceImpl.className} implements ${content.service.className} { 22 | private final Logger LOG = LogManager.getLogger(this.getClass()); 23 | 24 | @Autowired 25 | private ${content.dao.className} ${content.dao.className?uncap_first}; 26 | // TODO 当你看到这个方法时你应该创建一个工具类做通用的方法,定义自己的返回格式化 27 | private static final int C200 = 200; 28 | private static final int C412 = 412; 29 | public String resultFormat(int code, Object data) { 30 | JSONObject result = new JSONObject(); 31 | result.put("code", code); 32 | if (data != null) { 33 | result.put("data", data); 34 | } 35 | return result.toJSONString(); 36 | } 37 | 38 | @Override 39 | public String ${content.service.item.select.value!}(${content.entity.className} value) { 40 | //TODO这里可以做通过Assist做添加查询 41 | List<${content.entity.className}> result = ${content.dao.className?uncap_first}.${content.dao.item.select.value!}(null); 42 | if (LOG.isDebugEnabled()) { 43 | LOG.debug("执行获取${content.entity.className}数据集-->结果:", result); 44 | } 45 | return resultFormat(C200, result); 46 | } 47 | <#if content.entity.primaryKeyAttr??> 48 | @Override 49 | public String ${content.service.item.selectById.value!}(${content.entity.primaryKeyAttr.javaType} id) { 50 | if (id == null) { 51 | if (LOG.isDebugEnabled()) { 52 | LOG.debug("执行通过${content.entity.className}的id获得${content.entity.className}对象-->失败:id不能为空"); 53 | } 54 | return resultFormat(C412, null); 55 | } 56 | ${content.entity.className} result = ${content.dao.className?uncap_first}.${content.dao.item.selectById.value!}(id); 57 | if (LOG.isDebugEnabled()) { 58 | LOG.debug("执行通过${content.entity.className}的id获得${content.entity.className}对象-->结果:", result); 59 | } 60 | return resultFormat(C200, result); 61 | } 62 | 63 | 64 | @Override 65 | public String ${content.service.item.insertNotNull.value!}(${content.entity.className} value) { 66 | if (value == null) { 67 | if (LOG.isDebugEnabled()) { 68 | LOG.debug("执行将${content.entity.className}中属性值不为null的数据保存到数据库-->失败:对象不能为空"); 69 | } 70 | return resultFormat(C412, null); 71 | } 72 | <#if content.entity.cantNullAttrs?exists> 73 | if(<#list content.entity.cantNullAttrs as item>value.${item.fget}() == null <#if item?has_next>|| ){ 74 | if (LOG.isDebugEnabled()) { 75 | LOG.debug("执行将${content.entity.className}中属性值不为null的数据保存到数据库-->失败:存在不能为空的空值"); 76 | } 77 | return resultFormat(C412, null); 78 | } 79 | 80 | int result = ${content.dao.className?uncap_first}.${content.dao.item.insertNotNull.value!}(value); 81 | if (LOG.isDebugEnabled()) { 82 | LOG.debug("执行将${content.entity.className}中属性值不为null的数据保存到数据库-->结果:", result); 83 | } 84 | return resultFormat(C200, result); 85 | } 86 | <#if content.entity.primaryKeyAttr??> 87 | @Override 88 | public String ${content.service.item.updateNotNull.value!}(${content.entity.className} value) { 89 | if (value == null) { 90 | if (LOG.isDebugEnabled()) { 91 | LOG.debug("执行通过${content.entity.className}的id更新${content.entity.className}中属性不为null的数据-->失败:对象为null"); 92 | } 93 | return resultFormat(C412, null); 94 | } 95 | int result = ${content.dao.className?uncap_first}.${content.dao.item.updateNotNullById.value!}(value); 96 | if (LOG.isDebugEnabled()) { 97 | LOG.debug("执行通过${content.entity.className}的id更新${content.entity.className}中属性不为null的数据-->结果:", result); 98 | } 99 | return resultFormat(C200, result); 100 | } 101 | 102 | @Override 103 | public String ${content.service.item.deleteById.value!}(${content.entity.primaryKeyAttr.javaType} id) { 104 | if (id == null) { 105 | if (LOG.isDebugEnabled()) { 106 | LOG.debug("执行通过${content.entity.className}的id删除${content.entity.className}-->失败:id不能为空"); 107 | } 108 | return resultFormat(C412, null); 109 | } 110 | int result = ${content.dao.className?uncap_first}.${content.dao.item.deleteById.value!}(id); 111 | if (LOG.isDebugEnabled()) { 112 | LOG.debug("执行通过${content.entity.className}的id删除${content.entity.className}-->结果:", result); 113 | } 114 | return resultFormat(C200, result); 115 | } 116 | 117 | 118 | 119 | } -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/StrUtil.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 字符串工具 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class StrUtil { 12 | 13 | /** 14 | * 去掉下划线并将字符串转换成帕斯卡命名规范 15 | * 16 | * @param str 17 | * @return 18 | */ 19 | public static String unlineToPascal(String str) { 20 | if (str != null) { 21 | if (str.indexOf("_") == -1) { 22 | return fristToUpCase(str); 23 | } 24 | StringBuilder result = new StringBuilder(); 25 | String[] temp = str.split("_"); 26 | for (int i = 0; i < temp.length; i++) { 27 | if (temp[i].equals("") || temp[i].isEmpty()) { 28 | continue; 29 | } 30 | result.append(fristToUpCaseLaterToLoCase(temp[i])); 31 | } 32 | return result.toString(); 33 | } 34 | 35 | return str; 36 | } 37 | 38 | /** 39 | * 去掉下划线并将字符串转换成驼峰命名规范 40 | * 41 | * @param str 42 | * @return 43 | */ 44 | public static String unlineToCamel(String str) { 45 | if (str != null) { 46 | if (str.indexOf("_") == -1) { 47 | return fristToLoCase(str); 48 | } 49 | StringBuilder result = new StringBuilder(); 50 | String[] temp = str.split("_"); 51 | boolean falg = false; 52 | for (int i = 0; i < temp.length; i++) { 53 | if (temp[i].equals("") || temp[i].isEmpty()) { 54 | continue; 55 | } 56 | if (falg == false) { 57 | falg = true; 58 | result.append(temp[i].toLowerCase()); 59 | } else { 60 | result.append(fristToUpCaseLaterToLoCase(temp[i])); 61 | } 62 | } 63 | return result.toString(); 64 | } 65 | 66 | return str; 67 | } 68 | 69 | /** 70 | * 将字符串首字母大写其后小写 71 | * 72 | * @param str 73 | * @return 74 | */ 75 | public static String fristToUpCaseLaterToLoCase(String str) { 76 | if (str != null && str.length() > 0) { 77 | str = (str.substring(0, 1).toUpperCase()) + (str.substring(1).toLowerCase()); 78 | } 79 | return str; 80 | } 81 | 82 | /** 83 | * 将字符串首字母小写其后大写 84 | * 85 | * @param str 86 | * @return 87 | */ 88 | public static String fristToLoCaseLaterToUpCase(String str) { 89 | if (str != null && str.length() > 0) { 90 | str = (str.substring(0, 1).toLowerCase()) + (str.substring(1).toUpperCase()); 91 | 92 | } 93 | return str; 94 | } 95 | 96 | /** 97 | * 将字符串首字母大写 98 | * 99 | * @param str 100 | * @return 101 | */ 102 | public static String fristToUpCase(String str) { 103 | if (str != null && str.length() > 0) { 104 | str = str.substring(0, 1).toUpperCase() + str.substring(1); 105 | } 106 | return str; 107 | } 108 | 109 | /** 110 | * 将字符串首字母小写 111 | * 112 | * @param str 113 | * @return 114 | */ 115 | public static String fristToLoCase(String str) { 116 | if (str != null && str.length() > 0) { 117 | str = str.substring(0, 1).toLowerCase() + str.substring(1); 118 | } 119 | return str; 120 | } 121 | 122 | /** 123 | * 检查字符串里面是否包含指定字符,包含返回true 124 | * 125 | * @param regex 126 | * 指定字符 127 | * @param str 128 | * 字符串 129 | * @return 130 | */ 131 | public static boolean indexOf(String regex, String... str) { 132 | if (str == null) { 133 | return false; 134 | } 135 | for (String temp : str) { 136 | if (temp.indexOf(regex) == -1) { 137 | return false; 138 | } 139 | } 140 | return true; 141 | } 142 | 143 | /** 144 | * 如果jdk大于1.8可以直接使用String.join
145 | * 将字符串中间以separator连接起来
146 | * 示例:magre(".","1","2","3") 结果:"1.2.3" 147 | * 148 | * @param separator 149 | * @param str 150 | * @return 151 | */ 152 | @Deprecated() 153 | public static String magre(String separator, String... str) { 154 | StringBuffer result = null; 155 | for (String temp : str) { 156 | if (result == null) { 157 | result = new StringBuffer(temp); 158 | } 159 | result.append("," + temp); 160 | } 161 | return result.toString(); 162 | } 163 | 164 | /** 165 | * 将字符串str中带有集合中rep[0]的字符串,代替为rep[1]的中的字符串 166 | * 167 | * @param str 168 | * @param rep 169 | * @return 170 | */ 171 | public static String replace(String str, List rep) { 172 | for (String[] item : rep) { 173 | if (item[1] == null) { 174 | item[1] = ""; 175 | } 176 | str = str.replace(item[0], item[1]); 177 | } 178 | return str; 179 | } 180 | 181 | /** 182 | * 创建字符串数组 183 | * 184 | * @param str 185 | * @return 186 | */ 187 | public static String[] asStrArray(String... str) { 188 | return str; 189 | } 190 | 191 | /** 192 | * 判断字符串是否为null或者空,如果是返回true 193 | * 194 | * @param str 195 | * @return 196 | */ 197 | public static boolean isNullOrEmpty(String str) { 198 | if (str == null || "".equals(str.trim())) { 199 | return true; 200 | } 201 | return false; 202 | } 203 | 204 | /** 205 | * 判断字符串是否为null或者空,如果是返回true 206 | * 207 | * @param str 208 | * @return 209 | */ 210 | public static boolean isNullOrEmpty(String... str) { 211 | for (int i = 0; i < str.length; i++) { 212 | if (str[i] == null || "".equals(str[i].trim())) { 213 | return true; 214 | } 215 | } 216 | return false; 217 | } 218 | 219 | } 220 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/common/IoUtil.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.common; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.io.OutputStreamWriter; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.nio.file.StandardOpenOption; 11 | 12 | /** 13 | * io工具类用于操作io相关 14 | * 15 | * @author duhua 16 | * 17 | */ 18 | public class IoUtil { 19 | /** 20 | * 将字符串存储为文件 21 | * 22 | * @param path 23 | * @param materi 24 | * @param codeFormat 25 | * @throws Exception 26 | */ 27 | public static void StrToFile(Path path, String materi, String codeFormat) throws Exception { 28 | OutputStream out = Files.newOutputStream(path, StandardOpenOption.CREATE); 29 | OutputStreamWriter writer = new OutputStreamWriter(out, codeFormat); 30 | writer.write(materi); 31 | writer.flush(); 32 | out.close(); 33 | writer.close(); 34 | } 35 | 36 | /** 37 | * 将字符串存储为文件 38 | * 39 | * @param dir 40 | * 目录 41 | * @param fileName 42 | * 文件名称 43 | * @param materi 44 | * 字符串内容 45 | * @param codeFormat 46 | * 字符编码方式 47 | * @throws Exception 48 | */ 49 | public static void StrToFile(Path dir, String fileName, String materi, String codeFormat) throws Exception { 50 | if (!isExists(dir)) { 51 | createDir(dir); 52 | } 53 | Path path = Paths.get(dir.toString(), fileName); 54 | OutputStream out = Files.newOutputStream(path, StandardOpenOption.CREATE); 55 | OutputStreamWriter writer = new OutputStreamWriter(out, codeFormat); 56 | writer.write(materi); 57 | writer.flush(); 58 | out.close(); 59 | writer.close(); 60 | } 61 | 62 | /** 63 | * 将字符串存储为文件,如果源文件存并且mode==true在则删除 64 | * 65 | * @param dir 66 | * 目录 67 | * @param fileName 68 | * 文件名称 69 | * @param materi 70 | * 字符串内容 71 | * @param codeFormat 72 | * 字符编码方式 73 | * @param mode 74 | * true删除原文件 75 | * @throws Exception 76 | */ 77 | public static void StrToFile(Path dir, String fileName, String materi, String codeFormat, boolean mode) 78 | throws Exception { 79 | if (mode) { 80 | Path path = Paths.get(dir.toString(), fileName); 81 | if (Files.exists(path)) { 82 | Files.delete(path); 83 | } 84 | } 85 | StrToFile(dir, fileName, materi, codeFormat); 86 | } 87 | 88 | /** 89 | * 通过读取文件并转换为utf-8的字符串 90 | * 91 | * @param path 92 | * @return 93 | * @throws Exception 94 | */ 95 | public static String fileToStr(String path) throws Exception { 96 | return fileToStr(path, "UTF-8"); 97 | } 98 | 99 | /** 100 | * 通过读取文件并转换为字符串 101 | * 102 | * @param path 103 | * 文件地址 104 | * @param charset 105 | * 字符编码 106 | * @return 107 | * @throws Exception 108 | */ 109 | public static String fileToStr(String path, String charset) throws Exception { 110 | Path uri = Paths.get(path); 111 | InputStream fis = Files.newInputStream(uri); 112 | int size = fis.available(); 113 | byte[] buffer = new byte[size]; 114 | fis.read(buffer); 115 | if (fis != null) { 116 | fis.close(); 117 | } 118 | return new String(buffer, charset); 119 | } 120 | 121 | /** 122 | * 判断文件或文件夹是否存在 123 | * 124 | * @param path 125 | * @return 126 | */ 127 | public static boolean isExists(String path) { 128 | return Files.exists(Paths.get(path)); 129 | } 130 | 131 | /** 132 | * 判断文件夹是否存在 133 | * 134 | * @param path 135 | * @return 136 | */ 137 | public static boolean isExists(Path path) { 138 | return Files.exists(path); 139 | } 140 | 141 | /** 142 | * 判断文件或文件夹是否存在 143 | * 144 | * @param path 145 | * @return 146 | */ 147 | public static boolean isExists(Path dir, String fileName) { 148 | return Files.exists(Paths.get(dir.toString(), fileName)); 149 | } 150 | 151 | /** 152 | * 创建文件夹 153 | * 154 | * @param dir 155 | * @return 156 | * @throws IOException 157 | */ 158 | public static Path createDir(String dir) throws IOException { 159 | return Files.createDirectories(Paths.get(dir)); 160 | } 161 | 162 | /** 163 | * 创建文件夹 164 | * 165 | * @param dir 166 | * @return 167 | * @throws IOException 168 | */ 169 | public static Path createDir(Path path) throws IOException { 170 | return Files.createDirectories(path); 171 | } 172 | 173 | /** 174 | * 将字符串装换成路径 175 | * 176 | * @param str 177 | * @return 178 | */ 179 | public static String toURL(String str) { 180 | if (StrUtil.isNullOrEmpty(str)) { 181 | return ""; 182 | } 183 | String result = str.replace(".", "/"); 184 | return result; 185 | } 186 | 187 | /** 188 | * 将字符串装换成路径 189 | * 190 | * @param str 191 | * @return 192 | */ 193 | public static String toURL(String... str) { 194 | if (StrUtil.isNullOrEmpty(str)) { 195 | return ""; 196 | } 197 | StringBuffer result = new StringBuffer(); 198 | for (String temp : str) { 199 | result.append(toURL(temp)); 200 | } 201 | return result.toString(); 202 | } 203 | 204 | } 205 | -------------------------------------------------------------------------------- /src/main/resources/config/language/language_en.properties: -------------------------------------------------------------------------------- 1 | page.createConnection=Create DataBase Connection 2 | page.updateConnection=Update DataBase Connection 3 | common.btnSet=Set 4 | tips.pathCantEmpty=The generated path cannot be empty 5 | historyConfig.tableTips=No configuration information has been added, the configuration can be saved through the home page 6 | index.lblConnection=Connection 7 | index.lblConfig=Configuration 8 | index.lblInstructions=Instructions 9 | index.lblSetting=Setting 10 | instruction.lblVersion=Version : 11 | instruction.lblInstructions=Instructions : 12 | instruction.lblProjectPath=ProjectPath : 13 | instruction.lblTemplatePath=TemplatePath : 14 | instruction.lblTalkGroupInQQ=TalkGroupInQQ : 15 | instruction.lblAuthorsEmail=AuthorsEmail : 16 | setting.lblLanguage=Language : 17 | index.lblProjectPath=GeneratePath: 18 | index.txtProjectPath=Input or choose generate directory,for example: E:/temp-vertx 19 | index.btnSelectFile=Select 20 | index.lblTableName=TableName: 21 | index.txtTableName=Double click the left database table name to load 22 | index.lblEntityPackage=EntityPackage: 23 | index.lblServicePackage=ServiceImplPackage: 24 | index.lblServiceImplPackage=ServiceImplPackage: 25 | index.lblRouterPackage=ControllerPackage: 26 | index.lblSqlPackage=DaoPackage: 27 | index.lblAssistPackage=AssistPackage: 28 | index.lblAbstractSqlPackage=AbstractSqlPackage: 29 | index.lblSqlParamsPackage=MapperPackage: 30 | index.lblUnitTestPackage=UnitTestPackage: 31 | index.lblEntityName=EntityName: 32 | index.lblServiceName=ServiceImplName: 33 | index.lblServiceImplName=ServiceImplName: 34 | index.lblRouterName=ControllerName: 35 | index.lblSqlName=DaoName: 36 | index.lblAssistName=AssistName: 37 | index.lblAbstractSqlName=AbstractSqlName: 38 | index.lblSqlParamsName=MapperName: 39 | index.lblUnitTestName=UnitTestName: 40 | index.runCreateTipsText=generating 41 | index.lblSetCustom=CustomPackageClass: 42 | index.lblSetCustomProperty=CustomProperty: 43 | index.lblCodeFormat=FileCodeFormat: 44 | index.btnRunCreate=RunCreate 45 | index.btnSaveConfig=SaveConfig 46 | index.tvmiOpenConnect=OpenConnect 47 | index.tvmiCloseConnect=CloseConnect 48 | index.tvmiUpdateConnect=UpdateConnect 49 | index.tvmiDeleteConnect=DeleteConnect 50 | index.tvmiCreateFullDB=CreateFullDataBase 51 | index.saveConfigTips=Please input the configuration name: \r\n (the name of the table is not stored in the scope, it must be loaded through the database) 52 | index.saveConfigNotCTips=All class names must contain placeholders for replacing table names: {c} 53 | index.selectTableTips=Please select the database table ! Open the left database and double-click the table name to load... 54 | index.createTableTips=Please double-click the left side data to select the table you want to generate, or to generate the entire database on the left side. 55 | 56 | conn.lblConnName=ConnectName: 57 | conn.lblConnURL=ConnectURL: 58 | conn.lblListenPort=ListenPort: 59 | conn.lblDBType=DatabaseType: 60 | conn.lblDBName=DatabaseName: 61 | conn.lblUserName=UserName: 62 | conn.lblUserPwd=UserPwd: 63 | conn.lblDBCoding=DatabaseCode: 64 | conn.txtConnName=Custom display name 65 | conn.txtConnURL=Connect URL example:127.0.0.1 / localhost 66 | conn.txtListenPort=ListenPortNumberExample: 1521 67 | conn.cboDBType=InputOrSelectDatabaseType 68 | conn.txtDBName=DatabaseName 69 | conn.txtUserName=UserName 70 | conn.txtUserPwd=UserPwd 71 | conn.cboDBCoding=DatabaseCodeFormat 72 | conn.btnTestConn=TestConnect 73 | conn.btnSave=Save 74 | conn.btnCancel=Cancel 75 | 76 | config.lblTips=Warm reminder: when the system starts, it will load the default configuration file by default. If it is a common configuration, you can store the name as default. 77 | config.tdInfo=ConfigurationName 78 | config.tdOperation=Operation 79 | config.btnLoad=LoadConfig 80 | config.btnDelete=DeleteConfig 81 | 82 | setEntity.tdcreate=IsCreate 83 | setEntity.tdColumn=ColumnName 84 | setEntity.tdSqlType=SqlType 85 | setEntity.tdJavaType=JavaType 86 | setEntity.tdField=Field 87 | setEntity.lblTableAlias=TableAlias : 88 | setEntity.txtTableAlias=Input custom table alias 89 | setEntity.lblPrimaryKey=PrimaryKey : 90 | setEntity.txtPrimaryKey=No primary key 91 | setEntity.lblKey=Type : 92 | setEntity.txtKey=Example : Animal 93 | setEntity.lblValue=Name : 94 | setEntity.txtValue=Example : dog 95 | setEntity.chkFieldCamel=Field camel naming 96 | 97 | set.tblTips=You can customize the added property on the right... 98 | set.tdDescribe=describe 99 | set.lblTips=Tip: if you need the entity class name, you can use {c}, for example: insert{c} if the class name is User, the result is: insertUser, {C}=User, {c}=user 100 | set.btnSaveConfig=SaveConfig 101 | set.lblAddCustomProperty=Add custom properties: 102 | set.lblDescribe=Desc : 103 | set.txtKey=Input the Key 104 | set.txtValue=Input the value 105 | set.txtDescribe=Input the describe 106 | set.btnAddProperty=AddProperty 107 | set.lblTemplate=Use the template: 108 | set.cboTemplate=Select or input the template name 109 | set.btnConfirm=Confirm 110 | set.btnCancel=Cancel 111 | set.btnCancelTips=If cancel they will revert to the default value, Do you want to cancel? 112 | set.chkOverrideFile=If the file exists override 113 | set.abstractAutomatic=Automatic selection by DB type 114 | set.tblMenuItemDelete= Delete this property 115 | set.tblMenuItemDeleteConfirm= Do you want to delete this property 116 | set.commonPackageName = PackageName 117 | set.commonClassName = ClassName 118 | set.commonSuffix = suffix 119 | set.commonTemplateName= TemplateName 120 | set.lblPackageName = Pname: 121 | set.lblClassName = Cname: 122 | set.txtPackageName = Input package name 123 | set.txtClassName = Input class name 124 | 125 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/TableAttributeKeyValueTemplate.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | import javafx.beans.property.SimpleStringProperty; 6 | import javafx.beans.property.StringProperty; 7 | import javafx.scene.control.ComboBox; 8 | 9 | /** 10 | * Table的key与packageName属性 11 | * 12 | * @author Mirren 13 | * 14 | */ 15 | public class TableAttributeKeyValueTemplate { 16 | /** key列 */ 17 | private StringProperty key = new SimpleStringProperty(); 18 | /** 包名 */ 19 | private StringProperty packageName = new SimpleStringProperty(); 20 | /** 类名 */ 21 | private StringProperty className = new SimpleStringProperty(); 22 | /** 后缀名 */ 23 | private StringProperty suffix = new SimpleStringProperty(".java"); 24 | /** 模板 */ 25 | private ComboBox template; 26 | /** 模板的值 */ 27 | private String templateValue; 28 | 29 | /** 30 | * 初始化 31 | */ 32 | public TableAttributeKeyValueTemplate() { 33 | super(); 34 | } 35 | 36 | /** 37 | * 初始化 38 | * 39 | * @param key 40 | * key列的值 41 | * @param packageName 42 | * 包名 43 | * @param className 44 | * 类名 45 | * @param suffix 46 | * 后缀名 47 | * @param templateValue 48 | * 模板的值 49 | */ 50 | public TableAttributeKeyValueTemplate(String key, String packageName, String className, String suffix, String templateValue) { 51 | super(); 52 | this.key.setValue(key); 53 | this.packageName.setValue(packageName); 54 | this.className.setValue(className); 55 | this.suffix.setValue(suffix); 56 | this.template = new ComboBox<>(); 57 | this.template.setValue(templateValue); 58 | this.templateValue = templateValue; 59 | } 60 | 61 | /** 62 | * 初始化 63 | */ 64 | public TableAttributeKeyValueTemplate(JSONObject object) { 65 | super(); 66 | setKey(object.getString("key")); 67 | setPackageName(object.getString("packageName")); 68 | setClassName(object.getString("className")); 69 | setSuffix(object.getString("suffix")); 70 | setTemplateValue(object.getString("templateValue")); 71 | } 72 | 73 | /** 74 | * 将JSONObject对象转换为当前对象 75 | * 76 | * @param object 77 | * @return 78 | */ 79 | public static TableAttributeKeyValueTemplate fromJson(JSONObject object) { 80 | return new TableAttributeKeyValueTemplate(object); 81 | } 82 | 83 | /** 84 | * 将当期对象转换为JSONObject 85 | * 86 | * @return 87 | */ 88 | public JSONObject toJson() { 89 | JSONObject result = new JSONObject(); 90 | result.put("key", key.getValue()); 91 | result.put("packageName", packageName.getValue()); 92 | result.put("className", className.getValue()); 93 | result.put("suffix", suffix.getValue()); 94 | result.put("templateValue", getTemplateValue()); 95 | return result; 96 | } 97 | 98 | /** 99 | * 初始化 100 | * 101 | * @param key 102 | * key列的值 103 | * @param packageName 104 | * packageName列的值 105 | * @param className 106 | * 当前列的描述 107 | * @param template 108 | * 模板的ComboBox 109 | */ 110 | public TableAttributeKeyValueTemplate(String key, String packageName, String className, String suffix, ComboBox template) { 111 | super(); 112 | this.key.setValue(key); 113 | this.packageName.setValue(packageName); 114 | this.className.setValue(className); 115 | this.suffix.setValue(suffix); 116 | this.template = template; 117 | } 118 | 119 | public String getKey() { 120 | return key.getValue(); 121 | } 122 | 123 | public void setKey(String key) { 124 | this.key.setValue(key); 125 | } 126 | 127 | public void setKey(StringProperty key) { 128 | this.key = key; 129 | } 130 | 131 | public String getPackageName() { 132 | return packageName.getValue(); 133 | } 134 | 135 | public void setPackageName(String packageName) { 136 | this.packageName.setValue(packageName); 137 | } 138 | 139 | public void setPackageName(StringProperty packageName) { 140 | this.packageName = packageName; 141 | } 142 | 143 | public String getClassName() { 144 | return className.getValue(); 145 | } 146 | 147 | public void setClassName(String className) { 148 | this.className.setValue(className); 149 | } 150 | 151 | public void setClassName(StringProperty className) { 152 | this.className = className; 153 | } 154 | 155 | public String getTemplateValue() { 156 | if (template != null) { 157 | return template.getValue(); 158 | } 159 | if (templateValue != null) { 160 | return templateValue; 161 | } 162 | return null; 163 | } 164 | 165 | public void setTemplateValue(String templateValue) { 166 | this.templateValue = templateValue; 167 | if (this.template == null) { 168 | this.template = new ComboBox<>(); 169 | this.template.setValue(templateValue); 170 | } 171 | } 172 | 173 | public ComboBox getTemplate() { 174 | return template; 175 | } 176 | 177 | public String getSuffix() { 178 | return suffix.getValue(); 179 | } 180 | 181 | public void setSuffix(String suffix) { 182 | this.suffix.setValue(suffix); 183 | } 184 | public void setSuffix(StringProperty suffix) { 185 | this.suffix = suffix; 186 | } 187 | 188 | public void setTemplate(String template) { 189 | this.template.setValue(template); 190 | } 191 | 192 | public void setTemplate(ComboBox template) { 193 | this.template = template; 194 | } 195 | 196 | @Override 197 | public String toString() { 198 | return "TableAttributeKeyValueTemplate [key=" + key + ", packageName=" + packageName + ", className=" + className + ", suffix=" + suffix 199 | + ", template=" + template + ", templateValue=" + templateValue + "]"; 200 | } 201 | 202 | } 203 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/models/TableAttributeEntity.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.models; 2 | 3 | import javafx.beans.property.BooleanProperty; 4 | import javafx.beans.property.SimpleBooleanProperty; 5 | import javafx.beans.property.SimpleStringProperty; 6 | import javafx.beans.property.StringProperty; 7 | import javafx.scene.control.ComboBox; 8 | 9 | /** 10 | * Table的key与packageName属性 11 | * 12 | * @author Mirren 13 | * 14 | */ 15 | public class TableAttributeEntity implements Comparable { 16 | // ---------------------------表格需要的属性--------------------------------- 17 | /** 是否创建 */ 18 | private BooleanProperty tdCreate = new SimpleBooleanProperty(true); 19 | /** 列名 */ 20 | private StringProperty tdColumnName = new SimpleStringProperty(); 21 | /** jdbc数据类型 */ 22 | private StringProperty tdJdbcType = new SimpleStringProperty(); 23 | /** java数据类型 */ 24 | private ComboBox tdJavaType = new ComboBox(); 25 | /** 属性名称 */ 26 | private StringProperty tdField = new SimpleStringProperty(); 27 | 28 | // --------------------自定义属性-------------------------------- 29 | /** 30 | * 是否允许使用 NULL值
31 | * true = 明确允许使用 NULL值
32 | * false = 可能不允许使用 NULL值(不明确是否允许使用NULL值)
33 | */ 34 | private boolean nullable; 35 | 36 | // ----------------java.sql.DatabaseMetaData.getColumns自带的属性---------------------- 37 | /** 默认值 */ 38 | private String columnDef; 39 | /** 描述列的注释 */ 40 | private String remarks; 41 | /** 列的大小,对于 字符串 或 date 类型,列的大小是最大字符数,对于 numeric 和 decimal 类型,列的大小就是精度 */ 42 | private int columnSize; 43 | /** 小数部分的位数 */ 44 | private int decimalDigits; 45 | /** 表中的列的顺序(从 1 开始) */ 46 | private int ordinalPosition; 47 | /** 48 | * 初始化 49 | */ 50 | public TableAttributeEntity() { 51 | super(); 52 | initComboBox(); 53 | } 54 | /** 55 | * 初始化 56 | * 57 | * @param javaType 58 | * 数据类型 59 | * @param fieldName 60 | * 字段名称 61 | */ 62 | public TableAttributeEntity(String javaType, String fieldName) { 63 | super(); 64 | initComboBox(); 65 | this.tdJavaType.setValue(javaType); 66 | this.tdField.setValue(fieldName); 67 | } 68 | public void initComboBox() { 69 | tdJavaType.setEditable(true); 70 | tdJavaType.getItems().addAll("int", "double", "char", "long", "java.util.Date", "java.sql.Date", "java.time.LocalDate", 71 | "java.time.LocalTime", "java.time.LocalDateTime", "java.util.List", "java.util.Set", "java.util.Map", "JsonObject", 72 | "String", "Character", "Double", "Integer", "Long", "Object"); 73 | } 74 | 75 | public BooleanProperty tdCreateProperty() { 76 | return tdCreate; 77 | } 78 | public boolean getTdCreate() { 79 | return tdCreate.get(); 80 | } 81 | public void setTdCreate(boolean create) { 82 | this.tdCreate.set(create); 83 | } 84 | 85 | public String getTdColumnName() { 86 | return tdColumnName.getValue(); 87 | } 88 | 89 | public void setTdColumnName(String tdColumnName) { 90 | this.tdColumnName.setValue(tdColumnName); 91 | } 92 | 93 | public void setTdColumnName(StringProperty tdColumnName) { 94 | this.tdColumnName = tdColumnName; 95 | } 96 | 97 | public String getTdJdbcType() { 98 | return tdJdbcType.getValue(); 99 | } 100 | 101 | public void setTdJdbcType(String tdJdbcType) { 102 | this.tdJdbcType.setValue(tdJdbcType); 103 | } 104 | 105 | public void setTdJdbcType(StringProperty tdJdbcType) { 106 | this.tdJdbcType = tdJdbcType; 107 | } 108 | 109 | public ComboBox getTdJavaType() { 110 | return tdJavaType; 111 | } 112 | 113 | public void setTdJavaType(String tdJavaType) { 114 | this.tdJavaType.setValue(tdJavaType); 115 | } 116 | 117 | public void setTdJavaType(ComboBox tdJavaType) { 118 | this.tdJavaType = tdJavaType; 119 | } 120 | 121 | public String getTdField() { 122 | return tdField.getValue(); 123 | } 124 | 125 | public void setTdField(String tdField) { 126 | this.tdField.setValue(tdField); 127 | } 128 | 129 | public void setTdField(StringProperty tdField) { 130 | this.tdField = tdField; 131 | } 132 | 133 | public String getColumnDef() { 134 | return columnDef; 135 | } 136 | 137 | public void setColumnDef(String columnDef) { 138 | this.columnDef = columnDef; 139 | } 140 | 141 | public String getRemarks() { 142 | return remarks; 143 | } 144 | 145 | public void setRemarks(String remarks) { 146 | this.remarks = remarks; 147 | } 148 | 149 | public int getColumnSize() { 150 | return columnSize; 151 | } 152 | 153 | public void setColumnSize(int columnSize) { 154 | this.columnSize = columnSize; 155 | } 156 | 157 | public int getDecimalDigits() { 158 | return decimalDigits; 159 | } 160 | 161 | public void setDecimalDigits(int decimalDigits) { 162 | this.decimalDigits = decimalDigits; 163 | } 164 | 165 | public boolean isNullable() { 166 | return nullable; 167 | } 168 | 169 | public void setNullable(boolean nullable) { 170 | this.nullable = nullable; 171 | } 172 | 173 | public int getOrdinalPosition() { 174 | return ordinalPosition; 175 | } 176 | 177 | public void setOrdinalPosition(int ordinalPosition) { 178 | this.ordinalPosition = ordinalPosition; 179 | } 180 | 181 | @Override 182 | public String toString() { 183 | return "TableAttributeEntity [tdCreate=" + tdCreate + ", tdColumnName=" + tdColumnName + ", tdJdbcType=" + tdJdbcType + ", tdJavaType=" 184 | + tdJavaType + ", tdField=" + tdField + ", nullable=" + nullable + ", columnDef=" + columnDef + ", remarks=" + remarks 185 | + ", columnSize=" + columnSize + ", decimalDigits=" + decimalDigits + ", ordinalPosition=" + ordinalPosition + "]"; 186 | } 187 | @Override 188 | public int compareTo(TableAttributeEntity obj) { 189 | return ordinalPosition > obj.getOrdinalPosition() ? 1 : (ordinalPosition == obj.getOrdinalPosition() ? 0 : -1); 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /src/main/java/com/szmirren/controller/HistoryConfigController.java: -------------------------------------------------------------------------------- 1 | package com.szmirren.controller; 2 | 3 | import java.net.URL; 4 | import java.util.List; 5 | import java.util.ResourceBundle; 6 | 7 | import org.apache.log4j.Logger; 8 | 9 | import com.szmirren.Main; 10 | import com.szmirren.common.ConfigUtil; 11 | import com.szmirren.common.LanguageKey; 12 | import com.szmirren.models.HistoryConfigCVF; 13 | import com.szmirren.options.HistoryConfig; 14 | import com.szmirren.view.AlertUtil; 15 | 16 | import javafx.beans.property.StringProperty; 17 | import javafx.collections.FXCollections; 18 | import javafx.collections.ObservableList; 19 | import javafx.fxml.FXML; 20 | import javafx.scene.control.Button; 21 | import javafx.scene.control.Label; 22 | import javafx.scene.control.TableColumn; 23 | import javafx.scene.control.TableView; 24 | import javafx.scene.control.cell.PropertyValueFactory; 25 | import javafx.scene.layout.HBox; 26 | 27 | public class HistoryConfigController extends BaseController { 28 | private Logger LOG = Logger.getLogger(this.getClass()); 29 | private IndexController indexController; 30 | 31 | /** 配置信息表 */ 32 | @FXML 33 | private TableView tblConfigInfo; 34 | /** 提示语言 */ 35 | @FXML 36 | private Label lblTips; 37 | 38 | @Override 39 | public void initialize(URL location, ResourceBundle resources) { 40 | initTable(); 41 | } 42 | 43 | /** 44 | * 初始化配置table 45 | */ 46 | public void initTable() { 47 | LOG.debug("初始化配置信息窗口...."); 48 | LOG.debug("初始化配置信息表格..."); 49 | ObservableList data = null; 50 | try { 51 | data = getHistoryConfig(); 52 | } catch (Exception e) { 53 | tblConfigInfo.setPlaceholder(new Label("加载配置文件失败!失败原因:\r\n" + e.getMessage())); 54 | LOG.error("初始化配置信息表格出现异常!!!", e); 55 | } 56 | 57 | TableColumn tdInfo = new TableColumn("配置信息文件名"); 58 | tdInfo.textProperty().bind(Main.LANGUAGE.get(LanguageKey.CONFIG_TD_INFO)); 59 | TableColumn tdOperation = new TableColumn("操作"); 60 | tdOperation.textProperty().bind(Main.LANGUAGE.get(LanguageKey.CONFIG_TD_OPERATION)); 61 | tdInfo.setCellValueFactory(new PropertyValueFactory<>("name")); 62 | tdOperation.setCellValueFactory(new PropertyValueFactory<>("hbox")); 63 | tblConfigInfo.getColumns().add(tdInfo); 64 | tblConfigInfo.getColumns().add(tdOperation); 65 | tblConfigInfo.setItems(data); 66 | StringProperty property = Main.LANGUAGE.get(LanguageKey.HISTORY_CONFIG_TABLE_TIPS); 67 | String tips = property == null ? "尚未添加任何配置信息;可以通过首页保存配置新增" : property.get(); 68 | tblConfigInfo.setPlaceholder(new Label(tips)); 69 | // 设置列的大小自适应 70 | tblConfigInfo.setColumnResizePolicy(resize -> { 71 | double width = resize.getTable().getWidth(); 72 | tdInfo.setPrefWidth(width * 2 / 3); 73 | tdOperation.setPrefWidth(width / 3); 74 | return true; 75 | }); 76 | lblTips.textProperty().bind(Main.LANGUAGE.get(LanguageKey.CONFIG_LBL_TIPS)); 77 | LOG.debug("初始化配置信息完成!"); 78 | LOG.debug("初始化配置信息窗口完成!"); 79 | } 80 | 81 | /** 82 | * 获得配置文件Table 特别注意,条件添加的关系,加载与删除配置需要在这里面操作 83 | * 84 | * @return 85 | * @throws Exception 86 | */ 87 | public ObservableList getHistoryConfig() throws Exception { 88 | ObservableList result = FXCollections.observableArrayList(); 89 | List item = ConfigUtil.getHistoryConfigs(); 90 | // 遍历配置文件并加载到工厂里面,同时给操作配置文件的加载与删除 91 | 92 | for (HistoryConfig tmp : item) { 93 | String configName = tmp.getHistoryConfigName(); 94 | HBox box = new HBox(); 95 | box.setSpacing(15); 96 | Button button = new Button("加载配置"); 97 | button.textProperty().bind(Main.LANGUAGE.get(LanguageKey.CONFIG_BTN_LOAD)); 98 | button.setUserData(tmp.getHistoryConfigName()); 99 | button.setOnAction(Event -> { 100 | try { 101 | LOG.debug("执行将配置信息加载到首页..."); 102 | indexController.loadIndexConfigInfo(button.getUserData().toString()); 103 | closeDialogStage(); 104 | LOG.debug("将配置信息加载到首页成功!"); 105 | } catch (Exception e) { 106 | LOG.error("将配置信息加载到首页失败!!!" , e); 107 | AlertUtil.showErrorAlert("加载配置失败!失败原因:\r\n" + e.getMessage()); 108 | } 109 | }); 110 | Button button1 = new Button("删除配置"); 111 | button1.textProperty().bind(Main.LANGUAGE.get(LanguageKey.CONFIG_BTN_DATELE)); 112 | button1.setUserData(tmp.getHistoryConfigName()); 113 | button1.setOnAction(Event -> { 114 | if (AlertUtil.showConfirmAlert("确定删除吗?")) { 115 | try { 116 | LOG.debug("执行删除配置信息..."); 117 | ConfigUtil.deleteHistoryConfigByName(button1.getUserData().toString()); 118 | for (int i = 0; i < tblConfigInfo.getItems().size(); i++) { 119 | if (tblConfigInfo.getItems().get(i).getName().equals(button1.getUserData().toString())) { 120 | tblConfigInfo.getItems().remove(i); 121 | break; 122 | } 123 | } 124 | LOG.debug("执行删除配置完成!"); 125 | } catch (Exception e) { 126 | LOG.error("执行删除配置失败!!!" , e); 127 | AlertUtil.showErrorAlert("删除失败!失败原因:\r\n" + e.getMessage()); 128 | } 129 | } 130 | }); 131 | box.getChildren().addAll(button, button1); 132 | 133 | HistoryConfigCVF cvf = new HistoryConfigCVF(configName, box); 134 | result.add(cvf); 135 | } 136 | 137 | return result; 138 | } 139 | 140 | // -------------------get/set------------------------------ 141 | 142 | public IndexController getIndexController() { 143 | return indexController; 144 | } 145 | 146 | public void setIndexController(IndexController indexController) { 147 | this.indexController = indexController; 148 | } 149 | 150 | public TableView getTblConfigInfo() { 151 | return tblConfigInfo; 152 | } 153 | 154 | public void setTblConfigInfo(TableView tblConfigInfo) { 155 | this.tblConfigInfo = tblConfigInfo; 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /src/main/resources/FXML/UpdateConnection.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 48 | 56 | 64 | 72 | 80 | 88 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 122 | 134 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /src/main/resources/FXML/Connection.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 48 | 56 | 64 | 72 | 80 | 88 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 122 | 134 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /src/main/resources/FXML/SetCustomProperty.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 54 | 55 | 56 | 57 | 58 | 63 | 68 | 69 | 70 | 71 | 72 | 73 | 78 | 79 | 80 | 81 | 82 | 83 | 88 | 89 | 90 | 91 | 92 | 93 | 102 | 114 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/main/resources/FXML/SetCustom.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 56 | 57 | 58 | 59 | 60 | 65 | 70 | 71 | 72 | 73 | 74 | 75 | 80 | 81 | 82 | 83 | 84 | 85 | 90 | 91 | 92 | 93 | 94 | 95 | 104 | 116 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /src/main/resources/FXML/SetAbstractSQL.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 54 | 55 | 56 | 57 | 58 | 63 | 68 | 69 | 70 | 71 | 72 | 73 | 78 | 79 | 80 | 81 | 82 | 83 | 88 | 89 | 90 | 91 | 92 | 93 | 102 | 103 | 108 | 109 | 121 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | --------------------------------------------------------------------------------