├── README.md ├── pom.xml └── src └── main ├── java └── core │ ├── Main.java │ ├── database │ ├── Column.java │ ├── ConnectionFactory.java │ ├── DatabaseElement.java │ ├── DatabaseReader.java │ └── Table.java │ ├── file │ └── java │ │ ├── Class.java │ │ ├── Field.java │ │ ├── Interface.java │ │ ├── JavaComponent.java │ │ ├── JavaElement.java │ │ ├── JavaFile.java │ │ ├── Method.java │ │ ├── Parameter.java │ │ └── Type.java │ ├── generator │ ├── ClassGenerator.java │ ├── Generator.java │ ├── InterfaceGenerator.java │ ├── SwaggerUIGenerator.java │ ├── config │ │ ├── AbstractConfigGenerator.java │ │ ├── ConfigGenerator.java │ │ ├── HibernateConfigGenerator.java │ │ ├── PomGenerator.java │ │ ├── SpringConfigGenerator.java │ │ ├── SpringMVCConfigGenerator.java │ │ └── WebXmlGenerator.java │ ├── controller │ │ ├── ControllerGenerator.java │ │ └── SpringMVCGenerator.java │ ├── dao │ │ ├── DaoGenerator.java │ │ ├── DaoImplGenerator.java │ │ ├── HibernateGenerator.java │ │ ├── POGenerator.java │ │ └── POJOGenerator.java │ └── service │ │ ├── ServiceGenerator.java │ │ ├── ServiceImplGenerator.java │ │ └── SpringGenerator.java │ ├── resolver │ └── TypeResolver.java │ └── util │ ├── FileUtils.java │ ├── FreeMarkerUtils.java │ ├── JavaUtils.java │ ├── NameUtils.java │ ├── PackageUtils.java │ ├── PathUtils.java │ ├── StringUtils.java │ └── TextUtils.java └── resources ├── ftl ├── applicationContext-controller.xml.ftl ├── applicationContext-dao.xml.ftl ├── applicationContext-service.xml.ftl ├── pom.xml.ftl └── web.xml.ftl └── swagger-ui ├── css ├── print.css ├── reset.css ├── screen.css ├── style.css └── typography.css ├── fonts ├── DroidSans-Bold.ttf └── DroidSans.ttf ├── images ├── collapse.gif ├── expand.gif ├── explorer_icons.png ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── logo_small.png ├── pet_store_api.png ├── throbber.gif └── wordnik_api.png ├── index.html ├── lang ├── ca.js ├── el.js ├── en.js ├── es.js ├── fr.js ├── geo.js ├── it.js ├── ja.js ├── ko-kr.js ├── pl.js ├── pt.js ├── ru.js ├── tr.js ├── translator.js └── zh-cn.js ├── lib ├── backbone-min.js ├── es5-shim.js ├── handlebars-4.0.5.js ├── highlight.9.1.0.pack.js ├── highlight.9.1.0.pack_extended.js ├── jquery-1.8.0.min.js ├── jquery.ba-bbq.min.js ├── jquery.slideto.min.js ├── jquery.wiggle.min.js ├── js-yaml.min.js ├── jsoneditor.min.js ├── lodash.min.js ├── marked.js ├── object-assign-pollyfill.js ├── sanitize-html.min.js └── swagger-oauth.js ├── o2c.html ├── swagger-ui.js └── swagger-ui.min.js /README.md: -------------------------------------------------------------------------------- 1 | # CodeGenerator 2 | 详情见博客 http://www.jianshu.com/p/098da3724bed 3 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | CodeGenerator 8 | CodeGenerator 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | mysql 15 | mysql-connector-java 16 | 5.1.26 17 | 18 | 19 | 20 | 21 | freemarker 22 | freemarker 23 | 2.3.8 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-compiler-plugin 33 | 34 | 1.7 35 | 1.7 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/java/core/Main.java: -------------------------------------------------------------------------------- 1 | package core; 2 | 3 | import core.database.DatabaseReader; 4 | import core.database.Table; 5 | import core.generator.SwaggerUIGenerator; 6 | import core.generator.config.*; 7 | import core.generator.controller.SpringMVCGenerator; 8 | import core.generator.dao.HibernateGenerator; 9 | import core.generator.service.SpringGenerator; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * 入口类. 15 | * 16 | * @author 李程鹏 17 | */ 18 | public class Main { 19 | /** 20 | * Description: 21 | *
22 |      * 入口函数
23 |      * 
24 | * 25 | * @param args 参数 26 | */ 27 | public static void main(String[] args) throws Exception { 28 | // 生成代码 29 | generate("test", "root", "root"); 30 | } 31 | 32 | /** 33 | * Description: 34 | *
35 |      * 根据数据库信息生成代码.
36 |      * 
37 | * 38 | * @param database 数据库 39 | * @param username 账户名 40 | * @param password 密码 41 | */ 42 | private static void generate(String database, String username, String password) throws Exception { 43 | // 读取数据库表格 44 | List tables = new DatabaseReader(username, password, database).readTables(); 45 | // 生成Dao层代码(Hibernate). 46 | new HibernateGenerator(tables).generate(); 47 | // 生成Service层代码(Spring). 48 | new SpringGenerator(tables).generate(); 49 | // 生成Controller层代码(SpringMVC) 50 | new SpringMVCGenerator(tables).generate(); 51 | // 生成配置文件 52 | new ConfigGenerator(database, username, password).generate(); 53 | // 生成SwaggerUI文件 54 | new SwaggerUIGenerator().generate(); 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/core/database/Column.java: -------------------------------------------------------------------------------- 1 | package core.database; 2 | 3 | /** 4 | * 数据库表中的列. 5 | * 6 | * @author 李程鹏 7 | */ 8 | public class Column extends DatabaseElement { 9 | /** 10 | * 列的类型 11 | */ 12 | private int type; 13 | 14 | /** 15 | * 是否是主键列 16 | */ 17 | private boolean isPrimaryKey; 18 | 19 | /** 20 | * Description: 21 | *
22 |      * 返回主键列标志.
23 |      * 
24 | * 25 | * @return {@code boolean} - 主键列标志 26 | */ 27 | public boolean isPrimaryKey() { 28 | // 返回标志 29 | return isPrimaryKey; 30 | } 31 | 32 | /** 33 | * Description: 34 | *
35 |      * 设置主键列标志.
36 |      * 
37 | * 38 | * @param isPrimaryKey 标志 39 | */ 40 | public void setPrimaryKey(boolean isPrimaryKey) { 41 | // 赋值 42 | this.isPrimaryKey = isPrimaryKey; 43 | } 44 | 45 | /** 46 | * Description: 47 | *
48 |      * 获取列的类型.
49 |      * 
50 | * 51 | * @return {@code int} - 列的类型 52 | */ 53 | public int getType() { 54 | // 返回列的类型 55 | return type; 56 | } 57 | 58 | /** 59 | * Description: 60 | *
61 |      * 设置列的类型.
62 |      * 
63 | * 64 | * @param type 列的类型 65 | */ 66 | public void setType(int type) { 67 | // 赋值 68 | this.type = type; 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/java/core/database/ConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package core.database; 2 | 3 | import java.sql.Connection; 4 | import java.sql.Driver; 5 | import java.sql.SQLException; 6 | import java.util.Properties; 7 | 8 | /** 9 | * 数据库连接工厂. 10 | * 11 | * @author 李程鹏 12 | */ 13 | public class ConnectionFactory { 14 | /** 15 | * 工厂实例 16 | */ 17 | private static ConnectionFactory instance = new ConnectionFactory(); 18 | 19 | /** 20 | * Description: 21 | *
22 |      * 获取工厂实例.
23 |      * 
24 | * 25 | * @return {@code core.database.ConnectionFactory} - 工厂实例 26 | */ 27 | public static ConnectionFactory getInstance() { 28 | // 返回工厂实例 29 | return instance; 30 | } 31 | 32 | /** 33 | * Description: 34 | *
35 |      * 获取连接驱动.
36 |      * 
37 | * 38 | * @return {@code java.sql.Driver} - 连接驱动 39 | */ 40 | private Driver getDriver() { 41 | // 驱动名 42 | String driverClass = "com.mysql.jdbc.Driver"; 43 | // 定义驱动对象 44 | Driver driver; 45 | try { 46 | // 加载驱动 47 | Class clazz = Class.forName(driverClass); 48 | // 创建驱动对象 49 | driver = (Driver) clazz.newInstance(); 50 | } catch (Exception e) { 51 | // 如果创建失败就抛出异常 52 | throw new RuntimeException("加载数据库驱动失败!"); 53 | } 54 | // 返回连接驱动 55 | return driver; 56 | } 57 | 58 | /** 59 | * Description: 60 | *
61 |      * 根据数据库信息获取连接对象.
62 |      * 
63 | * 64 | * @param username 用户名 65 | * @param password 密码 66 | * @param database 数据库 67 | * @return {@code java.sql.Connection} - 连接对象 68 | */ 69 | public Connection getConnection(String username, String password, String database) throws SQLException { 70 | // 获取连接驱动 71 | Driver driver = getDriver(); 72 | // 定义初始化属性对象 73 | Properties properties = new Properties(); 74 | // 设置用户名属性 75 | properties.setProperty("user", username); 76 | // 设置密码属性 77 | properties.setProperty("password", password); 78 | // 创建连接数据库的URL 79 | String url = "jdbc:mysql://localhost:3306/" + database; 80 | // 创建连接对象 81 | Connection connection = driver.connect(url, properties); 82 | // 如果创建失败 83 | if (connection == null) { 84 | // 抛出异常 85 | throw new SQLException("连接数据库失败!"); 86 | } 87 | // 返回连接对象 88 | return connection; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/core/database/DatabaseElement.java: -------------------------------------------------------------------------------- 1 | package core.database; 2 | 3 | /** 4 | * 数据库元素类. 5 | * 6 | * @author 李程鹏 7 | */ 8 | public class DatabaseElement { 9 | /** 10 | * 元素名 11 | */ 12 | protected String name; 13 | 14 | /** 15 | * 元素注释 16 | */ 17 | protected String remark; 18 | 19 | /** 20 | * Description: 21 | *
22 |      * 获取元素名.
23 |      * 
24 | * 25 | * @return {@code java.lang.String} - 元素名 26 | */ 27 | public String getName() { 28 | // 返回名字 29 | return name; 30 | } 31 | 32 | /** 33 | * Description: 34 | *
35 |      * 设置元素名.
36 |      * 
37 | * 38 | * @param name 名字 39 | */ 40 | public void setName(String name) { 41 | // 赋值 42 | this.name = name; 43 | } 44 | 45 | /** 46 | * Description: 47 | *
48 |      * 获取元素注释.
49 |      * 
50 | * 51 | * @return {@code java.lang.String} - 元素注释 52 | */ 53 | public String getRemark() { 54 | // 返回注释 55 | return remark; 56 | } 57 | 58 | /** 59 | * Description: 60 | *
61 |      * 设置元素注释.
62 |      * 
63 | * 64 | * @param remark 注释 65 | */ 66 | public void setRemark(String remark) { 67 | // 赋值 68 | this.remark = remark; 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/java/core/database/DatabaseReader.java: -------------------------------------------------------------------------------- 1 | package core.database; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DatabaseMetaData; 5 | import java.sql.ResultSet; 6 | import java.sql.Statement; 7 | import java.util.ArrayList; 8 | import java.util.HashSet; 9 | import java.util.List; 10 | import java.util.Set; 11 | 12 | /** 13 | * 数据库读取器. 14 | * 15 | * @author 李程鹏 16 | */ 17 | public class DatabaseReader { 18 | /** 19 | * 数据库名 20 | */ 21 | private final String database; 22 | 23 | /** 24 | * 数据库连接对象 25 | */ 26 | private Connection connection; 27 | 28 | /** 29 | * 数据库元数据 30 | */ 31 | private DatabaseMetaData databaseMetaData; 32 | 33 | /** 34 | * Description: 35 | *
 36 |      * 构造实例化数据库读取器.
 37 |      * 
38 | * 39 | * @param username 用户名 40 | * @param password 密码 41 | * @param database 数据库 42 | */ 43 | public DatabaseReader(String username, String password, String database) throws Exception { 44 | // 将数据库名赋值给属性 45 | this.database = database; 46 | // 获取数据库连接 47 | connection = ConnectionFactory.getInstance().getConnection(username, password, database); 48 | // 获取数据库元数据 49 | databaseMetaData = connection.getMetaData(); 50 | } 51 | 52 | /** 53 | * Description: 54 | *
 55 |      * 读取数据库表格信息.
 56 |      * 
57 | * 58 | * @return {@code java.util.List} - 表格信息 59 | */ 60 | public List
readTables() throws Exception { 61 | // 获取数据库中所有的表格名 62 | List tableNames = readTableNames(); 63 | // 定义并初始化表格对象集合 64 | List
tables = new ArrayList<>(); 65 | // 遍历表格名集合 66 | for (String tableName : tableNames) { 67 | // 新建表格对象 68 | Table table = new Table(); 69 | // 设置表格注释 70 | table.setRemark(getTableRemark(tableName)); 71 | // 设置表格名 72 | table.setName(tableName); 73 | // 设置列 74 | table.setColumns(readColumns(tableName)); 75 | // 将表格对象添加到集合中 76 | tables.add(table); 77 | } 78 | // 返回表格对象集合 79 | return tables; 80 | } 81 | 82 | /** 83 | * Description: 84 | *
 85 |      * 读取数据库中表格的名字.
 86 |      * 
87 | * 88 | * @return {@code java.util.List} - 表格名集合 89 | */ 90 | private List readTableNames() throws Exception { 91 | // 新建表格名集合 92 | List tableNames = new ArrayList<>(); 93 | // 指定查询参数 94 | String[] types = {"TABLE"}; 95 | // 查询数据库的表格信息,获取查询结果集. 96 | ResultSet resultSet = databaseMetaData.getTables(null, database, "%", types); 97 | // 遍历查询结果集 98 | while (resultSet.next()) { 99 | // 取出表格名,放入集合中. 100 | tableNames.add(resultSet.getString("TABLE_NAME")); 101 | } 102 | // 关闭查询结果集 103 | resultSet.close(); 104 | // 返回表格名集合 105 | return tableNames; 106 | } 107 | 108 | /** 109 | * Description: 110 | *
111 |      * 通过表格名读取表格列信息.
112 |      * 
113 | * 114 | * @param tableName 表格名 115 | * @return {@code java.util.List} - 列集合 116 | */ 117 | private List readColumns(String tableName) throws Exception { 118 | // 获取表格中的主键 119 | Set primaryKeys = getPrimaryKeys(tableName); 120 | // 根据表格名查询表格中列的信息,获取查询结果集. 121 | ResultSet resultSet = databaseMetaData.getColumns(null, null, tableName, null); 122 | // 新建列集合 123 | List columns = new ArrayList<>(); 124 | // 遍历查询结果集 125 | while (resultSet.next()) { 126 | // 新建列对象 127 | Column column = new Column(); 128 | // 获取列名 129 | String columnName = resultSet.getString("COLUMN_NAME"); 130 | // 如果该列是主键列 131 | if (primaryKeys.contains(columnName)) { 132 | // 设置列主键标志 133 | column.setPrimaryKey(true); 134 | } 135 | // 设置列名 136 | column.setName(columnName); 137 | // 设置列的类型 138 | column.setType(resultSet.getInt("DATA_TYPE")); 139 | // 设置列的注释 140 | column.setRemark(resultSet.getString("REMARKS")); 141 | // 将列对象放入集合中 142 | columns.add(column); 143 | } 144 | // 关闭查询结果集 145 | resultSet.close(); 146 | // 返回列集合 147 | return columns; 148 | } 149 | 150 | /** 151 | * Description: 152 | *
153 |      * 根据表格名获取表格注释.因为使用API获取不到信息,所以只能自己写.
154 |      * 
155 | * 156 | * @param tableName 表名 157 | * @return {@code java.lang.String} - 表格注释 158 | */ 159 | private String getTableRemark(String tableName) throws Exception { 160 | // 获取语句执行对象 161 | Statement statement = connection.createStatement(); 162 | // 查询表格的创建语句,获取查询结果集. 163 | ResultSet resultSet = statement.executeQuery("show create table " + tableName); 164 | // 如果查询结果集不为空 165 | if (resultSet != null && resultSet.next()) { 166 | // 定义返回结果 167 | String remark; 168 | // 取出表格的创建语句 169 | String createStatement = resultSet.getString(2); 170 | // 获取表格注释标志的下标位置 171 | int index = createStatement.indexOf("COMMENT='"); 172 | // 如果表格创建语句中没有指定注释 173 | if (index < 0) { 174 | // 返回空串 175 | return ""; 176 | } 177 | // 截取出最后的字符串 178 | remark = createStatement.substring(index + 9); 179 | // 去掉最后一个引号后就是注释本身了 180 | remark = remark.substring(0, remark.length() - 1); 181 | // 返回表格注释 182 | return remark; 183 | } else {// 如果查询结果集为空 184 | // 返回空串 185 | return ""; 186 | } 187 | } 188 | 189 | /** 190 | * Description: 191 | *
192 |      * 获取表格中的主键.
193 |      * 
194 | * 195 | * @param tableName 表格名 196 | * @return {@code java.util.Set} - 主键集合 197 | */ 198 | private Set getPrimaryKeys(String tableName) throws Exception { 199 | // 定义主键集合 200 | Set primaryKeys = new HashSet<>(); 201 | // 查询主键信息 202 | ResultSet resultSet = databaseMetaData.getPrimaryKeys(null, null, tableName); 203 | // 遍历查询结果集 204 | while (resultSet.next()) { 205 | // 将主键列的列名放入主键集合中 206 | primaryKeys.add(resultSet.getString("COLUMN_NAME")); 207 | } 208 | // 返回主键集合 209 | return primaryKeys; 210 | } 211 | } -------------------------------------------------------------------------------- /src/main/java/core/database/Table.java: -------------------------------------------------------------------------------- 1 | package core.database; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 数据库中的表. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public class Table extends DatabaseElement { 11 | /** 12 | * 表中的列 13 | */ 14 | private List columns; 15 | 16 | /** 17 | * Description: 18 | *
19 |      * 获取列集合.
20 |      * 
21 | * 22 | * @return {@code java.util.List} - 列集合 23 | */ 24 | public List getColumns() { 25 | // 返回列集合 26 | return columns; 27 | } 28 | 29 | /** 30 | * Description: 31 | *
32 |      * 设置列集合.
33 |      * 
34 | * 35 | * @param columns 列集合 36 | */ 37 | public void setColumns(List columns) { 38 | // 赋值 39 | this.columns = columns; 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/core/file/java/Class.java: -------------------------------------------------------------------------------- 1 | package core.file.java; 2 | 3 | import core.util.JavaUtils; 4 | import core.util.TextUtils; 5 | 6 | import java.util.*; 7 | 8 | /** 9 | * 类. 10 | * 11 | * @author 李程鹏 12 | */ 13 | public class Class extends JavaFile { 14 | /** 15 | * 父类 16 | */ 17 | private Type superClass; 18 | 19 | /** 20 | * 类中的属性 21 | */ 22 | private List fields = new ArrayList<>(); 23 | 24 | /** 25 | * 内部类 26 | */ 27 | private List classes = new ArrayList<>(); 28 | 29 | /** 30 | * 实现的接口 31 | */ 32 | private Set implementedInterfaces = new TreeSet<>(); 33 | 34 | /** 35 | * Description: 36 | *
 37 |      * 设置父类.
 38 |      * 
39 | * 40 | * @param superClass 父类 41 | */ 42 | public void setSuperClass(Type superClass) { 43 | // 赋值 44 | this.superClass = superClass; 45 | } 46 | 47 | /** 48 | * Description: 49 | *
 50 |      * 添加属性.
 51 |      * 
52 | * 53 | * @param field 属性 54 | */ 55 | public void addField(Field field) { 56 | // 添加入集合 57 | fields.add(field); 58 | } 59 | 60 | /** 61 | * Description: 62 | *
 63 |      * 添加类.
 64 |      * 
65 | * 66 | * @param class_ 类 67 | */ 68 | public void addClass(Class class_) { 69 | // 添加入集合 70 | classes.add(class_); 71 | } 72 | 73 | /** 74 | * Description: 75 | *
 76 |      * 添加实现的接口.
 77 |      * 
78 | * 79 | * @param implementedInterface 需要实现的接口 80 | */ 81 | public void addImplementedInterface(Type implementedInterface) { 82 | // 添加入集合 83 | implementedInterfaces.add(implementedInterface); 84 | } 85 | 86 | /** 87 | * Description: 88 | *
 89 |      * 输出类的内容.
 90 |      * 
91 | * 92 | * @param indentCount 缩进次数 93 | * @return {@code java.lang.String} - 类的内容 94 | */ 95 | public String toString(int indentCount) { 96 | // 定义类内容变量 97 | StringBuilder class_ = new StringBuilder(); 98 | // 添加导入的类型 99 | putImports(class_); 100 | // 添加文档注释 101 | putDocuments(class_, indentCount); 102 | // 添加注解 103 | putAnnotations(class_, indentCount); 104 | // 添加缩进 105 | TextUtils.addIndentation(class_, indentCount); 106 | // 添加基本信息 107 | putInformation(class_); 108 | // 添加类的具体内容 109 | putContent(class_, indentCount); 110 | // 返回类的内容 111 | return class_.toString(); 112 | } 113 | 114 | /** 115 | * Description: 116 | *
117 |      * 为类放入基本信息.
118 |      * 
119 | * 120 | * @param class_ 类 121 | */ 122 | @Override 123 | protected void putInformation(StringBuilder class_) { 124 | // 添加访问控制符 125 | putVisibility(class_); 126 | // 添加抽象标志 127 | putAbstract(class_); 128 | // 添加静态标志 129 | putStatic(class_); 130 | // 添加终结标志 131 | putFinal(class_); 132 | // 添加类关键字 133 | class_.append("class"); 134 | // 添加空格 135 | TextUtils.addSpace(class_); 136 | // 添加类名 137 | class_.append(type.getTypeName()); 138 | // 如果父类不为空 139 | if (superClass != null) { 140 | // 添加空格 141 | TextUtils.addSpace(class_); 142 | // 添加继承关键字 143 | class_.append("extends"); 144 | // 添加空格 145 | TextUtils.addSpace(class_); 146 | // 添加父类名 147 | class_.append(superClass.getTypeName()); 148 | } 149 | // 添加本类需要实现的接口 150 | JavaUtils.putImplementedInterfaces(class_, implementedInterfaces); 151 | } 152 | 153 | /** 154 | * Description: 155 | *
156 |      * 添加类的具体内容.
157 |      * 
158 | * 159 | * @param class_ 类 160 | * @param indentCount 缩进次数 161 | */ 162 | @Override 163 | protected void putContent(StringBuilder class_, Integer indentCount) { 164 | // 添加空格 165 | TextUtils.addSpace(class_); 166 | // 添加左花括号 167 | class_.append("{"); 168 | // 增加缩进次数 169 | indentCount++; 170 | // 获取属性集合的迭代器 171 | Iterator fieldsIterator = fields.iterator(); 172 | // 遍历属性集合 173 | while (fieldsIterator.hasNext()) { 174 | // 换行 175 | TextUtils.addLine(class_); 176 | // 获取属性对象 177 | Field field = fieldsIterator.next(); 178 | // 添加属性内容 179 | class_.append(field.toString(indentCount)); 180 | // 如果还有下一个属性 181 | if (fieldsIterator.hasNext()) { 182 | // 换行 183 | TextUtils.addLine(class_); 184 | } 185 | } 186 | // 如果类中有方法 187 | if (methods.size() > 0) { 188 | // 换行 189 | TextUtils.addLine(class_); 190 | } 191 | // 获取方法集合的迭代器 192 | Iterator methodsIterator = methods.iterator(); 193 | // 遍历方法集合 194 | while (methodsIterator.hasNext()) { 195 | // 换行 196 | TextUtils.addLine(class_); 197 | // 获取方法对象 198 | Method method = methodsIterator.next(); 199 | // 不是接口中的方法 200 | method.setInterfaceMethod(false); 201 | // 添加方法内容 202 | class_.append(method.toString(indentCount)); 203 | // 如果还有下一个方法 204 | if (methodsIterator.hasNext()) { 205 | // 换行 206 | TextUtils.addLine(class_); 207 | } 208 | } 209 | // 如果类中有内部类 210 | if (classes.size() > 0) { 211 | // 换行 212 | TextUtils.addLine(class_); 213 | } 214 | // 获取内部类集合的迭代器 215 | Iterator classesIterator = classes.iterator(); 216 | // 遍历内部类集合 217 | while (classesIterator.hasNext()) { 218 | // 换行 219 | TextUtils.addLine(class_); 220 | // 获取内部类对象 221 | Class innerClass = classesIterator.next(); 222 | // 添加内部类内容 223 | class_.append(innerClass.toString(indentCount)); 224 | // 如果还有下一个内部类 225 | if (classesIterator.hasNext()) { 226 | // 换行 227 | TextUtils.addLine(class_); 228 | } 229 | } 230 | // 减小缩进次数 231 | indentCount--; 232 | // 换行 233 | TextUtils.addLine(class_); 234 | // 缩进 235 | TextUtils.addIndentation(class_, indentCount); 236 | // 添加右花括号 237 | class_.append('}'); 238 | } 239 | } -------------------------------------------------------------------------------- /src/main/java/core/file/java/Field.java: -------------------------------------------------------------------------------- 1 | package core.file.java; 2 | 3 | import core.util.TextUtils; 4 | 5 | /** 6 | * 属性. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public class Field extends JavaComponent { 11 | /** 12 | * 初始值 13 | */ 14 | private String initValue; 15 | 16 | /** 17 | * Description: 18 | *
 19 |      * 设置初始值.
 20 |      * 
21 | * 22 | * @param initValue 初始值 23 | */ 24 | public void setInitValue(String initValue) { 25 | // 赋值 26 | this.initValue = initValue; 27 | } 28 | 29 | /** 30 | * Description: 31 | *
 32 |      * 输出属性内容.
 33 |      * 
34 | * 35 | * @param indentCount 缩进次数 36 | * @return {@code java.lang.String} - 属性内容 37 | */ 38 | public String toString(int indentCount) { 39 | // 定义并初始化属性内容变量 40 | StringBuilder field = new StringBuilder(); 41 | // 添加文档注释 42 | putDocuments(field, indentCount); 43 | // 添加注解 44 | putAnnotations(field, indentCount); 45 | // 缩进 46 | TextUtils.addIndentation(field, indentCount); 47 | // 添加基本信息 48 | putInformation(field); 49 | // 添加内容 50 | putContent(field, null); 51 | // 返回结果 52 | return field.toString(); 53 | } 54 | 55 | /** 56 | * Description: 57 | *
 58 |      * 添加基本信息.
 59 |      * 
60 | * 61 | * @param field 属性 62 | */ 63 | @Override 64 | protected void putInformation(StringBuilder field) { 65 | // 添加访问控制符 66 | putVisibility(field); 67 | // 添加静态标志 68 | putStatic(field); 69 | // 添加终结标志 70 | putFinal(field); 71 | } 72 | 73 | /** 74 | * Description: 75 | *
 76 |      * 添加内容.
 77 |      * 
78 | * 79 | * @param field 属性 80 | * @param indentCount 缩进次数 81 | */ 82 | @Override 83 | protected void putContent(StringBuilder field, Integer indentCount) { 84 | // 添加属性类型 85 | field.append(type.getTypeName()); 86 | // 添加空格 87 | TextUtils.addSpace(field); 88 | // 添加属性名 89 | field.append(name); 90 | // 如果属性初始值不为空 91 | if (initValue != null && initValue.length() > 0) { 92 | // 添加空格 93 | TextUtils.addSpace(field); 94 | // 添加等号 95 | field.append("="); 96 | // 添加空格 97 | TextUtils.addSpace(field); 98 | // 添加初始值 99 | field.append(initValue); 100 | } 101 | // 添加分号 102 | field.append(';'); 103 | } 104 | } -------------------------------------------------------------------------------- /src/main/java/core/file/java/Interface.java: -------------------------------------------------------------------------------- 1 | package core.file.java; 2 | 3 | import core.util.JavaUtils; 4 | import core.util.TextUtils; 5 | 6 | import java.util.*; 7 | 8 | /** 9 | * 接口. 10 | * 11 | * @author 李程鹏 12 | */ 13 | public class Interface extends JavaFile { 14 | /** 15 | * 父接口 16 | */ 17 | private Set superInterfaces = new LinkedHashSet<>(); 18 | 19 | /** 20 | * Description: 21 | *
 22 |      * 添加父接口.
 23 |      * 
24 | * 25 | * @param superInterface 父接口 26 | */ 27 | public void addSuperInterface(Type superInterface) { 28 | // 添加入集合 29 | superInterfaces.add(superInterface); 30 | } 31 | 32 | /** 33 | * Description: 34 | *
 35 |      * 输出接口内容.
 36 |      * 
37 | * 38 | * @return {@code java.lang.String} - 接口内容 39 | */ 40 | public String toString() { 41 | // 定义并初始化接口内容变量 42 | StringBuilder interface_ = new StringBuilder(); 43 | // 添加导入的类型 44 | putImports(interface_); 45 | // 定义并初始化缩进次数 46 | int indentCount = 0; 47 | // 添加文档注释 48 | putDocuments(interface_, indentCount); 49 | // 添加注解 50 | putAnnotations(interface_, indentCount); 51 | // 添加接口基本信息 52 | putInformation(interface_); 53 | // 添加接口具体内容 54 | putContent(interface_, indentCount); 55 | // 返回接口内容 56 | return interface_.toString(); 57 | } 58 | 59 | /** 60 | * Description: 61 | *
 62 |      * 为接口放入基本信息.
 63 |      * 
64 | * 65 | * @param interface_ 接口 66 | */ 67 | @Override 68 | protected void putInformation(StringBuilder interface_) { 69 | // 添加访问控制符 70 | interface_.append(visibility); 71 | // 添加接口关键字 72 | interface_.append("interface"); 73 | // 添加空格 74 | TextUtils.addSpace(interface_); 75 | // 添加接口名 76 | interface_.append(type.getTypeName()); 77 | // 添加继承的父接口 78 | JavaUtils.putSuperInterfaces(interface_, superInterfaces); 79 | } 80 | 81 | /** 82 | * Description: 83 | *
 84 |      * 为接口放入具体的内容.
 85 |      * 
86 | * 87 | * @param interface_ 接口 88 | * @param indentCount 缩进次数 89 | */ 90 | @Override 91 | protected void putContent(StringBuilder interface_, Integer indentCount) { 92 | // 添加空格 93 | TextUtils.addSpace(interface_); 94 | // 添加左花括号 95 | interface_.append("{"); 96 | // 增加缩进次数 97 | indentCount++; 98 | // 获取方法集合的迭代器 99 | Iterator iterator = methods.iterator(); 100 | // 遍历方法集合 101 | while (iterator.hasNext()) { 102 | // 换行 103 | TextUtils.addLine(interface_); 104 | // 取出方法 105 | Method method = iterator.next(); 106 | // 设置方法为接口方法 107 | method.setInterfaceMethod(true); 108 | // 添加方法 109 | interface_.append(method.toString(indentCount)); 110 | // 如果还有下一个方法 111 | if (iterator.hasNext()) { 112 | // 加一个空行 113 | TextUtils.addLine(interface_); 114 | } 115 | } 116 | // 减小缩进次数 117 | indentCount--; 118 | // 换行 119 | TextUtils.addLine(interface_); 120 | // 缩进 121 | TextUtils.addIndentation(interface_, indentCount); 122 | // 添加右花括号 123 | interface_.append('}'); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/core/file/java/JavaComponent.java: -------------------------------------------------------------------------------- 1 | package core.file.java; 2 | 3 | /** 4 | * Java组件抽象类. 5 | * 6 | * @author 李程鹏 7 | */ 8 | public abstract class JavaComponent extends JavaElement { 9 | /** 10 | * 组件类型(在方法中表示返回值类型). 11 | */ 12 | protected Type type; 13 | 14 | /** 15 | * 组件名 16 | */ 17 | protected String name; 18 | 19 | /** 20 | * Description: 21 | *
22 |      * 设置组件类型.
23 |      * 
24 | * 25 | * @param type 组件类型 26 | */ 27 | public void setType(Type type) { 28 | // 赋值 29 | this.type = type; 30 | } 31 | 32 | /** 33 | * Description: 34 | *
35 |      * 设置组件名.
36 |      * 
37 | * 38 | * @param name 组件名 39 | */ 40 | public void setName(String name) { 41 | // 赋值 42 | this.name = name; 43 | } 44 | 45 | /** 46 | * Description: 47 | *
48 |      * 获取组件类型.
49 |      * 
50 | * 51 | * @return {@code core.file.java.Type} - 组件类型 52 | */ 53 | public Type getType() { 54 | // 返回组件类型 55 | return type; 56 | } 57 | 58 | /** 59 | * Description: 60 | *
61 |      * 获取组件名.
62 |      * 
63 | * 64 | * @return {@code java.lang.String} - 组件名 65 | */ 66 | public String getName() { 67 | // 返回组件名 68 | return name; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/core/file/java/JavaElement.java: -------------------------------------------------------------------------------- 1 | package core.file.java; 2 | 3 | import core.util.TextUtils; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * Java元素抽象类. 10 | * 11 | * @author 李程鹏 12 | */ 13 | public abstract class JavaElement { 14 | /** 15 | * 访问控制符(private,protected,public) 16 | */ 17 | protected String visibility; 18 | 19 | /** 20 | * 静态标志 21 | */ 22 | protected boolean isStatic; 23 | 24 | /** 25 | * 终结标志 26 | */ 27 | protected boolean isFinal; 28 | 29 | /** 30 | * 抽象标志 31 | */ 32 | protected boolean isAbstract; 33 | 34 | /** 35 | * 文档注释集合 36 | */ 37 | protected List documents = new ArrayList<>(); 38 | 39 | /** 40 | * 注解集合 41 | */ 42 | protected List annotations = new ArrayList<>(); 43 | 44 | /** 45 | * Description: 46 | *
 47 |      * 设置访问控制符.
 48 |      * 
49 | * 50 | * @param visibility 访问控制符 51 | */ 52 | public void setVisibility(String visibility) { 53 | // 赋值 54 | this.visibility = visibility; 55 | } 56 | 57 | /** 58 | * Description: 59 | *
 60 |      * 设置静态标志.
 61 |      * 
62 | * 63 | * @param isStatic 静态标志 64 | */ 65 | public void setStatic(boolean isStatic) { 66 | // 赋值 67 | this.isStatic = isStatic; 68 | } 69 | 70 | /** 71 | * Description: 72 | *
 73 |      * 设置终结标志.
 74 |      * 
75 | * 76 | * @param isFinal 终结标志 77 | */ 78 | public void setFinal(boolean isFinal) { 79 | // 赋值 80 | this.isFinal = isFinal; 81 | } 82 | 83 | /** 84 | * Description: 85 | *
 86 |      * 设置抽象标志.
 87 |      * 
88 | * 89 | * @param isAbstract 抽象标志 90 | */ 91 | public void setAbstract(boolean isAbstract) { 92 | // 赋值 93 | this.isAbstract = isAbstract; 94 | } 95 | 96 | /** 97 | * Description: 98 | *
 99 |      * 添加文档注释.
100 |      * 
101 | * 102 | * @param document 文档注释 103 | */ 104 | public void addDocument(String document) { 105 | // 将文档注释添加到集合中 106 | documents.add(document); 107 | } 108 | 109 | /** 110 | * Description: 111 | *
112 |      * 添加注解.
113 |      * 
114 | * 115 | * @param annotation 注解 116 | */ 117 | public void addAnnotation(String annotation) { 118 | // 将注解添加到集合中 119 | annotations.add(annotation); 120 | } 121 | 122 | /** 123 | * Description: 124 | *
125 |      * 为Java元素放入访问控制符.
126 |      * 
127 | * 128 | * @param javaElement Java元素 129 | */ 130 | protected void putVisibility(StringBuilder javaElement) { 131 | // 放入操作 132 | javaElement.append(visibility); 133 | } 134 | 135 | /** 136 | * Description: 137 | *
138 |      * 为Java元素放入静态标志.
139 |      * 
140 | * 141 | * @param javaElement Java元素 142 | */ 143 | protected void putStatic(StringBuilder javaElement) { 144 | // 如果需要静态标志 145 | if (isStatic) { 146 | // 添加static关键字 147 | javaElement.append("static"); 148 | // 添加空格 149 | TextUtils.addSpace(javaElement); 150 | } 151 | } 152 | 153 | /** 154 | * Description: 155 | *
156 |      * 为Java元素放入终结标志.
157 |      * 
158 | * 159 | * @param javaElement Java元素 160 | */ 161 | protected void putFinal(StringBuilder javaElement) { 162 | // 如果需要终结标志 163 | if (isFinal) { 164 | // 添加final关键字 165 | javaElement.append("final"); 166 | // 添加空格 167 | TextUtils.addSpace(javaElement); 168 | } 169 | } 170 | 171 | /** 172 | * Description: 173 | *
174 |      * 为Java元素放入抽象标志.
175 |      * 
176 | * 177 | * @param javaElement Java元素 178 | */ 179 | protected void putAbstract(StringBuilder javaElement) { 180 | // 如果需要抽象标志 181 | if (isAbstract) { 182 | // 添加abstract关键字 183 | javaElement.append("abstract"); 184 | // 添加空格 185 | TextUtils.addSpace(javaElement); 186 | } 187 | } 188 | 189 | /** 190 | * Description: 191 | *
192 |      * 为Java元素放入文档注释.
193 |      * 
194 | * 195 | * @param javaElement Java元素 196 | * @param indentCount 缩进次数 197 | */ 198 | protected void putDocuments(StringBuilder javaElement, Integer indentCount) { 199 | // 放入操作 200 | putStrings(javaElement, documents, indentCount); 201 | } 202 | 203 | /** 204 | * Description: 205 | *
206 |      * 为Java元素放入注解.
207 |      * 
208 | * 209 | * @param javaElement Java元素 210 | * @param indentCount 缩进次数 211 | */ 212 | protected void putAnnotations(StringBuilder javaElement, Integer indentCount) { 213 | // 放入操作 214 | putStrings(javaElement, annotations, indentCount); 215 | } 216 | 217 | /** 218 | * Description: 219 | *
220 |      * 为Java元素放入基本信息,具体由子类来实现.
221 |      * 
222 | * 223 | * @param javaElement Java元素 224 | */ 225 | protected abstract void putInformation(StringBuilder javaElement); 226 | 227 | /** 228 | * Description: 229 | *
230 |      * 为Java元素放入内容,具体由子类来实现.
231 |      * 
232 | * 233 | * @param javaElement Java元素 234 | * @param indentCount 缩进次数 235 | */ 236 | protected abstract void putContent(StringBuilder javaElement, Integer indentCount); 237 | 238 | /** 239 | * Description: 240 | *
241 |      * 为Java元素放入字符串集合.
242 |      * 
243 | * 244 | * @param javaElement Java元素 245 | * @param strings 字符串集合 246 | * @param indentCount 缩进次数 247 | */ 248 | private void putStrings(StringBuilder javaElement, List strings, Integer indentCount) { 249 | // 遍历字符串集合 250 | for (String string : strings) { 251 | // 缩进 252 | TextUtils.addIndentation(javaElement, indentCount); 253 | // 添加字符串 254 | javaElement.append(string); 255 | // 换行 256 | TextUtils.addLine(javaElement); 257 | } 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /src/main/java/core/file/java/JavaFile.java: -------------------------------------------------------------------------------- 1 | package core.file.java; 2 | 3 | import core.util.StringUtils; 4 | import core.util.TextUtils; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Set; 9 | import java.util.TreeSet; 10 | 11 | /** 12 | * Java文件类. 13 | * 14 | * @author 李程鹏 15 | */ 16 | public abstract class JavaFile extends JavaElement { 17 | /** 18 | * 类型(类名或者接口名) 19 | */ 20 | protected Type type; 21 | 22 | /** 23 | * 需要导入的类型 24 | */ 25 | protected Set imports = new TreeSet<>(); 26 | 27 | /** 28 | * 方法集合 29 | */ 30 | protected List methods = new ArrayList<>(); 31 | 32 | /** 33 | * Description: 34 | *
 35 |      * 获取类型.
 36 |      * 
37 | * 38 | * @return {@code core.file.java.Type} - 类型 39 | */ 40 | public Type getType() { 41 | // 返回类型 42 | return type; 43 | } 44 | 45 | /** 46 | * Description: 47 | *
 48 |      * 设置类型.
 49 |      * 
50 | * 51 | * @param type 类型 52 | */ 53 | public void setType(Type type) { 54 | // 赋值 55 | this.type = type; 56 | } 57 | 58 | /** 59 | * Description: 60 | *
 61 |      * 添加需要导入的类型.
 62 |      * 
63 | * 64 | * @param import_ 需要导入的类型 65 | */ 66 | public void addImport(Type import_) { 67 | // 如果这个类型需要导入,而且它的包名和本文件的包名不相同. 68 | if (import_.isNeedImport() && !import_.getPackageName().equals(type.getPackageName())) { 69 | // 添加入集合 70 | imports.add(import_); 71 | } 72 | } 73 | 74 | /** 75 | * Description: 76 | *
 77 |      * 添加方法.
 78 |      * 
79 | * 80 | * @param method 方法 81 | */ 82 | public void addMethod(Method method) { 83 | // 添加入集合 84 | methods.add(method); 85 | } 86 | 87 | /** 88 | * Description: 89 | *
 90 |      * 为Java文件放入导入的类型.
 91 |      * 
92 | * 93 | * @param javaFile Java文件 94 | */ 95 | protected void putImports(StringBuilder javaFile) { 96 | // 获取文件类型所在的包名 97 | String packageName = type.getPackageName(); 98 | // 如果包名不为空 99 | if (packageName != null && packageName.length() > 0) { 100 | // 添加包关键字 101 | javaFile.append("package"); 102 | // 添加空格 103 | TextUtils.addSpace(javaFile); 104 | // 添加包名 105 | javaFile.append(type.getPackageName()); 106 | // 添加分号 107 | javaFile.append(';'); 108 | // 换行 109 | TextUtils.addLine(javaFile); 110 | // 换行 111 | TextUtils.addLine(javaFile); 112 | } 113 | // 获取导入语句集合 114 | Set importStatements = StringUtils.getImportStatements(imports); 115 | // 遍历导入语句集合 116 | for (String importStatement : importStatements) { 117 | // 添加导入语句 118 | javaFile.append(importStatement); 119 | // 换行 120 | TextUtils.addLine(javaFile); 121 | } 122 | // 如果已经添加了导入语句 123 | if (importStatements.size() > 0) { 124 | // 添加一个空行 125 | TextUtils.addLine(javaFile); 126 | } 127 | } 128 | } -------------------------------------------------------------------------------- /src/main/java/core/file/java/Method.java: -------------------------------------------------------------------------------- 1 | package core.file.java; 2 | 3 | import core.util.JavaUtils; 4 | import core.util.TextUtils; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.ListIterator; 9 | 10 | /** 11 | * 方法. 12 | * 13 | * @author 李程鹏 14 | */ 15 | public class Method extends JavaComponent { 16 | /** 17 | * 是否是构造方法 18 | */ 19 | private boolean isConstructor; 20 | 21 | /** 22 | * 是否是接口中的方法 23 | */ 24 | private boolean isInterfaceMethod; 25 | 26 | /** 27 | * 方法参数 28 | */ 29 | private List parameters = new ArrayList<>(); 30 | 31 | /** 32 | * 方法需要抛出的异常 33 | */ 34 | private List exceptions = new ArrayList<>(); 35 | 36 | /** 37 | * 方法体 38 | */ 39 | private List statements = new ArrayList<>(); 40 | 41 | /** 42 | * Description: 43 | *
 44 |      * 设置构造方法标志.
 45 |      * 
46 | * 47 | * @param isConstructor 构造方法标志 48 | */ 49 | public void setConstructor(boolean isConstructor) { 50 | // 赋值 51 | this.isConstructor = isConstructor; 52 | } 53 | 54 | /** 55 | * Description: 56 | *
 57 |      * 设置接口方法标志.
 58 |      * 
59 | * 60 | * @param isInterfaceMethod 接口方法标志 61 | */ 62 | public void setInterfaceMethod(boolean isInterfaceMethod) { 63 | // 赋值 64 | this.isInterfaceMethod = isInterfaceMethod; 65 | } 66 | 67 | /** 68 | * Description: 69 | *
 70 |      * 返回方法的参数.
 71 |      * 
72 | * 73 | * @return {@code java.util.List} - 参数集合 74 | */ 75 | public List getParameters() { 76 | // 返回参数集合 77 | return parameters; 78 | } 79 | 80 | /** 81 | * Description: 82 | *
 83 |      * 添加参数.
 84 |      * 
85 | * 86 | * @param parameter 参数 87 | */ 88 | public void addParameter(Parameter parameter) { 89 | // 添加操作 90 | parameters.add(parameter); 91 | } 92 | 93 | /** 94 | * Description: 95 | *
 96 |      * 添加异常.
 97 |      * 
98 | * 99 | * @param exception 异常 100 | */ 101 | public void addException(Type exception) { 102 | // 添加操作 103 | exceptions.add(exception); 104 | } 105 | 106 | /** 107 | * Description: 108 | *
109 |      * 添加方法语句.
110 |      * 
111 | * 112 | * @param statement 方法语句 113 | */ 114 | public void addStatement(String statement) { 115 | // 添加操作 116 | statements.add(statement); 117 | } 118 | 119 | /** 120 | * Description: 121 | *
122 |      * 输出方法内容.
123 |      * 
124 | * 125 | * @param indentCount 缩进次数 126 | * @return {@code java.lang.String} - 方法内容 127 | */ 128 | public String toString(int indentCount) { 129 | // 定义并初始化方法内容变量 130 | StringBuilder method = new StringBuilder(); 131 | // 添加文档注释 132 | putDocuments(method, indentCount); 133 | // 添加注解 134 | putAnnotations(method, indentCount); 135 | // 缩进 136 | TextUtils.addIndentation(method, indentCount); 137 | // 添加基本信息 138 | putInformation(method); 139 | // 添加内容 140 | putContent(method, indentCount); 141 | // 返回结果 142 | return method.toString(); 143 | } 144 | 145 | /** 146 | * Description: 147 | *
148 |      * 为方法放入基本信息.
149 |      * 
150 | * 151 | * @param method 方法 152 | */ 153 | @Override 154 | protected void putInformation(StringBuilder method) { 155 | // 添加关键字 156 | putKeyWords(method); 157 | // 添加方法名 158 | method.append(name); 159 | // 添加参数 160 | putParameters(method); 161 | // 添加异常 162 | JavaUtils.putExceptions(method, exceptions); 163 | } 164 | 165 | /** 166 | * Description: 167 | *
168 |      * 为方法放入方法体内容.
169 |      * 
170 | * 171 | * @param method 方法 172 | * @param indentCount 缩进次数 173 | */ 174 | @Override 175 | protected void putContent(StringBuilder method, Integer indentCount) { 176 | // 如果方法体为空 177 | if (statements.size() == 0) { 178 | // 添加分号 179 | method.append(";"); 180 | } else {// 如果方法体不为空 181 | // 添加空格 182 | TextUtils.addSpace(method); 183 | // 添加左花括号 184 | method.append("{"); 185 | // 增加缩进次数 186 | indentCount++; 187 | // 获取方法语句集合的迭代器 188 | ListIterator listIterator = statements.listIterator(); 189 | // 遍历方法语句集合 190 | while (listIterator.hasNext()) { 191 | // 取出语句 192 | String statement = listIterator.next(); 193 | // 如果该语句以"}"开始(例如:"}else{"). 194 | if (statement.startsWith("}")) { 195 | // 减小缩进次数 196 | indentCount--; 197 | } 198 | // 换行 199 | TextUtils.addLine(method); 200 | // 缩进 201 | TextUtils.addIndentation(method, indentCount); 202 | // 添加语句 203 | method.append(statement); 204 | // 如果该语句又开启了一个新的语句块(例如:"if(){"). 205 | if ((statement.endsWith("{") && !statement.startsWith("switch")) || statement.endsWith(":")) { 206 | // 增加缩进次数 207 | indentCount++; 208 | } 209 | // 如果该语句以"break"关键字开始 210 | if (statement.startsWith("break")) { 211 | // 如果该语句后面还有语句 212 | if (listIterator.hasNext()) { 213 | // 获取该语句后面的语句 214 | String nextStatement = listIterator.next(); 215 | // 如果后面的语句以"}"开始 216 | if (nextStatement.startsWith("}")) { 217 | // 增加缩进次数 218 | indentCount++; 219 | } 220 | // 将迭代器返回上一次所在的位置 221 | listIterator.previous(); 222 | } 223 | // 减小缩进次数 224 | indentCount--; 225 | } 226 | } 227 | // 减小缩进次数 228 | indentCount--; 229 | // 换行 230 | TextUtils.addLine(method); 231 | // 缩进 232 | TextUtils.addIndentation(method, indentCount); 233 | // 添加右花括号 234 | method.append('}'); 235 | } 236 | } 237 | 238 | /** 239 | * Description: 240 | *
241 |      * 为方法放入关键字.
242 |      * 
243 | * 244 | * @param method 方法 245 | */ 246 | private void putKeyWords(StringBuilder method) { 247 | // 如果不是接口的方法 248 | if (!isInterfaceMethod) { 249 | // 添加访问控制符 250 | putVisibility(method); 251 | // 添加静态标志 252 | putStatic(method); 253 | // 添加终结标志 254 | putFinal(method); 255 | // 如果方法体为空 256 | if (statements.size() == 0) { 257 | // 添加abstract关键字 258 | method.append("abstract"); 259 | // 添加空格 260 | TextUtils.addSpace(method); 261 | } 262 | } 263 | // 如果不是构造方法 264 | if (!isConstructor) { 265 | // 如果返回值为空 266 | if (type == null) { 267 | // 添加void关键字 268 | method.append("void"); 269 | } else {// 如果返回值不为空 270 | // 添加返回值类型 271 | method.append(type.getTypeName()); 272 | } 273 | // 添加空格 274 | TextUtils.addSpace(method); 275 | } 276 | } 277 | 278 | /** 279 | * Description: 280 | *
281 |      * 为方法放入参数信息.
282 |      * 
283 | * 284 | * @param method 方法 285 | */ 286 | private void putParameters(StringBuilder method) { 287 | // 添加左圆括号 288 | method.append("("); 289 | // 是否需要添加逗号 290 | boolean needComma = false; 291 | // 遍历参数集合 292 | for (Parameter parameter : parameters) { 293 | // 如果需要添加逗号 294 | if (needComma) { 295 | // 添加逗号 296 | method.append(","); 297 | // 添加空格 298 | TextUtils.addSpace(method); 299 | } else { 300 | // 除了第一个参数,后边的参数在添加时都需要在参数前加上逗号.. 301 | needComma = true; 302 | } 303 | // 添加参数内容 304 | method.append(parameter.toString()); 305 | } 306 | // 添加右圆括号 307 | method.append(")"); 308 | } 309 | } -------------------------------------------------------------------------------- /src/main/java/core/file/java/Parameter.java: -------------------------------------------------------------------------------- 1 | package core.file.java; 2 | 3 | import core.util.TextUtils; 4 | 5 | /** 6 | * 方法的参数. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public class Parameter extends JavaComponent { 11 | /** 12 | * 是否是不定长参数 13 | */ 14 | private boolean isVariable; 15 | 16 | /** 17 | * Description: 18 | *
 19 |      * 构造初始化参数对象.
 20 |      * 
21 | * 22 | * @param type 参数类型 23 | * @param name 参数名称 24 | * @param isVariable 是否是变长参数 25 | */ 26 | public Parameter(Type type, String name, boolean isVariable) { 27 | // 为参数属性赋值 28 | this.type = type; 29 | // 为参数名称赋值 30 | this.name = name; 31 | // 为不定长标志赋值 32 | this.isVariable = isVariable; 33 | } 34 | 35 | /** 36 | * Description: 37 | *
 38 |      * 构造初始化参数对象.
 39 |      * 
40 | * 41 | * @param type 参数类型 42 | * @param name 参数名字 43 | * @param annotation 参数注解 44 | */ 45 | public Parameter(Type type, String name, String annotation) { 46 | // 调用另外一个构造函数 47 | this(type, name, false); 48 | // 添加参数注解 49 | annotations.add(annotation); 50 | } 51 | 52 | /** 53 | * Description: 54 | *
 55 |      * 构造初始化参数对象.
 56 |      * 
57 | * 58 | * @param type 参数类型 59 | * @param name 参数名字 60 | */ 61 | public Parameter(Type type, String name) { 62 | // 调用另外一个构造函数 63 | this(type, name, false); 64 | } 65 | 66 | /** 67 | * Description: 68 | *
 69 |      * 输出参数内容.
 70 |      * 
71 | * 72 | * @return {@code java.lang.String} - 参数内容 73 | */ 74 | @Override 75 | public String toString() { 76 | // 定义并初始化参数内容变量 77 | StringBuilder parameter = new StringBuilder(); 78 | // 添加注解 79 | putAnnotations(parameter, null); 80 | // 添加内容 81 | putContent(parameter, null); 82 | // 返回参数内容 83 | return parameter.toString(); 84 | } 85 | 86 | /** 87 | * Description: 88 | *
 89 |      * 为参数放入注解(重写父类的方法).
 90 |      * 
91 | * 92 | * @param parameter 参数 93 | * @param indentCount 缩进次数 94 | */ 95 | @Override 96 | protected void putAnnotations(StringBuilder parameter, Integer indentCount) { 97 | // 循环遍历参数的注解集合 98 | for (String annotation : annotations) { 99 | // 为参数添加注解 100 | parameter.append(annotation); 101 | // 添加空格 102 | TextUtils.addSpace(parameter); 103 | } 104 | } 105 | 106 | /** 107 | * Description: 108 | *
109 |      * 为参数添加内容.
110 |      * 
111 | * 112 | * @param parameter 参数 113 | * @param indentCount 缩进次数 114 | */ 115 | @Override 116 | protected void putContent(StringBuilder parameter, Integer indentCount) { 117 | // 添加参数的类型 118 | parameter.append(type.getTypeName()); 119 | // 添加空格 120 | TextUtils.addSpace(parameter); 121 | // 如果参数是不定长的 122 | if (isVariable) { 123 | // 添加不定长关键字 124 | parameter.append("..."); 125 | // 添加空格 126 | TextUtils.addSpace(parameter); 127 | } 128 | // 添加参数名字 129 | parameter.append(name); 130 | } 131 | 132 | /** 133 | * 空方法 134 | */ 135 | @Override 136 | protected void putInformation(StringBuilder javaElement) {} 137 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/ClassGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator; 2 | 3 | import core.file.java.Class; 4 | import core.database.Table; 5 | import core.file.java.Type; 6 | import core.util.StringUtils; 7 | 8 | /** 9 | * 类生成器. 10 | * 11 | * @author 李程鹏 12 | */ 13 | public abstract class ClassGenerator extends Generator { 14 | /** 15 | * 类的类型 16 | */ 17 | protected Type classType; 18 | 19 | /** 20 | * 实现类需要实现的接口类型 21 | */ 22 | protected Type interfaceType; 23 | 24 | /** 25 | * 需要操作的实体类型名 26 | */ 27 | protected String entityTypeName; 28 | 29 | /** 30 | * Description: 31 | *
32 |      * 构造初始化生成器.
33 |      * 
34 | * 35 | * @param table 表格对象 36 | */ 37 | public ClassGenerator(Table table) { 38 | // 调用父类的构造方法 39 | super(table); 40 | // 初始化实体类型名 41 | this.entityTypeName = entityType.getTypeName(); 42 | } 43 | 44 | /** 45 | * Description: 46 | *
47 |      * 获取通用变量名.
48 |      * 
49 | * 50 | * @param suffix 自定义后缀 51 | * @return {@code java.lang.String} - 变量名 52 | */ 53 | protected String getCommonName(String suffix) { 54 | // 返回变量名 55 | return StringUtils.toCamelCase(table.getName(), false) + suffix; 56 | } 57 | 58 | /** 59 | * Description: 60 | *
61 |      * 为类导入通用类型.
62 |      * 
63 | * 64 | * @param class_ 类 65 | */ 66 | protected void addCommonImports(Class class_) { 67 | // 导入的这个包下包含@Autowired和@Qualifier 68 | class_.addImport(new Type("org.springframework.beans.factory.annotation.*")); 69 | // 导入的这个包下包含@Controller,@Service和@Repository 70 | class_.addImport(new Type("org.springframework.stereotype.*")); 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/Generator.java: -------------------------------------------------------------------------------- 1 | package core.generator; 2 | 3 | import core.database.Column; 4 | import core.database.Table; 5 | import core.file.java.*; 6 | import core.util.PackageUtils; 7 | import core.util.StringUtils; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * 生成器抽象类. 14 | * 15 | * @author 李程鹏 16 | */ 17 | public abstract class Generator { 18 | /** 19 | * 数据库表 20 | */ 21 | protected Table table; 22 | 23 | /** 24 | * 需要操作的实体类型 25 | */ 26 | protected Type entityType; 27 | 28 | /** 29 | * Description: 30 | *
 31 |      * 构造初始化生成器.
 32 |      * 
33 | * 34 | * @param table 表 35 | */ 36 | public Generator(Table table) { 37 | // 赋值 38 | this.table = table; 39 | // 初始化实体类型 40 | this.entityType = new Type(PackageUtils.ENTITY.getValue() + getTableName()); 41 | } 42 | 43 | /** 44 | * Description: 45 | *
 46 |      * 获取驼峰样式的表格名.
 47 |      * 
48 | * 49 | * @return {@code java.lang.String} - 表格名 50 | */ 51 | protected String getTableName() { 52 | // 返回大驼峰样式的表格名 53 | return StringUtils.toCamelCase(table.getName(), true); 54 | } 55 | 56 | /** 57 | * Description: 58 | *
 59 |      * 获取驼峰样式的列名.
 60 |      * 
61 | * 62 | * @param column 列对象 63 | * @return {@code java.lang.String} - 列名 64 | */ 65 | protected String getColumnName(Column column) { 66 | // 返回小驼峰样式的列名 67 | return StringUtils.toCamelCase(column.getName(), false); 68 | } 69 | 70 | /** 71 | * Description: 72 | *
 73 |      * 为属性生成文档注释.
 74 |      * 
75 | * 76 | * @param field 属性 77 | * @param document 文档注释 78 | */ 79 | protected void generateFieldDocument(Field field, String document) { 80 | // 只有文档注释不为空是才添加 81 | if (StringUtils.isNotEmpty(document)) { 82 | field.addDocument("/**"); 83 | // 将注释的前后空格去掉再添加 84 | field.addDocument(" * " + document.trim()); 85 | field.addDocument(" */"); 86 | } 87 | } 88 | 89 | /** 90 | * Description: 91 | *
 92 |      * 添加方法的文档注释.
 93 |      * 
94 | * 95 | * @param method 方法 96 | * @param statement 文档注释 97 | * @param map 属性的文档注释集合 98 | */ 99 | protected void generateMethodDocument(Method method, String statement, Map map) { 100 | method.addDocument("/**"); 101 | method.addDocument(" * " + statement); 102 | // 遍历方法中的属性 103 | for (Parameter parameter : method.getParameters()) { 104 | // 获取属性的名字 105 | String parameterName = parameter.getName(); 106 | // 添加对属性的注释 107 | method.addDocument(" * @param " + parameterName + " " + map.get(parameterName)); 108 | } 109 | method.addDocument(" */"); 110 | } 111 | 112 | /** 113 | * Description: 114 | *
115 |      * 添加文件文档注释.
116 |      * 
117 | * 118 | * @param javaFile java文件 119 | * @param document 文档注释 120 | */ 121 | protected void generateFileDocument(JavaFile javaFile, String document) { 122 | javaFile.addDocument("/**"); 123 | // 如果注释不为空 124 | if (StringUtils.isNotEmpty(document)) { 125 | // 添加去掉前后空格的注释 126 | javaFile.addDocument(" * " + document.trim()); 127 | javaFile.addDocument(" * "); 128 | } 129 | // 添加文件编写作者 130 | javaFile.addDocument(" * @author 李程鹏"); 131 | javaFile.addDocument(" */"); 132 | } 133 | 134 | /** 135 | * Description: 136 | *
137 |      * 生成代码.
138 |      * 
139 | * 140 | * @return {@code java.lang.Object} - 生成的代码字符串 141 | */ 142 | protected abstract Object generate(); 143 | 144 | /** 145 | * Description: 146 | *
147 |      * 生成注释(这个方法不通用,只是为了减少冗余代码而抽取出来的).
148 |      * 
149 | * 150 | * @param method 方法 151 | * @param methodDoc 方法的文档注释 152 | * @param paramName 参数名 153 | * @param paramDoc 参数的文档注释 154 | */ 155 | protected void generateDocument(Method method, String methodDoc, String paramName, String paramDoc) { 156 | // 新建一个映射对象 157 | Map map = new HashMap<>(); 158 | // 将参数名和参数的注释映射关联起来 159 | map.put(paramName, paramDoc); 160 | // 添加方法的文档注释 161 | generateMethodDocument(method, methodDoc, map); 162 | } 163 | 164 | /** 165 | * Description: 166 | *
167 |      * 放入增加方法的基本信息.
168 |      * 
169 | * 170 | * @param method 方法 171 | */ 172 | protected void putAddMethodInfo(Method method) { 173 | // 设置访问控制符 174 | method.setVisibility("public "); 175 | // 设置方法名 176 | method.setName("addEntity"); 177 | // 定义参数名 178 | String parameterName = "entity"; 179 | // 新建一个参数 180 | Parameter parameter = new Parameter(entityType, parameterName); 181 | // 为方法添加参数 182 | method.addParameter(parameter); 183 | // 添加方法注释 184 | generateDocument(method, "增加实体对象", parameterName, "实体"); 185 | } 186 | 187 | /** 188 | * Description: 189 | *
190 |      * 放入删除方法的基本信息.
191 |      * 
192 | * 193 | * @param method 方法 194 | */ 195 | protected void putDeleteMethodInfo(Method method) { 196 | // 设置访问控制符 197 | method.setVisibility("public "); 198 | // 设置方法名 199 | method.setName("deleteEntity"); 200 | // 定义参数名 201 | String parameterName = "id"; 202 | // 新建一个参数 203 | Parameter parameter = new Parameter(new Type("int"), parameterName); 204 | // 为方法添加参数 205 | method.addParameter(parameter); 206 | // 添加方法注释 207 | generateDocument(method, "根据主键删除实体对象", parameterName, "主键"); 208 | } 209 | 210 | /** 211 | * Description: 212 | *
213 |      * 放入修改方法的基本信息.
214 |      * 
215 | * 216 | * @param method 方法 217 | */ 218 | protected void putUpdateMethodInfo(Method method) { 219 | // 设置访问控制符 220 | method.setVisibility("public "); 221 | // 设置方法名 222 | method.setName("updateEntity"); 223 | // 定义参数名 224 | String parameterName = "entity"; 225 | // 新建一个参数 226 | Parameter parameter = new Parameter(entityType, parameterName); 227 | // 为方法添加参数 228 | method.addParameter(parameter); 229 | // 添加方法注释 230 | generateDocument(method, "修改实体对象", parameterName, "实体"); 231 | } 232 | 233 | /** 234 | * Description: 235 | *
236 |      * 放入查询方法(按主键查)的基本信息.
237 |      * 
238 | * 239 | * @param method 方法 240 | */ 241 | protected void putReadOneMethodInfo(Method method) { 242 | // 设置访问控制符 243 | method.setVisibility("public "); 244 | // 设置方法名 245 | method.setName("readEntity"); 246 | // 设置方法的返回值类型 247 | method.setType(entityType); 248 | // 定义参数名 249 | String parameterName = "id"; 250 | // 新建一个参数 251 | Parameter parameter = new Parameter(new Type("int"), parameterName); 252 | // 为方法添加参数 253 | method.addParameter(parameter); 254 | // 添加方法注释 255 | generateDocument(method, "根据主键查询实体对象", parameterName, "主键"); 256 | } 257 | 258 | /** 259 | * Description: 260 | *
261 |      * 放入查询方法(查询所有)的基本信息.
262 |      * 
263 | * 264 | * @param method 方法 265 | */ 266 | protected void putReadAllMethodInfo(Method method) { 267 | // 设置访问控制符 268 | method.setVisibility("public "); 269 | // 设置方法名 270 | method.setName("readEntities"); 271 | // 定义方法返回值类型 272 | Type returnType = new Type("java.util.List"); 273 | // 设置返回值类型中的泛型参数 274 | returnType.addTypeArgument(entityType); 275 | // 为方法设置返回值类型 276 | method.setType(returnType); 277 | // 添加方法注释 278 | generateMethodDocument(method, "查询所有实体对象", null); 279 | } 280 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/InterfaceGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator; 2 | 3 | import core.database.Table; 4 | import core.file.java.Interface; 5 | import core.file.java.Method; 6 | import core.file.java.Type; 7 | 8 | /** 9 | * 接口生成器. 10 | * 11 | * @author 李程鹏 12 | */ 13 | public class InterfaceGenerator extends Generator { 14 | /** 15 | * 接口类型(接口名). 16 | */ 17 | protected Type interfaceType; 18 | 19 | /** 20 | * 接口文件注释 21 | */ 22 | protected String comment; 23 | 24 | /** 25 | * Description: 26 | *
 27 |      * 构造初始化生成器.
 28 |      * 
29 | * 30 | * @param table 表格对象 31 | */ 32 | public InterfaceGenerator(Table table) { 33 | // 调用父类的构造函数 34 | super(table); 35 | } 36 | 37 | /** 38 | * Description: 39 | *
 40 |      * 生成代码.
 41 |      * 
42 | * 43 | * @return {@code core.file.java.Interface} - 生成的接口类. 44 | */ 45 | @Override 46 | public Interface generate() { 47 | // 新建一个接口 48 | Interface interface_ = new Interface(); 49 | // 设置接口的文档注释 50 | generateFileDocument(interface_, comment); 51 | // 设置设置访问控制符 52 | interface_.setVisibility("public "); 53 | // 设置接口的类型 54 | interface_.setType(interfaceType); 55 | // 为接口生成添加方法 56 | generateAddMethod(interface_); 57 | // 为接口生成删除方法 58 | generateDeleteMethod(interface_); 59 | // 为接口生成修改方法 60 | generateUpdateMethod(interface_); 61 | // 为接口生成查询方法(按主键查). 62 | generateReadOneMethod(interface_); 63 | // 为接口生成查询方法(查询所有). 64 | generateReadAllMethod(interface_); 65 | // 为接口导入实体类型 66 | interface_.addImport(entityType); 67 | // 返回接口 68 | return interface_; 69 | } 70 | 71 | /** 72 | * Description: 73 | *
 74 |      * 为接口生成增加方法.
 75 |      * 
76 | * 77 | * @param interface_ 接口 78 | */ 79 | private void generateAddMethod(Interface interface_) { 80 | // 新建一个方法 81 | Method method = new Method(); 82 | // 放入增加方法的基本信息 83 | putAddMethodInfo(method); 84 | // 为接口添加该方法 85 | interface_.addMethod(method); 86 | } 87 | 88 | /** 89 | * Description: 90 | *
 91 |      * 为接口生成删除方法.
 92 |      * 
93 | * 94 | * @param interface_ 接口 95 | */ 96 | private void generateDeleteMethod(Interface interface_) { 97 | // 新建一个方法 98 | Method method = new Method(); 99 | // 放入删除方法的基本信息 100 | putDeleteMethodInfo(method); 101 | // 获取方法的参数类型 102 | Type parameterType = method.getParameters().get(0).getType(); 103 | // 为接口导入参数类型 104 | interface_.addImport(parameterType); 105 | // 为接口添加该方法 106 | interface_.addMethod(method); 107 | } 108 | 109 | /** 110 | * Description: 111 | *
112 |      * 为接口生成修改方法.
113 |      * 
114 | * 115 | * @param interface_ 接口 116 | */ 117 | private void generateUpdateMethod(Interface interface_) { 118 | // 新建一个方法 119 | Method method = new Method(); 120 | // 放入修改方法的基本信息 121 | putUpdateMethodInfo(method); 122 | // 为接口添加该方法 123 | interface_.addMethod(method); 124 | } 125 | 126 | /** 127 | * Description: 128 | *
129 |      * 为接口生成查询方法(按主键查).
130 |      * 
131 | * 132 | * @param interface_ 接口 133 | */ 134 | private void generateReadOneMethod(Interface interface_) { 135 | // 新建一个方法 136 | Method method = new Method(); 137 | // 放入查询方法(按主键查)的基本信息 138 | putReadOneMethodInfo(method); 139 | // 获取方法的参数类型 140 | Type parameterType = method.getParameters().get(0).getType(); 141 | // 为接口导入参数类型 142 | interface_.addImport(parameterType); 143 | // 为接口添加该方法 144 | interface_.addMethod(method); 145 | } 146 | 147 | /** 148 | * Description: 149 | *
150 |      * 为接口生成查询方法(查询所有).
151 |      * 
152 | * 153 | * @param interface_ 接口 154 | */ 155 | private void generateReadAllMethod(Interface interface_) { 156 | // 新建一个方法 157 | Method method = new Method(); 158 | // 放入查询方法(查询所有)的基本信息 159 | putReadAllMethodInfo(method); 160 | // 为接口添加需要导入的返回值类型 161 | interface_.addImport(method.getType()); 162 | // 为接口添加该方法 163 | interface_.addMethod(method); 164 | } 165 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/SwaggerUIGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator; 2 | 3 | import core.util.FileUtils; 4 | import core.util.NameUtils; 5 | import core.util.PathUtils; 6 | 7 | /** 8 | * SwaggerUI文件生成器. 9 | * 10 | * @author 李程鹏 11 | */ 12 | public class SwaggerUIGenerator { 13 | /** 14 | * Description: 15 | *
16 |      * 生成SwaggerUI.实际上就是将本工程下准备好的UI文件拷贝到新生成的工程下.
17 |      * 
18 | */ 19 | public void generate() { 20 | // 获取本工程下准备好的UI文件路径 21 | String from = PathUtils.PROJECT.getValue() + PathUtils.SWAGGER_UI_FROM.getValue(); 22 | // 获取新生成工程的项目路径 23 | String projectPath = "\\" + NameUtils.PROJECT.getValue(); 24 | // 获取UI文件在新工程下的目的路径 25 | String to = PathUtils.DESKTOP.getValue() + projectPath + PathUtils.SWAGGER_UI_TO.getValue(); 26 | // 将所有UI文件拷贝过去 27 | FileUtils.copyDirectory(from, to); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/config/AbstractConfigGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.config; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 配置文件生成器抽象类. 8 | * 9 | * @author 李程鹏 10 | */ 11 | public abstract class AbstractConfigGenerator { 12 | /** 13 | * 数据映射对象 14 | */ 15 | protected Map data = new HashMap<>(); 16 | 17 | /** 18 | * Description: 19 | *
20 |      * 为数据映射对象放入数据.
21 |      * 
22 | */ 23 | protected abstract void putData(); 24 | 25 | /** 26 | * Description: 27 | *
28 |      * 生成配置文件.
29 |      * 
30 | */ 31 | protected abstract void generate() throws Exception; 32 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/config/ConfigGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.config; 2 | 3 | /** 4 | * 配置文件生成器. 5 | * 6 | * @author 李程鹏 7 | */ 8 | public class ConfigGenerator { 9 | /** 10 | * 数据库 11 | */ 12 | private String database; 13 | 14 | /** 15 | * 账户名 16 | */ 17 | private String username; 18 | 19 | /** 20 | * 密码 21 | */ 22 | private String password; 23 | 24 | /** 25 | * Description: 26 | *
27 |      * 构造初始化生成器.
28 |      * 
29 | * 30 | * @param database 数据库 31 | * @param username 账户名 32 | * @param password 密码 33 | */ 34 | public ConfigGenerator(String database, String username, String password) { 35 | // 赋值 36 | this.database = database; 37 | // 赋值 38 | this.username = username; 39 | // 赋值 40 | this.password = password; 41 | } 42 | 43 | /** 44 | * Description: 45 | *
46 |      * 生成配置文件.
47 |      * 
48 | */ 49 | public void generate() throws Exception { 50 | // 生成SpringMVC配置文件 51 | new SpringMVCConfigGenerator().generate(); 52 | // 生成Spring配置文件 53 | new SpringConfigGenerator().generate(); 54 | // 生成Hibernate配置文件 55 | new HibernateConfigGenerator(database, username, password).generate(); 56 | // 生成web.xml 57 | new WebXmlGenerator().generate(); 58 | // 生成pom.xml 59 | new PomGenerator().generate(); 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/config/HibernateConfigGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.config; 2 | 3 | import core.util.*; 4 | 5 | /** 6 | * Hibernate配置文件生成器. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public class HibernateConfigGenerator extends AbstractConfigGenerator { 11 | /** 12 | * 数据库 13 | */ 14 | private String database; 15 | 16 | /** 17 | * 账户名 18 | */ 19 | private String username; 20 | 21 | /** 22 | * 密码 23 | */ 24 | private String password; 25 | 26 | /** 27 | * Description: 28 | *
29 |      * 构造初始化生成器.
30 |      * 
31 | * 32 | * @param database 数据库 33 | * @param username 账户名 34 | * @param password 密码 35 | */ 36 | public HibernateConfigGenerator(String database, String username, String password) { 37 | // 赋值 38 | this.database = database; 39 | // 赋值 40 | this.username = username; 41 | // 赋值 42 | this.password = password; 43 | } 44 | 45 | /** 46 | * Description: 47 | *
48 |      * 为数据映射对象放入数据.
49 |      * 
50 | */ 51 | protected void putData() { 52 | // 获取实体对象所在的包名 53 | String entityPackage = StringUtils.removeLastDot(PackageUtils.ENTITY.getValue()); 54 | // 获取Dao层所在的包名 55 | String daoPackage = StringUtils.removeLastDot(PackageUtils.DAO.getValue()); 56 | // 放入实体对象包名 57 | data.put("entityPackage", entityPackage); 58 | // 放入Dao层包名 59 | data.put("daoPackage", daoPackage); 60 | // 放入数据库信息 61 | data.put("database", database); 62 | // 放入用户名 63 | data.put("username", username); 64 | // 放入密码 65 | data.put("password", password); 66 | } 67 | 68 | /** 69 | * Description: 70 | *
71 |      * 生成配置文件.
72 |      * 
73 | */ 74 | protected void generate() throws Exception { 75 | // 为数据映射对象放入数据 76 | putData(); 77 | // 获取Hibernate配置文件的文件名 78 | String fileName = NameUtils.HIBERNATE_CONFIG.getValue(); 79 | // 获取Hibernate配置文件生成的相对路径 80 | String relativePath = PathUtils.HIBERNATE_CONFIG.getValue(); 81 | // 使用模板引擎生成配置文件 82 | FreeMarkerUtils.generateFile(fileName, relativePath, data); 83 | } 84 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/config/PomGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.config; 2 | 3 | import core.util.*; 4 | 5 | /** 6 | * pom.xml生成器. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public class PomGenerator extends AbstractConfigGenerator { 11 | /** 12 | * Description: 13 | *
14 |      * 为数据映射对象放入数据.
15 |      * 
16 | */ 17 | protected void putData() { 18 | // 放入项目名 19 | data.put("projectName", NameUtils.PROJECT.getValue()); 20 | } 21 | 22 | /** 23 | * Description: 24 | *
25 |      * 生成配置文件.
26 |      * 
27 | */ 28 | protected void generate() throws Exception { 29 | // 为数据映射对象放入数据 30 | putData(); 31 | // 获取配置文件名 32 | String fileName = NameUtils.POM_XML.getValue(); 33 | // 使用模板引擎生成配置文件 34 | FreeMarkerUtils.generateFile(fileName, "\\", data); 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/config/SpringConfigGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.config; 2 | 3 | import core.util.*; 4 | 5 | /** 6 | * Spring配置文件生成器. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public class SpringConfigGenerator extends AbstractConfigGenerator { 11 | /** 12 | * Description: 13 | *
14 |      * 为数据映射对象放入数据.
15 |      * 
16 | */ 17 | protected void putData() { 18 | // 获取Service层所在的包名 19 | String servicePackage = StringUtils.removeLastDot(PackageUtils.SERVICE.getValue()); 20 | // 放入Service层包名 21 | data.put("servicePackage", servicePackage); 22 | } 23 | 24 | /** 25 | * Description: 26 | *
27 |      * 生成配置文件.
28 |      * 
29 | */ 30 | protected void generate() throws Exception { 31 | // 为数据映射对象放入数据 32 | putData(); 33 | // 获取Spring配置文件的文件名 34 | String fileName = NameUtils.SPRING_CONFIG.getValue(); 35 | // 获取Spring配置文件生成的相对路径 36 | String relativePath = PathUtils.SPRING_CONFIG.getValue(); 37 | // 使用模板引擎生成配置文件 38 | FreeMarkerUtils.generateFile(fileName, relativePath, data); 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/config/SpringMVCConfigGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.config; 2 | 3 | import core.util.*; 4 | 5 | /** 6 | * SpringMVC配置文件生成器. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public class SpringMVCConfigGenerator extends AbstractConfigGenerator { 11 | /** 12 | * Description: 13 | *
14 |      * 为数据映射对象放入数据.
15 |      * 
16 | */ 17 | protected void putData() { 18 | // 获取Controller层所在的包名 19 | String controllerPackage = StringUtils.removeLastDot(PackageUtils.CONTROLLER.getValue()); 20 | // 放入Controller层的包名 21 | data.put("controllerPackage", controllerPackage); 22 | } 23 | 24 | /** 25 | * Description: 26 | *
27 |      * 生成配置文件.
28 |      * 
29 | */ 30 | protected void generate() throws Exception { 31 | // 为数据映射对象放入数据 32 | putData(); 33 | // 获取SpringMVC配置文件的文件名 34 | String fileName = NameUtils.SPRING_MVC_CONFIG.getValue(); 35 | // 获取SpringMVC配置文件生成的相对路径 36 | String relativePath = PathUtils.SPRING_MVC_CONFIG.getValue(); 37 | // 使用模板引擎生成配置文件 38 | FreeMarkerUtils.generateFile(fileName, relativePath, data); 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/config/WebXmlGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.config; 2 | 3 | import core.util.FreeMarkerUtils; 4 | import core.util.NameUtils; 5 | import core.util.PathUtils; 6 | 7 | /** 8 | * web.xml生成器. 9 | * 10 | * @author 李程鹏 11 | */ 12 | public class WebXmlGenerator extends AbstractConfigGenerator { 13 | /** 14 | * Description: 15 | *
16 |      * 为数据映射对象放入数据.
17 |      * 
18 | */ 19 | protected void putData() { 20 | // 放入SpringMVC配置文件的文件名 21 | data.put("springMVCConfig", NameUtils.SPRING_MVC_CONFIG.getValue()); 22 | // 放入Spring配置文件的文件名 23 | data.put("springConfig", NameUtils.SPRING_CONFIG.getValue()); 24 | // 放入Hibernate配置文件的文件名 25 | data.put("hibernateConfig", NameUtils.HIBERNATE_CONFIG.getValue()); 26 | } 27 | 28 | /** 29 | * Description: 30 | *
31 |      * 生成配置文件.
32 |      * 
33 | */ 34 | protected void generate() throws Exception { 35 | // 为数据映射对象放入数据 36 | putData(); 37 | // 获取配置文件的文件名 38 | String fileName = NameUtils.WEB_XML.getValue(); 39 | // 获取配置文件生成的相对路径 40 | String relativePath = PathUtils.WEB_XML.getValue(); 41 | // 使用模板引擎生成配置文件 42 | FreeMarkerUtils.generateFile(fileName, relativePath, data); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/controller/ControllerGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.controller; 2 | 3 | import core.file.java.*; 4 | import core.database.Table; 5 | import core.file.java.Class; 6 | import core.generator.ClassGenerator; 7 | import core.util.PackageUtils; 8 | 9 | /** 10 | * Controller类生成器. 11 | * 12 | * @author 李程鹏 13 | */ 14 | public class ControllerGenerator extends ClassGenerator { 15 | /** 16 | * Service层接口的类型 17 | */ 18 | private Type serviceType; 19 | 20 | /** 21 | * Service层接口的名字 22 | */ 23 | private String serviceName; 24 | 25 | /** 26 | * Description: 27 | *
 28 |      * 构造初始化生成器.
 29 |      * 
30 | * 31 | * @param table 表格对象 32 | */ 33 | public ControllerGenerator(Table table) { 34 | // 调用父类的构造函数 35 | super(table); 36 | // 初始化类的类型 37 | this.classType = new Type(PackageUtils.CONTROLLER.getValue() + getTableName() + "Controller"); 38 | // 初始化Service层接口的类型 39 | this.serviceType = new Type(PackageUtils.SERVICE.getValue() + getTableName() + "Service"); 40 | // 初始化Service层接口的名字 41 | this.serviceName = getCommonName("Service"); 42 | } 43 | 44 | /** 45 | * Description: 46 | *
 47 |      * 生成代码.
 48 |      * 
49 | * 50 | * @return {@code core.file.java.Class} - 生成的Controller类. 51 | */ 52 | @Override 53 | public Class generate() { 54 | // 新建一个类 55 | Class class_ = new Class(); 56 | // 生成类的文档注释 57 | generateFileDocument(class_, "操作" + table.getRemark() + "对象的控制层代码"); 58 | // 添加类的注解 59 | class_.addAnnotation("@Controller"); 60 | class_.addAnnotation("@RequestMapping(\"/" + getCommonName("") + "\")"); 61 | // 设置访问控制符 62 | class_.setVisibility("public "); 63 | // 设置类的类型 64 | class_.setType(classType); 65 | // 为类生成属性 66 | generateField(class_); 67 | // 为类生成增加方法 68 | generateAddMethod(class_); 69 | // 为类生成删除方法 70 | generateDeleteMethod(class_); 71 | // 为类生成修改方法 72 | generateUpdateMethod(class_); 73 | // 为类生成查询方法(按主键查). 74 | generateReadOneMethod(class_); 75 | // 为类生成查询方法(查询所有). 76 | generateReadAllMethod(class_); 77 | // 添加类需要导入的类型 78 | addImports(class_); 79 | // 返回生成的Controller类 80 | return class_; 81 | } 82 | 83 | /** 84 | * Description: 85 | *
 86 |      * 添加类需要导入的类型.
 87 |      * 
88 | * 89 | * @param class_ 类 90 | */ 91 | private void addImports(Class class_) { 92 | // 为类导入通用类型 93 | addCommonImports(class_); 94 | // 导入接口的类型 95 | class_.addImport(serviceType); 96 | // 导入实体类型 97 | class_.addImport(entityType); 98 | // 导入的这个包下包含@RequestMapping,@ResponseBody和@PathVariable 99 | class_.addImport(new Type("org.springframework.web.bind.annotation.*")); 100 | } 101 | 102 | /** 103 | * Description: 104 | *
105 |      * 为类生成属性.
106 |      * 
107 | * 108 | * @param class_ 类 109 | */ 110 | private void generateField(Class class_) { 111 | // 新建一个属性 112 | Field field = new Field(); 113 | // 为属性添加文档注释 114 | generateFieldDocument(field, "业务层接口"); 115 | // 为属性添加注解 116 | field.addAnnotation("@Autowired"); 117 | field.addAnnotation("@Qualifier(\"" + serviceName + "\")"); 118 | // 设置访问控制符 119 | field.setVisibility("private "); 120 | // 设置属性的类型 121 | field.setType(serviceType); 122 | // 设置属性名 123 | field.setName(serviceName); 124 | // 为类添加属性 125 | class_.addField(field); 126 | } 127 | 128 | /** 129 | * Description: 130 | *
131 |      * 为类生成增加方法.
132 |      * 
133 | * 134 | * @param class_ 类 135 | */ 136 | private void generateAddMethod(Class class_) { 137 | // 新建一个方法 138 | Method method = new Method(); 139 | // 放入增加方法的基本信息 140 | putAddMethodInfo(method); 141 | // 为方法添加注解 142 | method.addAnnotation("@RequestMapping(value = \"/add\", method = RequestMethod.POST)"); 143 | method.addAnnotation("@ResponseBody"); 144 | // 设置方法的返回值 145 | method.setType(new Type("java.lang.String")); 146 | // 为方法的参数添加注解 147 | method.getParameters().get(0).addAnnotation("@RequestBody"); 148 | // 添加方法语句 149 | method.addStatement("// 调用业务层接口添加实体对象"); 150 | method.addStatement(serviceName + ".addEntity(entity);"); 151 | method.addStatement("// 返回增加操作结果"); 152 | method.addStatement("return \"Add success!\";"); 153 | // 为类添加方法 154 | class_.addMethod(method); 155 | } 156 | 157 | /** 158 | * Description: 159 | *
160 |      * 为类生成删除方法.
161 |      * 
162 | * 163 | * @param class_ 类 164 | */ 165 | private void generateDeleteMethod(Class class_) { 166 | // 新建一个方法 167 | Method method = new Method(); 168 | // 放入删除方法的基本信息 169 | putDeleteMethodInfo(method); 170 | // 为方法添加注解 171 | method.addAnnotation("@RequestMapping(value = \"/delete/{id}\", method = RequestMethod.GET)"); 172 | method.addAnnotation("@ResponseBody"); 173 | // 设置方法的返回值 174 | method.setType(new Type("java.lang.String")); 175 | // 为方法参数添加注解 176 | method.getParameters().get(0).addAnnotation("@PathVariable"); 177 | // 添加方法语句 178 | method.addStatement("// 调用业务层接口删除实体对象"); 179 | method.addStatement(serviceName + ".deleteEntity(id);"); 180 | method.addStatement("// 返回删除操作结果"); 181 | method.addStatement("return \"Delete success!\";"); 182 | // 为类添加方法 183 | class_.addMethod(method); 184 | } 185 | 186 | /** 187 | * Description: 188 | *
189 |      * 为类生成修改方法.
190 |      * 
191 | * 192 | * @param class_ 类 193 | */ 194 | private void generateUpdateMethod(Class class_) { 195 | // 新建一个方法 196 | Method method = new Method(); 197 | // 放入修改方法的基本信息 198 | putUpdateMethodInfo(method); 199 | // 为方法添加注解 200 | method.addAnnotation("@RequestMapping(value = \"/update\", method = RequestMethod.POST)"); 201 | method.addAnnotation("@ResponseBody"); 202 | // 设置方法的返回值 203 | method.setType(new Type("java.lang.String")); 204 | // 为方法参数添加注解 205 | method.getParameters().get(0).addAnnotation("@RequestBody"); 206 | // 添加方法语句 207 | method.addStatement("// 调用业务层接口修改实体对象"); 208 | method.addStatement(serviceName + ".updateEntity(entity);"); 209 | method.addStatement("// 返回修改操作结果"); 210 | method.addStatement("return \"Update success!\";"); 211 | // 为类添加方法 212 | class_.addMethod(method); 213 | } 214 | 215 | /** 216 | * Description: 217 | *
218 |      * 为类生成查询方法(按主键查).
219 |      * 
220 | * 221 | * @param class_ 类 222 | */ 223 | private void generateReadOneMethod(Class class_) { 224 | // 新建一个方法 225 | Method method = new Method(); 226 | // 放入查询方法的基本信息 227 | putReadOneMethodInfo(method); 228 | // 为方法参数添加注解 229 | method.getParameters().get(0).addAnnotation("@PathVariable"); 230 | // 为方法添加注解 231 | method.addAnnotation("@RequestMapping(value = \"/read/{id}\", method = RequestMethod.GET)"); 232 | method.addAnnotation("@ResponseBody"); 233 | // 添加注释 234 | method.addStatement("// 调用业务层接口查询实体对象"); 235 | // 添加方法语句 236 | method.addStatement("return " + serviceName + ".readEntity(id);"); 237 | // 为类添加方法 238 | class_.addMethod(method); 239 | } 240 | 241 | /** 242 | * Description: 243 | *
244 |      * 为类生成查询方法(查询所有).
245 |      * 
246 | * 247 | * @param class_ 类 248 | */ 249 | private void generateReadAllMethod(Class class_) { 250 | // 新建一个方法 251 | Method method = new Method(); 252 | // 放入查询方法的基本信息 253 | putReadAllMethodInfo(method); 254 | // 为方法添加注解 255 | method.addAnnotation("@RequestMapping(value = \"/read\", method = RequestMethod.GET)"); 256 | method.addAnnotation("@ResponseBody"); 257 | // 添加注释 258 | method.addStatement("// 调用业务层接口查询实体对象集合"); 259 | // 添加方法语句 260 | method.addStatement("return " + serviceName + ".readEntities();"); 261 | // 为类导入返回值类型 262 | class_.addImport(method.getType()); 263 | // 为类添加方法 264 | class_.addMethod(method); 265 | } 266 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/controller/SpringMVCGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.controller; 2 | 3 | import core.file.java.Class; 4 | import core.database.Table; 5 | import core.util.FileUtils; 6 | import core.util.PathUtils; 7 | import core.util.StringUtils; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * SpringMVC控制层代码生成器. 13 | * 14 | * @author 李程鹏 15 | */ 16 | public class SpringMVCGenerator { 17 | /** 18 | * 表格集合 19 | */ 20 | private List
tables; 21 | 22 | /** 23 | * Description: 24 | *
25 |      * 构造实例化生成器.
26 |      * 
27 | * 28 | * @param tables 表格集合 29 | */ 30 | public SpringMVCGenerator(List
tables) { 31 | // 赋值 32 | this.tables = tables; 33 | } 34 | 35 | /** 36 | * Description: 37 | *
38 |      * 生成代码.
39 |      * 
40 | */ 41 | public void generate() throws Exception { 42 | // 遍历表格集合 43 | for (Table table : tables) { 44 | // 获取生成的类 45 | Class controller = new ControllerGenerator(table).generate(); 46 | // 根据类的内容生成文件 47 | FileUtils.generateFile(PathUtils.CONTROLLER.getValue(), StringUtils.getJavaFileName(controller), controller.toString(0)); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/dao/DaoGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.dao; 2 | 3 | import core.database.Table; 4 | import core.file.java.Type; 5 | import core.generator.InterfaceGenerator; 6 | import core.util.PackageUtils; 7 | 8 | /** 9 | * Dao层接口生成器. 10 | * 11 | * @author 李程鹏 12 | */ 13 | public class DaoGenerator extends InterfaceGenerator { 14 | /** 15 | * Description: 16 | *
17 |      * 构造实例化生成器.
18 |      * 
19 | * 20 | * @param table 表格对象 21 | */ 22 | public DaoGenerator(Table table) { 23 | // 调用父类的构造方法 24 | super(table); 25 | // 实例化Dao层接口的类型 26 | this.interfaceType = new Type(PackageUtils.DAO.getValue() + getTableName() + "Dao"); 27 | // 设置Dao接口的文档注释 28 | this.comment = "持久层接口"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/core/generator/dao/DaoImplGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.dao; 2 | 3 | import core.database.Table; 4 | import core.file.java.*; 5 | import core.file.java.Class; 6 | import core.generator.ClassGenerator; 7 | import core.util.PackageUtils; 8 | 9 | /** 10 | * Dao层实现类生成器. 11 | * 12 | * @author 李程鹏 13 | */ 14 | public class DaoImplGenerator extends ClassGenerator { 15 | /** 16 | * 代码中使用的会话工厂类型 17 | */ 18 | private Type sessionFactoryType; 19 | 20 | /** 21 | * 公用的注释 22 | */ 23 | private String commonStatement; 24 | 25 | /** 26 | * 公用的语句 27 | */ 28 | private String commonComment; 29 | 30 | /** 31 | * Description: 32 | *
 33 |      * 构造实例化生成器对象.
 34 |      * 
35 | * 36 | * @param table 表格对象 37 | */ 38 | public DaoImplGenerator(Table table) { 39 | // 调用父类的构造函数 40 | super(table); 41 | // 初始化类的类型 42 | this.classType = new Type(PackageUtils.DAO_IMPL.getValue() + getTableName() + "DaoImpl"); 43 | // 初始化接口类型 44 | this.interfaceType = new Type(PackageUtils.DAO.getValue() + getTableName() + "Dao"); 45 | // 初始化会话工厂类型 46 | this.sessionFactoryType = new Type("org.hibernate.SessionFactory"); 47 | // 初始化公用注释 48 | this.commonComment = "// 获取会话对象"; 49 | // 初始化公用语句 50 | this.commonStatement = "Session session = sessionFactory.getCurrentSession();"; 51 | } 52 | 53 | /** 54 | * Description: 55 | *
 56 |      * 生成代码.
 57 |      * 
58 | * 59 | * @return {@code core.file.java.Class} - 生成的Dao层实现类. 60 | */ 61 | @Override 62 | public Class generate() { 63 | // 新建一个类 64 | Class class_ = new Class(); 65 | // 设置类的文档注释 66 | generateFileDocument(class_, "操作" + table.getRemark() + "对象的持久层代码"); 67 | // 添加类的注解 68 | class_.addAnnotation("@Repository(\"" + getCommonName("Dao") + "\")"); 69 | // 设置类的访问控制符 70 | class_.setVisibility("public "); 71 | // 设置类的类型 72 | class_.setType(classType); 73 | // 为类生成属性 74 | generateField(class_); 75 | // 为类生成构造方法 76 | generateConstructor(class_); 77 | // 为类生成增加方法 78 | generateAddMethod(class_); 79 | // 为类生成删除方法 80 | generateDeleteMethod(class_); 81 | // 为类生成修改方法 82 | generateUpdateMethod(class_); 83 | // 为类生成查询方法(按主键查). 84 | generateReadOneMethod(class_); 85 | // 为类生成查询方法(查询所有). 86 | generateReadAllMethod(class_); 87 | // 添加类需要实现的接口 88 | class_.addImplementedInterface(interfaceType); 89 | // 添加类需要导入的类型 90 | addImports(class_); 91 | // 返回生成的类 92 | return class_; 93 | } 94 | 95 | /** 96 | * Description: 97 | *
 98 |      * 添加类需要导入的类型
 99 |      * 
100 | * 101 | * @param class_ 类 102 | */ 103 | private void addImports(Class class_) { 104 | // 导入通用类型 105 | addCommonImports(class_); 106 | // 导入接口类型 107 | class_.addImport(interfaceType); 108 | // 导入实体类型 109 | class_.addImport(entityType); 110 | // 导入会话工厂类型 111 | class_.addImport(sessionFactoryType); 112 | // 导入会话类型 113 | class_.addImport(new Type("org.hibernate.Session")); 114 | // 导入条件对象类型 115 | class_.addImport(new Type("org.hibernate.Criteria")); 116 | } 117 | 118 | /** 119 | * Description: 120 | *
121 |      * 为类生成属性.
122 |      * 
123 | * 124 | * @param class_ 类 125 | */ 126 | private void generateField(Class class_) { 127 | // 新建一个属性 128 | Field field = new Field(); 129 | // 添加属性的文档注释 130 | generateFieldDocument(field, "会话工厂"); 131 | // 设置访问控制符 132 | field.setVisibility("private "); 133 | // 设置终结标志 134 | field.setFinal(true); 135 | // 设置属性的类型 136 | field.setType(sessionFactoryType); 137 | // 设置属性名 138 | field.setName("sessionFactory"); 139 | // 为类添加属性 140 | class_.addField(field); 141 | } 142 | 143 | /** 144 | * Description: 145 | *
146 |      * 为类生成构造方法.
147 |      * 
148 | * 149 | * @param class_ 类 150 | */ 151 | private void generateConstructor(Class class_) { 152 | // 新建一个方法 153 | Method method = new Method(); 154 | // 添加注解 155 | method.addAnnotation("@Autowired"); 156 | // 设置访问控制符 157 | method.setVisibility("public "); 158 | // 设置构造函数标志 159 | method.setConstructor(true); 160 | // 设置方法名 161 | method.setName(classType.getTypeName()); 162 | // 定义参数名字 163 | String parameterName = "sessionFactory"; 164 | // 定义一个参数 165 | Parameter parameter = new Parameter(sessionFactoryType, parameterName); 166 | // 为参数添加注解 167 | parameter.addAnnotation("@Qualifier(\"sessionFactory\")"); 168 | // 为方法添加参数 169 | method.addParameter(parameter); 170 | // 添加方法语句 171 | method.addStatement("// 为属性赋值"); 172 | method.addStatement("this.sessionFactory = sessionFactory;"); 173 | // 为方法添加文档注释 174 | generateDocument(method, "构造注入会话工厂对象", parameterName, "会话工厂"); 175 | // 为类添加方法 176 | class_.addMethod(method); 177 | } 178 | 179 | /** 180 | * Description: 181 | *
182 |      * 为类生成增加方法.
183 |      * 
184 | * 185 | * @param class_ 类 186 | */ 187 | private void generateAddMethod(Class class_) { 188 | // 新建一个方法 189 | Method method = new Method(); 190 | // 放入增加方法的基本信息 191 | putAddMethodInfo(method); 192 | // 添加方法语句 193 | method.addStatement(commonComment); 194 | method.addStatement(commonStatement); 195 | method.addStatement("// 添加实体对象"); 196 | method.addStatement("session.save(entity);"); 197 | // 为类添加方法 198 | class_.addMethod(method); 199 | } 200 | 201 | /** 202 | * Description: 203 | *
204 |      * 为类生成删除方法.
205 |      * 
206 | * 207 | * @param class_ 类 208 | */ 209 | private void generateDeleteMethod(Class class_) { 210 | // 新建一个方法 211 | Method method = new Method(); 212 | // 放入删除方法的基本信息 213 | putDeleteMethodInfo(method); 214 | // 为方法添加语句 215 | method.addStatement(commonComment); 216 | method.addStatement(commonStatement); 217 | method.addStatement("// 根据主键获取实体对象"); 218 | method.addStatement(entityTypeName + " entity = (" + entityTypeName + ") session.get(" + entityTypeName + ".class, id);"); 219 | method.addStatement("// 删除实体对象"); 220 | method.addStatement("session.delete(entity);"); 221 | // 为类添加方法 222 | class_.addMethod(method); 223 | } 224 | 225 | /** 226 | * Description: 227 | *
228 |      * 为类生成修改方法.
229 |      * 
230 | * 231 | * @param class_ 类 232 | */ 233 | private void generateUpdateMethod(Class class_) { 234 | // 新建一个方法 235 | Method method = new Method(); 236 | // 放入修改方法的基本信息 237 | putUpdateMethodInfo(method); 238 | // 添加方法语句 239 | method.addStatement(commonComment); 240 | method.addStatement(commonStatement); 241 | method.addStatement("// 更新实体对象"); 242 | method.addStatement("session.update(entity);"); 243 | // 为类添加方法 244 | class_.addMethod(method); 245 | } 246 | 247 | /** 248 | * Description: 249 | *
250 |      * 为类生成查询方法(按主键查).
251 |      * 
252 | * 253 | * @param class_ 类 254 | */ 255 | private void generateReadOneMethod(Class class_) { 256 | // 新建一个方法 257 | Method method = new Method(); 258 | // 放入查询方法的基本信息 259 | putReadOneMethodInfo(method); 260 | // 添加方法语句 261 | method.addStatement(commonComment); 262 | method.addStatement(commonStatement); 263 | method.addStatement("// 根据主键查询并返回查询结果"); 264 | method.addStatement("return (" + entityTypeName + ") session.get(" + entityTypeName + ".class, id);"); 265 | // 为类添加方法 266 | class_.addMethod(method); 267 | } 268 | 269 | /** 270 | * Description: 271 | *
272 |      * 为类生成查询方法(查询所有).
273 |      * 
274 | * 275 | * @param class_ 类 276 | */ 277 | private void generateReadAllMethod(Class class_) { 278 | // 新建一个方法 279 | Method method = new Method(); 280 | // 放入查询方法的基本信息 281 | putReadAllMethodInfo(method); 282 | // 添加方法语句 283 | method.addStatement(commonComment); 284 | method.addStatement(commonStatement); 285 | method.addStatement("// 创建QBC查询对象"); 286 | method.addStatement("Criteria criteria = session.createCriteria(" + entityTypeName + ".class);"); 287 | method.addStatement("// 查询并返回结果集"); 288 | method.addStatement("return criteria.list();"); 289 | // 为类导入返回值类型 290 | class_.addImport(method.getType()); 291 | // 为类添加方法 292 | class_.addMethod(method); 293 | } 294 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/dao/HibernateGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.dao; 2 | 3 | import core.database.Table; 4 | import core.file.java.Class; 5 | import core.file.java.Interface; 6 | import core.util.FileUtils; 7 | import core.util.PathUtils; 8 | import core.util.StringUtils; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Hibernate持久层代码生成器. 14 | * 15 | * @author 李程鹏 16 | */ 17 | public class HibernateGenerator { 18 | /** 19 | * 表格集合 20 | */ 21 | private List
tables; 22 | 23 | /** 24 | * Description: 25 | *
26 |      * 构造实例化生成器.
27 |      * 
28 | * 29 | * @param tables 表格集合 30 | */ 31 | public HibernateGenerator(List
tables) { 32 | // 赋值 33 | this.tables = tables; 34 | } 35 | 36 | /** 37 | * Description: 38 | *
39 |      * 生成代码.
40 |      * 
41 | */ 42 | public void generate() throws Exception { 43 | // 遍历表格集合 44 | for (Table table : tables) { 45 | // 生成实体类文件 46 | generatePO(table); 47 | // 生成Dao层接口文件 48 | generateDao(table); 49 | // 生成Dao层实现类文件 50 | generateDaoImpl(table); 51 | } 52 | } 53 | 54 | /** 55 | * Description: 56 | *
57 |      * 根据表格对象生成实体类文件.
58 |      * 
59 | * 60 | * @param table 表格对象 61 | */ 62 | private void generatePO(Table table) throws Exception { 63 | // 获取生成的实体类 64 | Class entity = new POGenerator(table).generate(); 65 | // 根据实体类内容生成文件 66 | FileUtils.generateFile(PathUtils.ENTITY.getValue(), StringUtils.getJavaFileName(entity), entity.toString(0)); 67 | } 68 | 69 | /** 70 | * Description: 71 | *
72 |      * 根据表格对象生成Dao层接口文件.
73 |      * 
74 | * 75 | * @param table 表格对象 76 | */ 77 | private void generateDao(Table table) throws Exception { 78 | // 获取生成的Dao接口对象 79 | Interface dao = new DaoGenerator(table).generate(); 80 | // 根据接口内容生成文件 81 | FileUtils.generateFile(PathUtils.DAO.getValue(), StringUtils.getJavaFileName(dao), dao.toString()); 82 | } 83 | 84 | /** 85 | * Description: 86 | *
87 |      * 根据表格对象生成Dao层接口实现类文件.
88 |      * 
89 | * 90 | * @param table 表格对象 91 | */ 92 | private void generateDaoImpl(Table table) throws Exception { 93 | // 获取生成的Dao接口实现类 94 | Class daoImpl = new DaoImplGenerator(table).generate(); 95 | // 根据实现类的内容生成文件 96 | FileUtils.generateFile(PathUtils.DAO_IMPL.getValue(), StringUtils.getJavaFileName(daoImpl), daoImpl.toString(0)); 97 | } 98 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/dao/POGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.dao; 2 | 3 | import core.database.Column; 4 | import core.database.Table; 5 | import core.file.java.Class; 6 | import core.file.java.Field; 7 | import core.file.java.Type; 8 | import core.resolver.TypeResolver; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 持久化对象(Persistent Object)生成器. 14 | * 15 | * @author 李程鹏 16 | */ 17 | public class POGenerator extends POJOGenerator { 18 | /** 19 | * Description: 20 | *
21 |      * 构造初始化实例.
22 |      * 
23 | * 24 | * @param table 表格对象 25 | */ 26 | public POGenerator(Table table) { 27 | // 调用父类的构造方法 28 | super(table); 29 | } 30 | 31 | /** 32 | * Description: 33 | *
34 |      * 生成代码.
35 |      * 
36 | * 37 | * @return {@code core.file.java.Class} - 生成的PO类 38 | */ 39 | @Override 40 | public Class generate() { 41 | // 新建一个类 42 | Class class_ = new Class(); 43 | // 设置类的文档注释 44 | generateFileDocument(class_, table.getRemark()); 45 | // 设置类的注解 46 | class_.addAnnotation("@Entity"); 47 | class_.addAnnotation("@Table(name = \"" + table.getName() + "\")"); 48 | // 设置类的访问控制符 49 | class_.setVisibility("public "); 50 | // 设置类的类型 51 | class_.setType(classType); 52 | // 获取表中的所有列 53 | List columns = table.getColumns(); 54 | // 遍历列集合 55 | for (Column column : columns) { 56 | // 新建一个属性 57 | Field field = new Field(); 58 | // 为属性添加文档注释 59 | generateFieldDocument(field, column.getRemark()); 60 | // 设置属性的访问控制符 61 | field.setVisibility("private "); 62 | // 设置属性的类型 63 | field.setType(new TypeResolver().resolve(column.getType())); 64 | // 设置属性名 65 | field.setName(getColumnName(column)); 66 | // 如果该列是主键 67 | if (column.isPrimaryKey()) { 68 | // 为属性添加主键注解 69 | field.addAnnotation("@Id"); 70 | // 为属性添加主键生成策略注解 71 | field.addAnnotation("@GeneratedValue(strategy = GenerationType.IDENTITY)"); 72 | } 73 | // 为属性添加列标识注解 74 | field.addAnnotation("@Column(name = \"" + column.getName() + "\")"); 75 | // 为类添加属性 76 | class_.addField(field); 77 | // 为类添加需要导入的类型 78 | class_.addImport(field.getType()); 79 | class_.addImport(new Type("javax.persistence.*")); 80 | // 生成Getter方法 81 | generateGetterMethod(class_, field); 82 | // 生成Setter方法 83 | generateSetterMethod(class_, field); 84 | } 85 | // 返回POJO类 86 | return class_; 87 | } 88 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/dao/POJOGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.dao; 2 | 3 | import core.database.Column; 4 | import core.database.Table; 5 | import core.file.java.*; 6 | import core.file.java.Class; 7 | import core.generator.Generator; 8 | import core.resolver.TypeResolver; 9 | import core.util.PackageUtils; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * 简单Java对象(Plain Ordinary Java Object)生成器. 15 | * 16 | * @author 李程鹏 17 | */ 18 | public class POJOGenerator extends Generator { 19 | /** 20 | * 类的类型(类名) 21 | */ 22 | protected Type classType; 23 | 24 | /** 25 | * Description: 26 | *
 27 |      * 构造初始化实例.
 28 |      * 
29 | * 30 | * @param table 表格对象 31 | */ 32 | public POJOGenerator(Table table) { 33 | // 调用父类构造函数 34 | super(table); 35 | // 初始化类的类型(类名). 36 | this.classType = new Type(PackageUtils.ENTITY.getValue() + getTableName()); 37 | } 38 | 39 | /** 40 | * Description: 41 | *
 42 |      * 生成代码.
 43 |      * 
44 | * 45 | * @return {@code core.file.java.Class} - 生成的POJO类 46 | */ 47 | @Override 48 | public Class generate() { 49 | // 新建一个类 50 | Class class_ = new Class(); 51 | // 设置类的类型 52 | class_.setType(classType); 53 | // 设置类的访问控制符 54 | class_.setVisibility("public "); 55 | // 获取表中的所有列 56 | List columns = table.getColumns(); 57 | // 遍历列集合 58 | for (Column column : columns) { 59 | // 新建一个属性 60 | Field field = new Field(); 61 | // 设置属性的访问控制符 62 | field.setVisibility("private "); 63 | // 设置属性的类型 64 | field.setType(new TypeResolver().resolve(column.getType())); 65 | // 设置属性名 66 | field.setName(getColumnName(column)); 67 | // 为类添加属性 68 | class_.addField(field); 69 | // 为类添加需要导入的类型 70 | class_.addImport(field.getType()); 71 | // 生成Getter方法 72 | generateGetterMethod(class_, field); 73 | // 生成Setter方法 74 | generateSetterMethod(class_, field); 75 | } 76 | // 返回POJO类 77 | return class_; 78 | } 79 | 80 | /** 81 | * Description: 82 | *
 83 |      * 根据属性生成Getter方法.
 84 |      * 
85 | * 86 | * @param class_ 类 87 | * @param field 属性 88 | */ 89 | protected void generateGetterMethod(Class class_, Field field) { 90 | // 获取属性的类型 91 | Type type = field.getType(); 92 | // 获取属性名 93 | String property = field.getName(); 94 | // 新建一个方法 95 | Method method = new Method(); 96 | // 设置访问控制符 97 | method.setVisibility("public "); 98 | // 设置返回值类型 99 | method.setType(type); 100 | // 设置方法名 101 | method.setName(getGetterMethodName(property, type)); 102 | // 定义方法语句变量 103 | StringBuilder statement = new StringBuilder(); 104 | // 添加返回关键字 105 | statement.append("return "); 106 | // 添加属性名 107 | statement.append(property); 108 | // 添加分号 109 | statement.append(";"); 110 | // 为方法添加语句 111 | method.addStatement(statement.toString()); 112 | // 为类添加方法 113 | class_.addMethod(method); 114 | } 115 | 116 | /** 117 | * Description: 118 | *
119 |      * 获取Getter方法的方法名.
120 |      * 
121 | * 122 | * @param property 属性 123 | * @param type 属性的类型 124 | * @return {@code java.lang.String} - 方法名 125 | */ 126 | private String getGetterMethodName(String property, Type type) { 127 | // 新建方法名变量 128 | StringBuilder methodName = new StringBuilder(); 129 | // 将属性名放入变量中 130 | methodName.append(property); 131 | // 如果方法名中的第一个字符是小写 132 | if (Character.isLowerCase(methodName.charAt(0))) { 133 | // 如果方法名只有一个字符或者第二个字符不是大写 134 | if (methodName.length() == 1 || !Character.isUpperCase(methodName.charAt(1))) { 135 | // 将变量中的第一个字符变成大写 136 | methodName.setCharAt(0, Character.toUpperCase(methodName.charAt(0))); 137 | } 138 | } 139 | // 如果属性的类型是布尔型 140 | if (type.equals(new Type("boolean"))) { 141 | // 在方法名前加入is 142 | methodName.insert(0, "is"); 143 | } else {// 否则 144 | // 在方法名前加入get 145 | methodName.insert(0, "get"); 146 | } 147 | // 返回方法名 148 | return methodName.toString(); 149 | } 150 | 151 | /** 152 | * Description: 153 | *
154 |      * 根据属性生成Setter方法.
155 |      * 
156 | * 157 | * @param class_ 类 158 | * @param field 属性 159 | */ 160 | protected void generateSetterMethod(Class class_, Field field) { 161 | // 获取属性的类型 162 | Type type = field.getType(); 163 | // 获取属性名 164 | String property = field.getName(); 165 | // 新建一个方法 166 | Method method = new Method(); 167 | // 设置方法的访问控制符 168 | method.setVisibility("public "); 169 | // 设置方法名 170 | method.setName(getSetterMethodName(property)); 171 | // 为方法添加参数 172 | method.addParameter(new Parameter(type, property)); 173 | // 定义方法语句变量 174 | StringBuilder statement = new StringBuilder(); 175 | // 为语句变量添加内容 176 | statement.append("this."); 177 | statement.append(property); 178 | statement.append(" = "); 179 | statement.append(property); 180 | statement.append(';'); 181 | // 为方法添加方法语句 182 | method.addStatement(statement.toString()); 183 | // 为类添加方法 184 | class_.addMethod(method); 185 | } 186 | 187 | /** 188 | * Description: 189 | *
190 |      * 获取Setter方法的方法名.
191 |      * 
192 | * 193 | * @param property 属性名 194 | * @return {@code java.lang.String} - 方法名 195 | */ 196 | private static String getSetterMethodName(String property) { 197 | // 新建方法名变量 198 | StringBuilder methodName = new StringBuilder(); 199 | // 将属性名放入变量中 200 | methodName.append(property); 201 | // 如果方法名中的第一个字符是小写 202 | if (Character.isLowerCase(methodName.charAt(0))) { 203 | // 如果方法名只有一个字符或者第二个字符不是大写 204 | if (methodName.length() == 1 || !Character.isUpperCase(methodName.charAt(1))) { 205 | // 将变量中的第一个字符变成大写 206 | methodName.setCharAt(0, Character.toUpperCase(methodName.charAt(0))); 207 | } 208 | } 209 | // 在方法名前加入set 210 | methodName.insert(0, "set"); 211 | // 返回方法名 212 | return methodName.toString(); 213 | } 214 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/service/ServiceGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.service; 2 | 3 | import core.database.Table; 4 | import core.file.java.Type; 5 | import core.generator.InterfaceGenerator; 6 | import core.util.PackageUtils; 7 | 8 | /** 9 | * Service层接口生成器. 10 | * 11 | * @author 李程鹏 12 | */ 13 | public class ServiceGenerator extends InterfaceGenerator { 14 | /** 15 | * Description: 16 | *
17 |      * 构造实例化生成器.
18 |      * 
19 | * 20 | * @param table 表格对象 21 | */ 22 | public ServiceGenerator(Table table) { 23 | // 调用父类的构造函数 24 | super(table); 25 | // 实例化Service层接口的类型 26 | this.interfaceType = new Type(PackageUtils.SERVICE.getValue() + getTableName() + "Service"); 27 | // 初始化业务层接口的文档注释 28 | this.comment = "业务层接口"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/core/generator/service/ServiceImplGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.service; 2 | 3 | import core.database.Table; 4 | import core.file.java.Class; 5 | import core.file.java.Field; 6 | import core.file.java.Method; 7 | import core.file.java.Type; 8 | import core.generator.ClassGenerator; 9 | import core.util.PackageUtils; 10 | 11 | /** 12 | * Service层实现类生成器. 13 | * 14 | * @author 李程鹏 15 | */ 16 | public class ServiceImplGenerator extends ClassGenerator { 17 | /** 18 | * Service实现类需要注入的Dao接口类型 19 | */ 20 | private Type daoType; 21 | 22 | /** 23 | * Dao层接口名字 24 | */ 25 | private String daoName; 26 | 27 | /** 28 | * Description: 29 | *
 30 |      * 构造初始化生成器对象.
 31 |      * 
32 | * 33 | * @param table 表格对象 34 | */ 35 | public ServiceImplGenerator(Table table) { 36 | // 调用父类的构造函数 37 | super(table); 38 | // 初始化类的类型 39 | this.classType = new Type(PackageUtils.SERVICE_IMPL.getValue() + getTableName() + "ServiceImpl"); 40 | // 初始化接口类型 41 | this.interfaceType = new Type(PackageUtils.SERVICE.getValue() + getTableName() + "Service"); 42 | // 初始化Dao接口类型 43 | this.daoType = new Type(PackageUtils.DAO.getValue() + getTableName() + "Dao"); 44 | // 初始化Dao层接口的名字 45 | this.daoName = getCommonName("Dao"); 46 | } 47 | 48 | /** 49 | * Description: 50 | *
 51 |      * 生成代码.
 52 |      * 
53 | * 54 | * @return {@code core.file.java.Class} - 生成的Dao层实现类 55 | */ 56 | @Override 57 | public Class generate() { 58 | // 新建一个类 59 | Class class_ = new Class(); 60 | // 设置类的文档注释 61 | generateFileDocument(class_, "操作" + table.getRemark() + "对象的业务层代码"); 62 | // 添加类的注解 63 | class_.addAnnotation("@Service(\"" + getCommonName("Service") + "\")"); 64 | class_.addAnnotation("@Transactional"); 65 | // 设置访问控制符 66 | class_.setVisibility("public "); 67 | // 设置类的类型 68 | class_.setType(classType); 69 | // 为类生成属性 70 | generateField(class_); 71 | // 为类生成增加方法 72 | generateAddMethod(class_); 73 | // 为类生成删除方法 74 | generateDeleteMethod(class_); 75 | // 为类生成修改方法 76 | generateUpdateMethod(class_); 77 | // 为类生成查询方法(按主键查). 78 | generateReadOneMethod(class_); 79 | // 为类生成查询方法(查询所有). 80 | generateReadAllMethod(class_); 81 | // 添加类需要实现的接口 82 | class_.addImplementedInterface(interfaceType); 83 | // 添加类需要导入的类型 84 | addImports(class_); 85 | // 返回生成的类 86 | return class_; 87 | } 88 | 89 | /** 90 | * Description: 91 | *
 92 |      * 添加类需要导入的类型
 93 |      * 
94 | * 95 | * @param class_ 类 96 | */ 97 | private void addImports(Class class_) { 98 | // 导入通用类型 99 | addCommonImports(class_); 100 | // 导入接口类型 101 | class_.addImport(interfaceType); 102 | // 导入被注入的接口类型 103 | class_.addImport(daoType); 104 | // 导入实体类型 105 | class_.addImport(entityType); 106 | // 导入事务标签类型 107 | class_.addImport(new Type("org.springframework.transaction.annotation.Transactional")); 108 | } 109 | 110 | /** 111 | * Description: 112 | *
113 |      * 为类生成属性.
114 |      * 
115 | * 116 | * @param class_ 类 117 | */ 118 | private void generateField(Class class_) { 119 | // 新建一个属性 120 | Field field = new Field(); 121 | // 添加属性的文档注释 122 | generateFieldDocument(field, "持久层接口"); 123 | // 为属性添加注解 124 | field.addAnnotation("@Autowired"); 125 | field.addAnnotation("@Qualifier(\"" + daoName + "\")"); 126 | // 设置访问控制符 127 | field.setVisibility("private "); 128 | // 设置属性类型 129 | field.setType(daoType); 130 | // 设置属性名 131 | field.setName(daoName); 132 | // 为类添加属性 133 | class_.addField(field); 134 | } 135 | 136 | /** 137 | * Description: 138 | *
139 |      * 为类生成增加方法.
140 |      * 
141 | * 142 | * @param class_ 类 143 | */ 144 | private void generateAddMethod(Class class_) { 145 | // 新建一个方法 146 | Method method = new Method(); 147 | // 放入增加方法的基本信息 148 | putAddMethodInfo(method); 149 | // 添加注释 150 | method.addStatement("// 调用持久层接口添加实体对象"); 151 | // 添加方法语句 152 | method.addStatement(daoName + ".addEntity(entity);"); 153 | // 为类添加方法 154 | class_.addMethod(method); 155 | } 156 | 157 | /** 158 | * Description: 159 | *
160 |      * 为类生成删除方法.
161 |      * 
162 | * 163 | * @param class_ 类 164 | */ 165 | private void generateDeleteMethod(Class class_) { 166 | // 新建一个方法 167 | Method method = new Method(); 168 | // 放入删除方法的基本信息 169 | putDeleteMethodInfo(method); 170 | // 添加注释 171 | method.addStatement("// 调用持久层接口删除实体对象"); 172 | // 添加方法语句 173 | method.addStatement(daoName + ".deleteEntity(id);"); 174 | // 为类添加方法 175 | class_.addMethod(method); 176 | } 177 | 178 | /** 179 | * Description: 180 | *
181 |      * 为类生成修改方法.
182 |      * 
183 | * 184 | * @param class_ 类 185 | */ 186 | private void generateUpdateMethod(Class class_) { 187 | // 新建一个方法 188 | Method method = new Method(); 189 | // 放入修改方法的基本信息 190 | putUpdateMethodInfo(method); 191 | // 添加注释 192 | method.addStatement("// 调用持久层接口修改实体对象"); 193 | // 添加方法语句 194 | method.addStatement(daoName + ".updateEntity(entity);"); 195 | // 为类添加方法 196 | class_.addMethod(method); 197 | } 198 | 199 | /** 200 | * Description: 201 | *
202 |      * 为类生成查询方法(按主键查).
203 |      * 
204 | * 205 | * @param class_ 类 206 | */ 207 | private void generateReadOneMethod(Class class_) { 208 | // 新建一个方法 209 | Method method = new Method(); 210 | // 放入查询方法的基本信息 211 | putReadOneMethodInfo(method); 212 | // 添加注释 213 | method.addStatement("// 调用持久层接口查询实体对象"); 214 | // 添加方法语句 215 | method.addStatement("return " + daoName + ".readEntity(id);"); 216 | // 为类添加方法 217 | class_.addMethod(method); 218 | } 219 | 220 | /** 221 | * Description: 222 | *
223 |      * 为类生成查询方法(查询所有).
224 |      * 
225 | * 226 | * @param class_ 类 227 | */ 228 | private void generateReadAllMethod(Class class_) { 229 | // 新建一个方法 230 | Method method = new Method(); 231 | // 放入查询方法的基本信息 232 | putReadAllMethodInfo(method); 233 | // 添加注释 234 | method.addStatement("// 调用持久层接口查询实体对象集合"); 235 | // 添加方法语句 236 | method.addStatement("return " + daoName + ".readEntities();"); 237 | // 为类导入返回值类型 238 | class_.addImport(method.getType()); 239 | // 为类添加方法 240 | class_.addMethod(method); 241 | } 242 | } -------------------------------------------------------------------------------- /src/main/java/core/generator/service/SpringGenerator.java: -------------------------------------------------------------------------------- 1 | package core.generator.service; 2 | 3 | import core.file.java.Class; 4 | import core.database.Table; 5 | import core.file.java.Interface; 6 | import core.util.FileUtils; 7 | import core.util.PathUtils; 8 | import core.util.StringUtils; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Spring业务层代码生成器. 14 | * 15 | * @author 李程鹏 16 | */ 17 | public class SpringGenerator { 18 | /** 19 | * 表格集合 20 | */ 21 | private List
tables; 22 | 23 | /** 24 | * Description: 25 | *
26 |      * 构造初始化生成器.
27 |      * 
28 | * 29 | * @param tables 表格对象 30 | */ 31 | public SpringGenerator(List
tables) { 32 | // 赋值 33 | this.tables = tables; 34 | } 35 | 36 | /** 37 | * Description: 38 | *
39 |      * 生成代码.
40 |      * 
41 | */ 42 | public void generate() throws Exception { 43 | // 遍历表格集合 44 | for (Table table : tables) { 45 | // 生成Service层接口文件 46 | generateService(table); 47 | // 生成Service层接口实现类文件 48 | generateServiceImpl(table); 49 | } 50 | } 51 | 52 | /** 53 | * Description: 54 | *
55 |      * 生成Service层接口文件.
56 |      * 
57 | * 58 | * @param table 表格对象 59 | */ 60 | private void generateService(Table table) throws Exception { 61 | // 获取生成的Service接口 62 | Interface service = new ServiceGenerator(table).generate(); 63 | // 根据接口对象内容生成文件 64 | FileUtils.generateFile(PathUtils.SERVICE.getValue(), StringUtils.getJavaFileName(service), service.toString()); 65 | } 66 | 67 | /** 68 | * Description: 69 | *
70 |      * 生成Service层接口实现类文件.
71 |      * 
72 | * 73 | * @param table 表格对象 74 | */ 75 | private void generateServiceImpl(Table table) throws Exception { 76 | // 获取生成的Service接口实现类 77 | Class serviceImpl = new ServiceImplGenerator(table).generate(); 78 | // 根据实现类的内容生成文件 79 | FileUtils.generateFile(PathUtils.SERVICE_IMPL.getValue(), StringUtils.getJavaFileName(serviceImpl), serviceImpl.toString(0)); 80 | } 81 | } -------------------------------------------------------------------------------- /src/main/java/core/resolver/TypeResolver.java: -------------------------------------------------------------------------------- 1 | package core.resolver; 2 | 3 | import core.file.java.Type; 4 | 5 | import java.sql.Types; 6 | import java.util.Date; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * 类型解析器(将JDBC类型解析为Java类型). 12 | * 13 | * @author 李程鹏 14 | */ 15 | public class TypeResolver { 16 | /** 17 | * 类型映射变量 18 | */ 19 | private Map typeMap; 20 | 21 | /** 22 | * Description: 23 | *
24 |      * 构造创建解析器实例,在创建过程中放入初始化数据.
25 |      * 
26 | */ 27 | public TypeResolver() { 28 | typeMap = new HashMap<>(); 29 | typeMap.put(Types.ARRAY, new Type(Object.class.getName())); 30 | typeMap.put(Types.BIGINT, new Type(Long.class.getName())); 31 | typeMap.put(Types.BINARY, new Type("byte[]")); 32 | typeMap.put(Types.BIT, new Type(Boolean.class.getName())); 33 | typeMap.put(Types.BLOB, new Type("byte[]")); 34 | typeMap.put(Types.BOOLEAN, new Type(Boolean.class.getName())); 35 | typeMap.put(Types.CHAR, new Type(String.class.getName())); 36 | typeMap.put(Types.CLOB, new Type(String.class.getName())); 37 | typeMap.put(Types.DATALINK, new Type(Object.class.getName())); 38 | typeMap.put(Types.DATE, new Type(Date.class.getName())); 39 | typeMap.put(Types.DISTINCT, new Type(Object.class.getName())); 40 | typeMap.put(Types.DOUBLE, new Type(Double.class.getName())); 41 | typeMap.put(Types.FLOAT, new Type(Double.class.getName())); 42 | typeMap.put(Types.INTEGER, new Type(Integer.class.getName())); 43 | typeMap.put(Types.JAVA_OBJECT, new Type(Object.class.getName())); 44 | typeMap.put(Types.LONGVARBINARY, new Type("byte[]")); 45 | typeMap.put(Types.LONGVARCHAR, new Type(String.class.getName())); 46 | typeMap.put(Types.NULL, new Type(Object.class.getName())); 47 | typeMap.put(Types.OTHER, new Type(Object.class.getName())); 48 | typeMap.put(Types.REAL, new Type(Float.class.getName())); 49 | typeMap.put(Types.REF, new Type(Object.class.getName())); 50 | typeMap.put(Types.SMALLINT, new Type(Short.class.getName())); 51 | typeMap.put(Types.STRUCT, new Type(Object.class.getName())); 52 | typeMap.put(Types.TIME, new Type(Date.class.getName())); 53 | typeMap.put(Types.TIMESTAMP, new Type(Date.class.getName())); 54 | typeMap.put(Types.TINYINT, new Type(Byte.class.getName())); 55 | typeMap.put(Types.VARBINARY, new Type("byte[]")); 56 | typeMap.put(Types.VARCHAR, new Type(String.class.getName())); 57 | } 58 | 59 | /** 60 | * Description: 61 | *
62 |      * 根据JDBC类型解析出对应的Java类型.
63 |      * 
64 | * 65 | * @param jdbcType JDBC类型 66 | * @return {@code core.file.java.Type} - Java类型 67 | */ 68 | public Type resolve(Integer jdbcType) { 69 | // 在Map查询并返回查询结果 70 | return typeMap.get(jdbcType); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/core/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | package core.util; 2 | 3 | import java.io.*; 4 | 5 | /** 6 | * 文件操作工具类. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public class FileUtils { 11 | /** 12 | * Description: 13 | *
 14 |      * 生成文件.
 15 |      * 
16 | * 17 | * @param relativePath 相对路径 18 | * @param fileName 文件名 19 | * @param content 文件内容 20 | */ 21 | public static void generateFile(String relativePath, String fileName, String content) throws Exception { 22 | // 获取工程的相对路径 23 | String projectPath = "\\" + NameUtils.PROJECT.getValue(); 24 | // 拼接出文件的绝对路径 25 | String absolutePath = PathUtils.DESKTOP.getValue() + projectPath + relativePath; 26 | // 定义文件路径对象 27 | File directory = new File(absolutePath); 28 | // 如果路径不存在 29 | if (!directory.exists()) { 30 | // 创建路径 31 | directory.mkdirs(); 32 | } 33 | // 定义文件对象 34 | File file = new File(absolutePath + fileName); 35 | // 根据文件对象创建文件输出流 36 | FileOutputStream fileOutputStream = new FileOutputStream(file, false); 37 | // 创建输出流写入器 38 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "utf-8"); 39 | // 创建缓冲区写入器 40 | BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter); 41 | // 写入文件内容 42 | bufferedWriter.write(content); 43 | // 关闭缓冲区写入器 44 | bufferedWriter.close(); 45 | } 46 | 47 | /** 48 | * Description: 49 | *
 50 |      * 拷贝文件.
 51 |      * 
52 | * 53 | * @param from 来源文件 54 | * @param to 目的文件 55 | */ 56 | public static void copyFile(String from, String to) { 57 | // 新建源文件对象 58 | File sourceFile = new File(from); 59 | // 新建目标文件对象 60 | File destinationFile = new File(to); 61 | // 定义文件输入流 62 | FileInputStream fileInputStream = null; 63 | // 定义文件输出流 64 | FileOutputStream fileOutputStream = null; 65 | try { 66 | // 如果目标文件对象不存在 67 | if (!destinationFile.exists()) { 68 | // 新建一个目标文件对象 69 | destinationFile.createNewFile(); 70 | } 71 | // 初始化文件输入流 72 | fileInputStream = new FileInputStream(sourceFile); 73 | // 初始化文件输出流 74 | fileOutputStream = new FileOutputStream(destinationFile); 75 | // 创建字节数组,图片只能使用字节流的形式进行拷贝. 76 | byte data[] = new byte[1024]; 77 | // 读取的字节数 78 | int count = 0; 79 | // 循环读取输入流的内容 80 | while ((count = fileInputStream.read(data)) != -1) { 81 | // 写出读取到的内容 82 | fileOutputStream.write(data, 0, count); 83 | } 84 | } catch (Exception e) { 85 | // 如果出了异常,打印异常信息. 86 | System.out.println("拷贝文件过程出错!"); 87 | } finally { 88 | try { 89 | // 关闭文件输入流 90 | if (fileInputStream != null) fileInputStream.close(); 91 | // 关闭文件输出流 92 | if (fileOutputStream != null) fileOutputStream.close(); 93 | } catch (IOException e) { 94 | // 如果出了异常,打印异常信息. 95 | System.out.println("关闭IO流对象出错!"); 96 | } 97 | } 98 | } 99 | 100 | /** 101 | * Description: 102 | *
103 |      * 拷贝文件夹.
104 |      * 
105 | * 106 | * @param from 来源路径 107 | * @param to 目的路径 108 | */ 109 | public static void copyDirectory(String from, String to) { 110 | // 根据来源路径新建一个文件夹对象 111 | File sourceDirectory = new File(from); 112 | // 获取来源路径下的所有文件和文件夹 113 | File[] sourceFiles = sourceDirectory.listFiles(); 114 | // 根据目的路径新建一个文件夹对象 115 | File destinationDirectory = new File(to); 116 | // 如果目的路径不存在 117 | if (!destinationDirectory.exists()) { 118 | // 创建目的路径 119 | destinationDirectory.mkdirs(); 120 | } 121 | // 遍历来源路径下的文件和文件夹 122 | for (File file : sourceFiles) { 123 | // 如果是文件 124 | if (file.isFile()) { 125 | // 拷贝文件到指定目录下 126 | copyFile(file.getPath(), to + "\\" + file.getName()); 127 | } else if (file.isDirectory()) {// 如果是文件夹 128 | // 递归调用拷贝文件夹的方法 129 | copyDirectory(file.getPath(), to + "\\" + file.getName()); 130 | } 131 | } 132 | } 133 | } -------------------------------------------------------------------------------- /src/main/java/core/util/FreeMarkerUtils.java: -------------------------------------------------------------------------------- 1 | package core.util; 2 | 3 | import freemarker.template.Configuration; 4 | import freemarker.template.Template; 5 | 6 | import java.io.File; 7 | import java.io.FileWriter; 8 | import java.util.Map; 9 | 10 | /** 11 | * FreeMarker模板引擎工具类. 12 | * 13 | * @author 李程鹏 14 | */ 15 | public class FreeMarkerUtils { 16 | /** 17 | * Description: 18 | *
19 |      * 使用模板引擎生成文件.
20 |      * 
21 | * 22 | * @param fileName 需要生成的文件名 23 | * @param relativePath 文件生成的相对路径 24 | * @param data 数据参数 25 | */ 26 | public static void generateFile(String fileName, String relativePath, Map data) throws Exception { 27 | // 新建配置对象 28 | Configuration configuration = new Configuration(); 29 | // 获取模板文件的绝对路径 30 | String templatePath = PathUtils.PROJECT.getValue() + PathUtils.FTL_TEMPLATE.getValue(); 31 | // 设置读取模板文件的路径 32 | configuration.setDirectoryForTemplateLoading(new File(templatePath)); 33 | // 读取模板文件并生成模板对象 34 | Template template = configuration.getTemplate(fileName + ".ftl"); 35 | // 获取工程的相对路径 36 | String projectPath = "\\" + NameUtils.PROJECT.getValue(); 37 | // 拼接出输出文件的绝对路径 38 | String filePath = PathUtils.DESKTOP.getValue() + projectPath + relativePath; 39 | // 定义文件路径对象 40 | File directory = new File(filePath); 41 | // 如果输出路径不存在 42 | if (!directory.exists()) { 43 | // 创建路径 44 | directory.mkdirs(); 45 | } 46 | // 获取文件写入器 47 | FileWriter fileWriter = new FileWriter(new File(filePath + fileName)); 48 | // 根据数据参数生成文件 49 | template.process(data, fileWriter); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/core/util/JavaUtils.java: -------------------------------------------------------------------------------- 1 | package core.util; 2 | 3 | import core.file.java.Type; 4 | 5 | import java.util.Collection; 6 | import java.util.List; 7 | import java.util.Set; 8 | 9 | /** 10 | * Java文件操作工具类. 11 | * 12 | * @author 李程鹏 13 | */ 14 | public class JavaUtils { 15 | /** 16 | * Description: 17 | *
18 |      * 为Java元素放入需要继承的父接口.
19 |      * 
20 | * 21 | * @param javaElement Java元素 22 | * @param superInterfaces 父接口集合 23 | */ 24 | public static void putSuperInterfaces(StringBuilder javaElement, Set superInterfaces) { 25 | // 放入操作 26 | putTypes(javaElement, superInterfaces, "extends"); 27 | } 28 | 29 | /** 30 | * Description: 31 | *
32 |      * 为Java元素放入需要抛出的异常.
33 |      * 
34 | * 35 | * @param javaElement Java元素 36 | * @param exceptions 异常集合 37 | */ 38 | public static void putExceptions(StringBuilder javaElement, List exceptions) { 39 | // 放入操作 40 | putTypes(javaElement, exceptions, "throws"); 41 | } 42 | 43 | /** 44 | * Description: 45 | *
46 |      * 为Java元素放入需要实现的接口.
47 |      * 
48 | * 49 | * @param javaElement Java元素 50 | * @param implementedInterfaces 接口集合 51 | */ 52 | public static void putImplementedInterfaces(StringBuilder javaElement, Set implementedInterfaces) { 53 | // 放入操作 54 | putTypes(javaElement, implementedInterfaces, "implements"); 55 | } 56 | 57 | /** 58 | * Description: 59 | *
60 |      * 为Java元素放入类型集合.
61 |      * 
62 | * 63 | * @param javaElement Java元素 64 | * @param types 类型集合 65 | * @param keyWord 关键字 66 | */ 67 | private static void putTypes(StringBuilder javaElement, Collection types, String keyWord) { 68 | // 如果集合不为空 69 | if (types.size() > 0) { 70 | // 添加空格 71 | TextUtils.addSpace(javaElement); 72 | // 添加关键字 73 | javaElement.append(keyWord); 74 | // 添加空格 75 | TextUtils.addSpace(javaElement); 76 | // 是否需要添加逗号 77 | boolean needComma = false; 78 | // 遍历类型集合 79 | for (Type type : types) { 80 | // 如果需要添加逗号 81 | if (needComma) { 82 | // 添加逗号 83 | javaElement.append(","); 84 | // 添加空格 85 | TextUtils.addSpace(javaElement); 86 | } else { 87 | // 除了第一个类型,后面的在添加时都需要先加上逗号. 88 | needComma = true; 89 | } 90 | // 添加类型名 91 | javaElement.append(type.getTypeName()); 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/core/util/NameUtils.java: -------------------------------------------------------------------------------- 1 | package core.util; 2 | 3 | /** 4 | * 名字枚举类. 5 | * 6 | * @author 李程鹏 7 | */ 8 | public enum NameUtils { 9 | // 项目名 10 | PROJECT("Project"), 11 | // SpringMVC配置文件名 12 | SPRING_MVC_CONFIG("applicationContext-controller.xml"), 13 | // Spring配置文件名 14 | SPRING_CONFIG("applicationContext-service.xml"), 15 | // Hibernate配置文件名 16 | HIBERNATE_CONFIG("applicationContext-dao.xml"), 17 | // web.xml文件名 18 | WEB_XML("web.xml"), 19 | // pom.xml文件名 20 | POM_XML("pom.xml"); 21 | 22 | /** 23 | * 枚举值 24 | */ 25 | private String value; 26 | 27 | /** 28 | * Description: 29 | *
30 |      * 构造初始化枚举对象.
31 |      * 
32 | * 33 | * @param value 枚举值 34 | */ 35 | NameUtils(String value) { 36 | // 赋值 37 | this.value = value; 38 | } 39 | 40 | /** 41 | * Description: 42 | *
43 |      * 获取枚举值
44 |      * 
45 | * 46 | * @return {@code java.lang.String} - 枚举值 47 | */ 48 | public String getValue() { 49 | // 返回枚举值 50 | return value; 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/core/util/PackageUtils.java: -------------------------------------------------------------------------------- 1 | package core.util; 2 | 3 | /** 4 | * 包名枚举类. 5 | * 6 | * @author 李程鹏 7 | */ 8 | public enum PackageUtils { 9 | // controller类所在的包 10 | CONTROLLER("core.controller."), 11 | // service接口所在的包 12 | SERVICE("core.service."), 13 | // service接口实现类所在的包 14 | SERVICE_IMPL("core.service.impl."), 15 | // dao接口所在的包 16 | DAO("core.dao."), 17 | // dao接口实现类所在的包 18 | DAO_IMPL("core.dao.impl."), 19 | // 实体类所在的包 20 | ENTITY("core.entity."); 21 | 22 | /** 23 | * 枚举值 24 | */ 25 | private String value; 26 | 27 | /** 28 | * Description: 29 | *
30 |      * 构造初始化枚举对象.
31 |      * 
32 | * 33 | * @param value 枚举值 34 | */ 35 | PackageUtils(String value) { 36 | // 赋值 37 | this.value = value; 38 | } 39 | 40 | /** 41 | * Description: 42 | *
43 |      * 获取枚举值
44 |      * 
45 | * 46 | * @return {@code java.lang.String} - 枚举值 47 | */ 48 | public String getValue() { 49 | // 返回枚举值 50 | return value; 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/core/util/PathUtils.java: -------------------------------------------------------------------------------- 1 | package core.util; 2 | 3 | import javax.swing.filechooser.FileSystemView; 4 | 5 | /** 6 | * 路径枚举类. 7 | * 8 | * @author 李程鹏 9 | */ 10 | public enum PathUtils { 11 | // controller类生成的相对路径 12 | CONTROLLER("\\src\\main\\java\\core\\controller\\"), 13 | // service接口生成的相对路径 14 | SERVICE("\\src\\main\\java\\core\\service\\"), 15 | // service接口实现类生成的相对路径 16 | SERVICE_IMPL("\\src\\main\\java\\core\\service\\impl\\"), 17 | // dao接口生成的相对路径 18 | DAO("\\src\\main\\java\\core\\dao\\"), 19 | // dao接口实现类生成的相对路径 20 | DAO_IMPL("\\src\\main\\java\\core\\dao\\impl\\"), 21 | // 实体类生成的相对路径 22 | ENTITY("\\src\\main\\java\\core\\entity\\"), 23 | // 模板文件存放的相对路径 24 | FTL_TEMPLATE("\\src\\main\\resources\\ftl\\"), 25 | // 本机桌面的绝对路径 26 | DESKTOP(FileSystemView.getFileSystemView().getHomeDirectory().getPath()), 27 | // 本工程文件夹所在的绝对路径 28 | PROJECT(System.getProperty("user.dir")), 29 | // web.xml生成的相对路径 30 | WEB_XML("\\web\\WEB-INF\\"), 31 | // SpringMVC配置文件生成的相对路径 32 | SPRING_MVC_CONFIG("\\src\\main\\resources\\"), 33 | // Spring配置文件生成的相对路径 34 | SPRING_CONFIG("\\src\\main\\resources\\"), 35 | // Hibernate配置文件生成的相对路径 36 | HIBERNATE_CONFIG("\\src\\main\\resources\\"), 37 | // SwaggerUI源文件的相对路径 38 | SWAGGER_UI_FROM("\\src\\main\\resources\\swagger-ui\\"), 39 | // SwaggerUI拷贝目的地的相对路径 40 | SWAGGER_UI_TO("\\web\\swagger-ui\\"); 41 | 42 | /** 43 | * 枚举值 44 | */ 45 | private String value; 46 | 47 | /** 48 | * Description: 49 | *
50 |      * 构造初始化枚举对象.
51 |      * 
52 | * 53 | * @param value 枚举值 54 | */ 55 | PathUtils(String value) { 56 | // 赋值 57 | this.value = value; 58 | } 59 | 60 | /** 61 | * Description: 62 | *
63 |      * 获取枚举值
64 |      * 
65 | * 66 | * @return {@code java.lang.String} - 枚举值 67 | */ 68 | public String getValue() { 69 | // 返回枚举值 70 | return value; 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/core/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | package core.util; 2 | 3 | import core.file.java.Interface; 4 | import core.file.java.Type; 5 | import core.file.java.Class; 6 | 7 | import java.util.Set; 8 | import java.util.TreeSet; 9 | 10 | /** 11 | * 字符串操作工具类. 12 | * 13 | * @author 李程鹏 14 | */ 15 | public class StringUtils { 16 | /** 17 | * Description: 18 | *
 19 |      * 根据需要导入的类型创建导入语句.
 20 |      * 
21 | * 22 | * @param imports 需要导入的语句 23 | * @return {@code java.util.Set} - 导入语句集合 24 | */ 25 | public static Set getImportStatements(Set imports) { 26 | // 定义导入语句集合 27 | Set importStatements = new TreeSet<>(); 28 | // 定义导入语句变量 29 | StringBuilder importStatement = new StringBuilder(); 30 | // 遍历需要导入的类型 31 | for (Type import_ : imports) { 32 | // 遍历类型中需要导入的值 33 | for (String importValue : import_.getImports()) { 34 | // 清空导入语句变量 35 | importStatement.setLength(0); 36 | // 添加导入关键字 37 | importStatement.append("import"); 38 | // 添加空格 39 | TextUtils.addSpace(importStatement); 40 | // 添加需要导入的值 41 | importStatement.append(importValue); 42 | // 添加分号 43 | importStatement.append(';'); 44 | // 将导入语句放入集合中 45 | importStatements.add(importStatement.toString()); 46 | } 47 | } 48 | // 返回导入语句集合 49 | return importStatements; 50 | } 51 | 52 | /** 53 | * Description: 54 | *
 55 |      * 将输入的字符串转成驼峰式字符串.
 56 |      * 
57 | * 58 | * @param input 输入的字符串 59 | * @param isUpper 是否按照大驼峰式规则 60 | * @return {@code java.lang.String} - 驼峰式字符串 61 | */ 62 | public static String toCamelCase(String input, boolean isUpper) { 63 | // 定义结果值变量 64 | StringBuilder output = new StringBuilder(); 65 | // 用于判断下一个字符是否需要大写的标志 66 | boolean nextUpperCase = false; 67 | // 循环遍历输入字符串的每一个字符 68 | for (int i = 0; i < input.length(); i++) { 69 | // 取出当前字符 70 | char c = input.charAt(i); 71 | // 分情况处理字符 72 | switch (c) { 73 | // 如果当前字符是一些特殊的分隔符 74 | case '_': 75 | case '-': 76 | case '@': 77 | case '$': 78 | case '#': 79 | case ' ': 80 | case '/': 81 | case '&': 82 | // 如果结果值中存在了字符 83 | if (output.length() > 0) { 84 | // 下一个字符需要大写 85 | nextUpperCase = true; 86 | } 87 | break; 88 | default:// 如果当前字符是字母 89 | // 如果该字符需要大写 90 | if (nextUpperCase) { 91 | // 将该字符的大写形式放入结果变量中 92 | output.append(Character.toUpperCase(c)); 93 | // 设置标志值为假 94 | nextUpperCase = false; 95 | } else {// 如果当前字符不需要大写 96 | // 将该字符的小写形式放入结果变量中 97 | output.append(Character.toLowerCase(c)); 98 | } 99 | break; 100 | } 101 | } 102 | // 如果需要按照大驼峰规则来转换 103 | if (isUpper) { 104 | // 将结果值变量中的第一个字符变成大写 105 | output.setCharAt(0, Character.toUpperCase(output.charAt(0))); 106 | } 107 | // 返回结果值 108 | return output.toString(); 109 | } 110 | 111 | /** 112 | * Description: 113 | *
114 |      * 根据类对象生成文件名.
115 |      * 
116 | * 117 | * @param class_ 类对象 118 | * @return {@code java.lang.String} - 文件名 119 | */ 120 | public static String getJavaFileName(Class class_) { 121 | // 返回对应的文件名 122 | return class_.getType().getTypeName() + ".java"; 123 | } 124 | 125 | /** 126 | * Description: 127 | *
128 |      * 根据接口对象生成文件名.
129 |      * 
130 | * 131 | * @param interface_ 接口对象 132 | * @return {@code java.lang.String} - 文件名 133 | */ 134 | public static String getJavaFileName(Interface interface_) { 135 | // 返回对应的文件名 136 | return interface_.getType().getTypeName() + ".java"; 137 | } 138 | 139 | /** 140 | * Description: 141 | *
142 |      * 去掉字符串末尾的点.
143 |      * 
144 | * 145 | * @param content 字符串内容 146 | * @return {@code java.lang.String} - 处理结果 147 | */ 148 | public static String removeLastDot(String content) { 149 | // 返回处理结果 150 | return content.substring(0, content.length() - 1); 151 | } 152 | 153 | /** 154 | * Description: 155 | *
156 |      * 判断字符串是否是空串.
157 |      * 
158 | * 159 | * @param content 字符串内容 160 | * @return {@code boolean} - 判断结果 161 | */ 162 | public static boolean isNotEmpty(String content) { 163 | // 返回判断结果 164 | return content != null && !"".equals(content.trim()); 165 | } 166 | } -------------------------------------------------------------------------------- /src/main/java/core/util/TextUtils.java: -------------------------------------------------------------------------------- 1 | package core.util; 2 | 3 | /** 4 | * 文本操作工具类. 5 | * 6 | * @author 李程鹏 7 | */ 8 | public class TextUtils { 9 | /** 10 | * Description: 11 | *
12 |      * 为文本添加Tab缩进.
13 |      * 
14 | * 15 | * @param text 目标文本 16 | * @param indentCount 缩进次数 17 | */ 18 | public static void addIndentation(StringBuilder text, int indentCount) { 19 | // 循环添加Tab缩进 20 | for (int count = 0; count < indentCount; count++) { 21 | // 添加一个Tab缩进 22 | text.append("\t"); 23 | } 24 | } 25 | 26 | /** 27 | * Description: 28 | *
29 |      * 为文本添加换行符.
30 |      * 
31 | * 32 | * @param text 目标文本 33 | */ 34 | public static void addLine(StringBuilder text) { 35 | // 添加一个换行符 36 | text.append("\n"); 37 | } 38 | 39 | /** 40 | * Description: 41 | *
42 |      * 为文本添加空格.
43 |      * 
44 | * 45 | * @param text 目标文本 46 | */ 47 | public static void addSpace(StringBuilder text) { 48 | // 添加一个空格 49 | text.append(" "); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/resources/ftl/applicationContext-controller.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/resources/ftl/applicationContext-dao.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | ${entityPackage} 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.hibernate.dialect.MySQL5Dialect 38 | 39 | true 40 | 41 | true 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/resources/ftl/applicationContext-service.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/main/resources/ftl/pom.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ${projectName} 8 | ${projectName} 9 | 1.0-SNAPSHOT 10 | war 11 | 12 | 13 | 14 | org.springframework 15 | spring-webmvc 16 | 4.2.1.RELEASE 17 | 18 | 19 | 20 | javax.servlet 21 | javax.servlet-api 22 | 3.1.0 23 | 24 | 25 | 26 | javax.servlet 27 | jstl 28 | 1.2 29 | 30 | 31 | 32 | com.fasterxml.jackson.core 33 | jackson-databind 34 | 2.8.1 35 | 36 | 37 | 38 | org.springframework 39 | spring-context 40 | 4.2.1.RELEASE 41 | 42 | 43 | 44 | org.springframework 45 | spring-orm 46 | 4.2.1.RELEASE 47 | 48 | 49 | 50 | org.springframework 51 | spring-aspects 52 | 4.2.1.RELEASE 53 | 54 | 55 | 56 | org.hibernate 57 | hibernate-core 58 | 4.3.11.Final 59 | 60 | 61 | 62 | c3p0 63 | c3p0 64 | 0.9.1.2 65 | 66 | 67 | 68 | com.mchange 69 | mchange-commons-java 70 | 0.2.8 71 | 72 | 73 | 74 | mysql 75 | mysql-connector-java 76 | 5.1.36 77 | 78 | 79 | 80 | org.modelmapper 81 | modelmapper 82 | 0.7.3 83 | 84 | 85 | 86 | com.mangofactory 87 | swagger-springmvc 88 | 0.9.5 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-compiler-plugin 98 | 99 | 1.7 100 | 1.7 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/main/resources/ftl/web.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | swagger-ui/index.html 9 | 10 | 11 | 12 | 13 | org.springframework.web.context.ContextLoaderListener 14 | 15 | 16 | 17 | 18 | contextConfigLocation 19 | classpath:${springConfig},classpath:${hibernateConfig} 20 | 21 | 22 | 23 | 24 | DispatcherServlet 25 | org.springframework.web.servlet.DispatcherServlet 26 | 27 | contextConfigLocation 28 | classpath:${springMVCConfig} 29 | 30 | 1 31 | 32 | 33 | 34 | DispatcherServlet 35 | 36 | / 37 | 38 | 39 | 40 | 41 | CharacterEncodingFilter 42 | org.springframework.web.filter.CharacterEncodingFilter 43 | 44 | encoding 45 | utf-8 46 | 47 | 48 | 49 | 50 | CharacterEncodingFilter 51 | 52 | /* 53 | 54 | 55 | 56 | 57 | default 58 | /swagger-ui/* 59 | 60 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/css/reset.css: -------------------------------------------------------------------------------- 1 | a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:"";content:none}table{border-collapse:collapse;border-spacing:0} -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/css/style.css: -------------------------------------------------------------------------------- 1 | .swagger-section #header a#logo{font-size:1.5em;font-weight:700;text-decoration:none;padding:20px 0 20px 40px}#text-head{font-size:80px;font-family:Roboto,sans-serif;color:#fff;float:right;margin-right:20%}.navbar-fixed-top .navbar-brand,.navbar-fixed-top .navbar-nav,.navbar-header{height:auto}.navbar-inverse{background-color:#000;border-color:#000}#navbar-brand{margin-left:20%}.navtext{font-size:10px}.h1,h1{font-size:60px}.navbar-default .navbar-header .navbar-brand{color:#a2dfee}.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a{color:#393939;font-family:Arvo,serif;font-size:1.5em}.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a:hover{color:#000}.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2{color:#525252;padding-left:0;display:block;clear:none;float:left;font-family:Arvo,serif;font-weight:700}.navbar-default .navbar-collapse,.navbar-default .navbar-form{border-color:#0a0a0a}.container1{width:1500px;margin:auto;margin-top:0;background-repeat:no-repeat;background-position:-40px -20px;margin-bottom:210px}.container-inner{width:1200px;margin:auto;background-color:hsla(192,8%,88%,.75);padding-bottom:40px;padding-top:40px;border-radius:15px}.header-content{padding:0;width:1000px}.title1{font-size:80px;font-family:Vollkorn,serif;color:#404040;text-align:center;padding-top:40px;padding-bottom:100px}#icon{margin-top:-18px}.subtext{font-size:25px;font-style:italic;color:#08b;text-align:right;padding-right:250px}.bg-primary{background-color:#00468b}.navbar-default .nav>li>a,.navbar-default .nav>li>a:focus,.navbar-default .nav>li>a:focus:hover,.navbar-default .nav>li>a:hover{color:#08b}.text-faded{font-size:25px;font-family:Vollkorn,serif}.section-heading{font-family:Vollkorn,serif;font-size:45px;padding-bottom:10px}hr{border-color:#00468b;padding-bottom:10px}.description{margin-top:20px;padding-bottom:200px}.description li{font-family:Vollkorn,serif;font-size:25px;color:#525252;margin-left:28%;padding-top:5px}.gap{margin-top:200px}.troubleshootingtext{color:hsla(0,0%,100%,.7);padding-left:30%}.troubleshootingtext li{list-style-type:circle;font-size:25px;padding-bottom:5px}.overlay{position:absolute;top:0;left:0;width:100%;height:100%;z-index:1}.block.response_body.json:hover{cursor:pointer}.backdrop{color:blue}#myModal{height:100%}.modal-backdrop{bottom:0;position:fixed}.curl{padding:10px;font-family:Anonymous Pro,Menlo,Consolas,Bitstream Vera Sans Mono,Courier New,monospace;font-size:.9em;max-height:400px;margin-top:5px;overflow-y:auto;background-color:#fcf6db;border:1px solid #e5e0c6;border-radius:4px}.curl_title{font-size:1.1em;margin:0;padding:15px 0 5px;font-family:Open Sans,Helvetica Neue,Arial,sans-serif;font-weight:500;line-height:1.1}.footer{display:none}.swagger-section .swagger-ui-wrap h2{padding:0}h2{margin:0;margin-bottom:5px}.markdown p,.swagger-section .swagger-ui-wrap .code{font-size:15px;font-family:Arvo,serif}.swagger-section .swagger-ui-wrap b{font-family:Arvo,serif}#signin:hover{cursor:pointer}.dropdown-menu{padding:15px}.navbar-right .dropdown-menu{left:0;right:auto}#signinbutton{width:100%;height:32px;font-size:13px;font-weight:700;color:#08b}.navbar-default .nav>li .details{color:#000;text-transform:none;font-size:15px;font-weight:400;font-family:Open Sans,sans-serif;font-style:italic;line-height:20px;top:-2px}.navbar-default .nav>li .details:hover{color:#000}#signout{width:100%;height:32px;font-size:13px;font-weight:700;color:#08b} -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/css/typography.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/css/typography.css -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/fonts/DroidSans-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/fonts/DroidSans-Bold.ttf -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/fonts/DroidSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/fonts/DroidSans.ttf -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/collapse.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/collapse.gif -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/expand.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/expand.gif -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/explorer_icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/explorer_icons.png -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/favicon-16x16.png -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/favicon-32x32.png -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/favicon.ico -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/logo_small.png -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/pet_store_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/pet_store_api.png -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/throbber.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/throbber.gif -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/images/wordnik_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiChengPengGH/CodeGenerator/42d86eacaae780925b02120ecc0b720719340036/src/main/resources/swagger-ui/images/wordnik_api.png -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Swagger UI 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 | 34 | 35 | 92 | 93 | 94 | 95 | 110 | 111 |
 
112 |
113 | 114 | 115 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/ca.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Advertència: Obsolet", 6 | "Implementation Notes":"Notes d'implementació", 7 | "Response Class":"Classe de la Resposta", 8 | "Status":"Estatus", 9 | "Parameters":"Paràmetres", 10 | "Parameter":"Paràmetre", 11 | "Value":"Valor", 12 | "Description":"Descripció", 13 | "Parameter Type":"Tipus del Paràmetre", 14 | "Data Type":"Tipus de la Dada", 15 | "Response Messages":"Missatges de la Resposta", 16 | "HTTP Status Code":"Codi d'Estatus HTTP", 17 | "Reason":"Raó", 18 | "Response Model":"Model de la Resposta", 19 | "Request URL":"URL de la Sol·licitud", 20 | "Response Body":"Cos de la Resposta", 21 | "Response Code":"Codi de la Resposta", 22 | "Response Headers":"Capçaleres de la Resposta", 23 | "Hide Response":"Amagar Resposta", 24 | "Try it out!":"Prova-ho!", 25 | "Show/Hide":"Mostrar/Amagar", 26 | "List Operations":"Llista Operacions", 27 | "Expand Operations":"Expandir Operacions", 28 | "Raw":"Cru", 29 | "can't parse JSON. Raw result":"no puc analitzar el JSON. Resultat cru", 30 | "Example Value":"Valor d'Exemple", 31 | "Model Schema":"Esquema del Model", 32 | "Model":"Model", 33 | "apply":"aplicar", 34 | "Username":"Nom d'usuari", 35 | "Password":"Contrasenya", 36 | "Terms of service":"Termes del servei", 37 | "Created by":"Creat per", 38 | "See more at":"Veure més en", 39 | "Contact the developer":"Contactar amb el desenvolupador", 40 | "api version":"versió de la api", 41 | "Response Content Type":"Tipus de Contingut de la Resposta", 42 | "fetching resource":"recollint recurs", 43 | "fetching resource list":"recollins llista de recursos", 44 | "Explore":"Explorant", 45 | "Show Swagger Petstore Example Apis":"Mostrar API d'Exemple Swagger Petstore", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"No es pot llegir del servidor. Potser no teniu la configuració de control d'accés apropiada.", 47 | "Please specify the protocol for":"Si us plau, especifiqueu el protocol per a", 48 | "Can't read swagger JSON from":"No es pot llegir el JSON de swagger des de", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Finalitzada la càrrega del recurs informatiu. Renderitzant Swagger UI", 50 | "Unable to read api":"No es pot llegir l'api", 51 | "from path":"des de la ruta", 52 | "server returned":"el servidor ha retornat" 53 | }); 54 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/el.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Προειδοποίηση: Έχει αποσυρθεί", 6 | "Implementation Notes":"Σημειώσεις Υλοποίησης", 7 | "Response Class":"Απόκριση", 8 | "Status":"Κατάσταση", 9 | "Parameters":"Παράμετροι", 10 | "Parameter":"Παράμετρος", 11 | "Value":"Τιμή", 12 | "Description":"Περιγραφή", 13 | "Parameter Type":"Τύπος Παραμέτρου", 14 | "Data Type":"Τύπος Δεδομένων", 15 | "Response Messages":"Μηνύματα Απόκρισης", 16 | "HTTP Status Code":"Κωδικός Κατάστασης HTTP", 17 | "Reason":"Αιτιολογία", 18 | "Response Model":"Μοντέλο Απόκρισης", 19 | "Request URL":"URL Αιτήματος", 20 | "Response Body":"Σώμα Απόκρισης", 21 | "Response Code":"Κωδικός Απόκρισης", 22 | "Response Headers":"Επικεφαλίδες Απόκρισης", 23 | "Hide Response":"Απόκρυψη Απόκρισης", 24 | "Headers":"Επικεφαλίδες", 25 | "Try it out!":"Δοκιμάστε το!", 26 | "Show/Hide":"Εμφάνιση/Απόκρυψη", 27 | "List Operations":"Λίστα Λειτουργιών", 28 | "Expand Operations":"Ανάπτυξη Λειτουργιών", 29 | "Raw":"Ακατέργαστο", 30 | "can't parse JSON. Raw result":"αδυναμία ανάλυσης JSON. Ακατέργαστο αποτέλεσμα", 31 | "Example Value":"Παράδειγμα Τιμής", 32 | "Model Schema":"Σχήμα Μοντέλου", 33 | "Model":"Μοντέλο", 34 | "Click to set as parameter value":"Πατήστε για να θέσετε τιμή παραμέτρου", 35 | "apply":"εφαρμογή", 36 | "Username":"Όνομα χρήση", 37 | "Password":"Κωδικός πρόσβασης", 38 | "Terms of service":"Όροι χρήσης", 39 | "Created by":"Δημιουργήθηκε από", 40 | "See more at":"Δείτε περισσότερα στο", 41 | "Contact the developer":"Επικοινωνήστε με τον προγραμματιστή", 42 | "api version":"έκδοση api", 43 | "Response Content Type":"Τύπος Περιεχομένου Απόκρισης", 44 | "Parameter content type:":"Τύπος περιεχομένου παραμέτρου:", 45 | "fetching resource":"παραλαβή πόρου", 46 | "fetching resource list":"παραλαβή λίστας πόρων", 47 | "Explore":"Εξερεύνηση", 48 | "Show Swagger Petstore Example Apis":"Εμφάνιση Api Δειγμάτων Petstore του Swagger", 49 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Αδυναμία ανάγνωσης από τον εξυπηρετητή. Μπορεί να μην έχει κατάλληλες ρυθμίσεις για access-control-origin.", 50 | "Please specify the protocol for":"Παρακαλώ προσδιορίστε το πρωτόκολλο για", 51 | "Can't read swagger JSON from":"Αδυναμία ανάγνωσης swagger JSON από", 52 | "Finished Loading Resource Information. Rendering Swagger UI":"Ολοκλήρωση Φόρτωσης Πληροφορικών Πόρου. Παρουσίαση Swagger UI", 53 | "Unable to read api":"Αδυναμία ανάγνωσης api", 54 | "from path":"από το μονοπάτι", 55 | "server returned":"ο εξυπηρετηρής επέστρεψε" 56 | }); 57 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/en.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Warning: Deprecated", 6 | "Implementation Notes":"Implementation Notes", 7 | "Response Class":"Response Class", 8 | "Status":"Status", 9 | "Parameters":"Parameters", 10 | "Parameter":"Parameter", 11 | "Value":"Value", 12 | "Description":"Description", 13 | "Parameter Type":"Parameter Type", 14 | "Data Type":"Data Type", 15 | "Response Messages":"Response Messages", 16 | "HTTP Status Code":"HTTP Status Code", 17 | "Reason":"Reason", 18 | "Response Model":"Response Model", 19 | "Request URL":"Request URL", 20 | "Response Body":"Response Body", 21 | "Response Code":"Response Code", 22 | "Response Headers":"Response Headers", 23 | "Hide Response":"Hide Response", 24 | "Headers":"Headers", 25 | "Try it out!":"Try it out!", 26 | "Show/Hide":"Show/Hide", 27 | "List Operations":"List Operations", 28 | "Expand Operations":"Expand Operations", 29 | "Raw":"Raw", 30 | "can't parse JSON. Raw result":"can't parse JSON. Raw result", 31 | "Example Value":"Example Value", 32 | "Model Schema":"Model Schema", 33 | "Model":"Model", 34 | "Click to set as parameter value":"Click to set as parameter value", 35 | "apply":"apply", 36 | "Username":"Username", 37 | "Password":"Password", 38 | "Terms of service":"Terms of service", 39 | "Created by":"Created by", 40 | "See more at":"See more at", 41 | "Contact the developer":"Contact the developer", 42 | "api version":"api version", 43 | "Response Content Type":"Response Content Type", 44 | "Parameter content type:":"Parameter content type:", 45 | "fetching resource":"fetching resource", 46 | "fetching resource list":"fetching resource list", 47 | "Explore":"Explore", 48 | "Show Swagger Petstore Example Apis":"Show Swagger Petstore Example Apis", 49 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Can't read from server. It may not have the appropriate access-control-origin settings.", 50 | "Please specify the protocol for":"Please specify the protocol for", 51 | "Can't read swagger JSON from":"Can't read swagger JSON from", 52 | "Finished Loading Resource Information. Rendering Swagger UI":"Finished Loading Resource Information. Rendering Swagger UI", 53 | "Unable to read api":"Unable to read api", 54 | "from path":"from path", 55 | "server returned":"server returned" 56 | }); 57 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/es.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Advertencia: Obsoleto", 6 | "Implementation Notes":"Notas de implementación", 7 | "Response Class":"Clase de la Respuesta", 8 | "Status":"Status", 9 | "Parameters":"Parámetros", 10 | "Parameter":"Parámetro", 11 | "Value":"Valor", 12 | "Description":"Descripción", 13 | "Parameter Type":"Tipo del Parámetro", 14 | "Data Type":"Tipo del Dato", 15 | "Response Messages":"Mensajes de la Respuesta", 16 | "HTTP Status Code":"Código de Status HTTP", 17 | "Reason":"Razón", 18 | "Response Model":"Modelo de la Respuesta", 19 | "Request URL":"URL de la Solicitud", 20 | "Response Body":"Cuerpo de la Respuesta", 21 | "Response Code":"Código de la Respuesta", 22 | "Response Headers":"Encabezados de la Respuesta", 23 | "Hide Response":"Ocultar Respuesta", 24 | "Try it out!":"Pruébalo!", 25 | "Show/Hide":"Mostrar/Ocultar", 26 | "List Operations":"Listar Operaciones", 27 | "Expand Operations":"Expandir Operaciones", 28 | "Raw":"Crudo", 29 | "can't parse JSON. Raw result":"no puede parsear el JSON. Resultado crudo", 30 | "Example Value":"Valor de Ejemplo", 31 | "Model Schema":"Esquema del Modelo", 32 | "Model":"Modelo", 33 | "apply":"aplicar", 34 | "Username":"Nombre de usuario", 35 | "Password":"Contraseña", 36 | "Terms of service":"Términos de Servicio", 37 | "Created by":"Creado por", 38 | "See more at":"Ver más en", 39 | "Contact the developer":"Contactar al desarrollador", 40 | "api version":"versión de la api", 41 | "Response Content Type":"Tipo de Contenido (Content Type) de la Respuesta", 42 | "fetching resource":"buscando recurso", 43 | "fetching resource list":"buscando lista del recurso", 44 | "Explore":"Explorar", 45 | "Show Swagger Petstore Example Apis":"Mostrar Api Ejemplo de Swagger Petstore", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"No se puede leer del servidor. Tal vez no tiene la configuración de control de acceso de origen (access-control-origin) apropiado.", 47 | "Please specify the protocol for":"Por favor, especificar el protocola para", 48 | "Can't read swagger JSON from":"No se puede leer el JSON de swagger desde", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Finalizada la carga del recurso de Información. Mostrando Swagger UI", 50 | "Unable to read api":"No se puede leer la api", 51 | "from path":"desde ruta", 52 | "server returned":"el servidor retornó" 53 | }); 54 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/fr.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Avertissement : Obsolète", 6 | "Implementation Notes":"Notes d'implémentation", 7 | "Response Class":"Classe de la réponse", 8 | "Status":"Statut", 9 | "Parameters":"Paramètres", 10 | "Parameter":"Paramètre", 11 | "Value":"Valeur", 12 | "Description":"Description", 13 | "Parameter Type":"Type du paramètre", 14 | "Data Type":"Type de données", 15 | "Response Messages":"Messages de la réponse", 16 | "HTTP Status Code":"Code de statut HTTP", 17 | "Reason":"Raison", 18 | "Response Model":"Modèle de réponse", 19 | "Request URL":"URL appelée", 20 | "Response Body":"Corps de la réponse", 21 | "Response Code":"Code de la réponse", 22 | "Response Headers":"En-têtes de la réponse", 23 | "Hide Response":"Cacher la réponse", 24 | "Headers":"En-têtes", 25 | "Try it out!":"Testez !", 26 | "Show/Hide":"Afficher/Masquer", 27 | "List Operations":"Liste des opérations", 28 | "Expand Operations":"Développer les opérations", 29 | "Raw":"Brut", 30 | "can't parse JSON. Raw result":"impossible de décoder le JSON. Résultat brut", 31 | "Example Value":"Exemple la valeur", 32 | "Model Schema":"Définition du modèle", 33 | "Model":"Modèle", 34 | "apply":"appliquer", 35 | "Username":"Nom d'utilisateur", 36 | "Password":"Mot de passe", 37 | "Terms of service":"Conditions de service", 38 | "Created by":"Créé par", 39 | "See more at":"Voir plus sur", 40 | "Contact the developer":"Contacter le développeur", 41 | "api version":"version de l'api", 42 | "Response Content Type":"Content Type de la réponse", 43 | "fetching resource":"récupération de la ressource", 44 | "fetching resource list":"récupération de la liste de ressources", 45 | "Explore":"Explorer", 46 | "Show Swagger Petstore Example Apis":"Montrer les Apis de l'exemple Petstore de Swagger", 47 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Impossible de lire à partir du serveur. Il se peut que les réglages access-control-origin ne soient pas appropriés.", 48 | "Please specify the protocol for":"Veuillez spécifier un protocole pour", 49 | "Can't read swagger JSON from":"Impossible de lire le JSON swagger à partir de", 50 | "Finished Loading Resource Information. Rendering Swagger UI":"Chargement des informations terminé. Affichage de Swagger UI", 51 | "Unable to read api":"Impossible de lire l'api", 52 | "from path":"à partir du chemin", 53 | "server returned":"réponse du serveur" 54 | }); 55 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/geo.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"ყურადღება: აღარ გამოიყენება", 6 | "Implementation Notes":"იმპლემენტაციის აღწერა", 7 | "Response Class":"რესპონს კლასი", 8 | "Status":"სტატუსი", 9 | "Parameters":"პარამეტრები", 10 | "Parameter":"პარამეტრი", 11 | "Value":"მნიშვნელობა", 12 | "Description":"აღწერა", 13 | "Parameter Type":"პარამეტრის ტიპი", 14 | "Data Type":"მონაცემის ტიპი", 15 | "Response Messages":"პასუხი", 16 | "HTTP Status Code":"HTTP სტატუსი", 17 | "Reason":"მიზეზი", 18 | "Response Model":"რესპონს მოდელი", 19 | "Request URL":"მოთხოვნის URL", 20 | "Response Body":"პასუხის სხეული", 21 | "Response Code":"პასუხის კოდი", 22 | "Response Headers":"პასუხის ჰედერები", 23 | "Hide Response":"დამალე პასუხი", 24 | "Headers":"ჰედერები", 25 | "Try it out!":"ცადე !", 26 | "Show/Hide":"გამოჩენა/დამალვა", 27 | "List Operations":"ოპერაციების სია", 28 | "Expand Operations":"ოპერაციები ვრცლად", 29 | "Raw":"ნედლი", 30 | "can't parse JSON. Raw result":"JSON-ის დამუშავება ვერ მოხერხდა. ნედლი პასუხი", 31 | "Example Value":"მაგალითი", 32 | "Model Schema":"მოდელის სტრუქტურა", 33 | "Model":"მოდელი", 34 | "Click to set as parameter value":"პარამეტრისთვის მნიშვნელობის მისანიჭებლად, დააკლიკე", 35 | "apply":"გამოყენება", 36 | "Username":"მოხმარებელი", 37 | "Password":"პაროლი", 38 | "Terms of service":"მომსახურების პირობები", 39 | "Created by":"შექმნა", 40 | "See more at":"ნახე ვრცლად", 41 | "Contact the developer":"დაუკავშირდი დეველოპერს", 42 | "api version":"api ვერსია", 43 | "Response Content Type":"პასუხის კონტენტის ტიპი", 44 | "Parameter content type:":"პარამეტრის კონტენტის ტიპი:", 45 | "fetching resource":"რესურსების მიღება", 46 | "fetching resource list":"რესურსების სიის მიღება", 47 | "Explore":"ნახვა", 48 | "Show Swagger Petstore Example Apis":"ნახე Swagger Petstore სამაგალითო Api", 49 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"სერვერთან დაკავშირება ვერ ხერხდება. შეამოწმეთ access-control-origin.", 50 | "Please specify the protocol for":"მიუთითეთ პროტოკოლი", 51 | "Can't read swagger JSON from":"swagger JSON წაკითხვა ვერ მოხერხდა", 52 | "Finished Loading Resource Information. Rendering Swagger UI":"რესურსების ჩატვირთვა სრულდება. Swagger UI რენდერდება", 53 | "Unable to read api":"api წაკითხვა ვერ მოხერხდა", 54 | "from path":"მისამართიდან", 55 | "server returned":"სერვერმა დააბრუნა" 56 | }); 57 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/it.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Attenzione: Deprecato", 6 | "Implementation Notes":"Note di implementazione", 7 | "Response Class":"Classe della risposta", 8 | "Status":"Stato", 9 | "Parameters":"Parametri", 10 | "Parameter":"Parametro", 11 | "Value":"Valore", 12 | "Description":"Descrizione", 13 | "Parameter Type":"Tipo di parametro", 14 | "Data Type":"Tipo di dato", 15 | "Response Messages":"Messaggi della risposta", 16 | "HTTP Status Code":"Codice stato HTTP", 17 | "Reason":"Motivo", 18 | "Response Model":"Modello di risposta", 19 | "Request URL":"URL della richiesta", 20 | "Response Body":"Corpo della risposta", 21 | "Response Code":"Oggetto della risposta", 22 | "Response Headers":"Intestazioni della risposta", 23 | "Hide Response":"Nascondi risposta", 24 | "Try it out!":"Provalo!", 25 | "Show/Hide":"Mostra/Nascondi", 26 | "List Operations":"Mostra operazioni", 27 | "Expand Operations":"Espandi operazioni", 28 | "Raw":"Grezzo (raw)", 29 | "can't parse JSON. Raw result":"non è possibile parsare il JSON. Risultato grezzo (raw).", 30 | "Model Schema":"Schema del modello", 31 | "Model":"Modello", 32 | "apply":"applica", 33 | "Username":"Nome utente", 34 | "Password":"Password", 35 | "Terms of service":"Condizioni del servizio", 36 | "Created by":"Creato da", 37 | "See more at":"Informazioni aggiuntive:", 38 | "Contact the developer":"Contatta lo sviluppatore", 39 | "api version":"versione api", 40 | "Response Content Type":"Tipo di contenuto (content type) della risposta", 41 | "fetching resource":"recuperando la risorsa", 42 | "fetching resource list":"recuperando lista risorse", 43 | "Explore":"Esplora", 44 | "Show Swagger Petstore Example Apis":"Mostra le api di esempio di Swagger Petstore", 45 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Non è possibile leggere dal server. Potrebbe non avere le impostazioni di controllo accesso origine (access-control-origin) appropriate.", 46 | "Please specify the protocol for":"Si prega di specificare il protocollo per", 47 | "Can't read swagger JSON from":"Impossibile leggere JSON swagger da:", 48 | "Finished Loading Resource Information. Rendering Swagger UI":"Lettura informazioni risorse termianta. Swagger UI viene mostrata", 49 | "Unable to read api":"Impossibile leggere la api", 50 | "from path":"da cartella", 51 | "server returned":"il server ha restituito" 52 | }); 53 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/ja.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"警告: 廃止予定", 6 | "Implementation Notes":"実装メモ", 7 | "Response Class":"レスポンスクラス", 8 | "Status":"ステータス", 9 | "Parameters":"パラメータ群", 10 | "Parameter":"パラメータ", 11 | "Value":"値", 12 | "Description":"説明", 13 | "Parameter Type":"パラメータタイプ", 14 | "Data Type":"データタイプ", 15 | "Response Messages":"レスポンスメッセージ", 16 | "HTTP Status Code":"HTTPステータスコード", 17 | "Reason":"理由", 18 | "Response Model":"レスポンスモデル", 19 | "Request URL":"リクエストURL", 20 | "Response Body":"レスポンスボディ", 21 | "Response Code":"レスポンスコード", 22 | "Response Headers":"レスポンスヘッダ", 23 | "Hide Response":"レスポンスを隠す", 24 | "Headers":"ヘッダ", 25 | "Try it out!":"実際に実行!", 26 | "Show/Hide":"表示/非表示", 27 | "List Operations":"操作一覧", 28 | "Expand Operations":"操作の展開", 29 | "Raw":"未加工", 30 | "can't parse JSON. Raw result":"JSONへ解釈できません. 未加工の結果", 31 | "Example Value":"値の例", 32 | "Model Schema":"モデルスキーマ", 33 | "Model":"モデル", 34 | "Click to set as parameter value":"パラメータ値と設定するにはクリック", 35 | "apply":"実行", 36 | "Username":"ユーザ名", 37 | "Password":"パスワード", 38 | "Terms of service":"サービス利用規約", 39 | "Created by":"Created by", 40 | "See more at":"詳細を見る", 41 | "Contact the developer":"開発者に連絡", 42 | "api version":"APIバージョン", 43 | "Response Content Type":"レスポンス コンテンツタイプ", 44 | "Parameter content type:":"パラメータコンテンツタイプ:", 45 | "fetching resource":"リソースの取得", 46 | "fetching resource list":"リソース一覧の取得", 47 | "Explore":"調査", 48 | "Show Swagger Petstore Example Apis":"SwaggerペットストアAPIの表示", 49 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"サーバから読み込めません. 適切なaccess-control-origin設定を持っていない可能性があります.", 50 | "Please specify the protocol for":"プロトコルを指定してください", 51 | "Can't read swagger JSON from":"次からswagger JSONを読み込めません", 52 | "Finished Loading Resource Information. Rendering Swagger UI":"リソース情報の読み込みが完了しました. Swagger UIを描画しています", 53 | "Unable to read api":"APIを読み込めません", 54 | "from path":"次のパスから", 55 | "server returned":"サーバからの返答" 56 | }); 57 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/ko-kr.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"경고:폐기예정됨", 6 | "Implementation Notes":"구현 노트", 7 | "Response Class":"응답 클래스", 8 | "Status":"상태", 9 | "Parameters":"매개변수들", 10 | "Parameter":"매개변수", 11 | "Value":"값", 12 | "Description":"설명", 13 | "Parameter Type":"매개변수 타입", 14 | "Data Type":"데이터 타입", 15 | "Response Messages":"응답 메세지", 16 | "HTTP Status Code":"HTTP 상태 코드", 17 | "Reason":"원인", 18 | "Response Model":"응답 모델", 19 | "Request URL":"요청 URL", 20 | "Response Body":"응답 본문", 21 | "Response Code":"응답 코드", 22 | "Response Headers":"응답 헤더", 23 | "Hide Response":"응답 숨기기", 24 | "Headers":"헤더", 25 | "Try it out!":"써보기!", 26 | "Show/Hide":"보이기/숨기기", 27 | "List Operations":"목록 작업", 28 | "Expand Operations":"전개 작업", 29 | "Raw":"원본", 30 | "can't parse JSON. Raw result":"JSON을 파싱할수 없음. 원본결과:", 31 | "Model Schema":"모델 스키마", 32 | "Model":"모델", 33 | "apply":"적용", 34 | "Username":"사용자 이름", 35 | "Password":"암호", 36 | "Terms of service":"이용약관", 37 | "Created by":"작성자", 38 | "See more at":"추가정보:", 39 | "Contact the developer":"개발자에게 문의", 40 | "api version":"api버전", 41 | "Response Content Type":"응답Content Type", 42 | "fetching resource":"리소스 가져오기", 43 | "fetching resource list":"리소스 목록 가져오기", 44 | "Explore":"탐색", 45 | "Show Swagger Petstore Example Apis":"Swagger Petstore 예제 보기", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"서버로부터 읽어들일수 없습니다. access-control-origin 설정이 올바르지 않을수 있습니다.", 47 | "Please specify the protocol for":"다음을 위한 프로토콜을 정하세요", 48 | "Can't read swagger JSON from":"swagger JSON 을 다음으로 부터 읽을수 없습니다", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"리소스 정보 불러오기 완료. Swagger UI 랜더링", 50 | "Unable to read api":"api를 읽을 수 없습니다.", 51 | "from path":"다음 경로로 부터", 52 | "server returned":"서버 응답함." 53 | }); 54 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/pl.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Uwaga: Wycofane", 6 | "Implementation Notes":"Uwagi Implementacji", 7 | "Response Class":"Klasa Odpowiedzi", 8 | "Status":"Status", 9 | "Parameters":"Parametry", 10 | "Parameter":"Parametr", 11 | "Value":"Wartość", 12 | "Description":"Opis", 13 | "Parameter Type":"Typ Parametru", 14 | "Data Type":"Typ Danych", 15 | "Response Messages":"Wiadomości Odpowiedzi", 16 | "HTTP Status Code":"Kod Statusu HTTP", 17 | "Reason":"Przyczyna", 18 | "Response Model":"Model Odpowiedzi", 19 | "Request URL":"URL Wywołania", 20 | "Response Body":"Treść Odpowiedzi", 21 | "Response Code":"Kod Odpowiedzi", 22 | "Response Headers":"Nagłówki Odpowiedzi", 23 | "Hide Response":"Ukryj Odpowiedź", 24 | "Headers":"Nagłówki", 25 | "Try it out!":"Wypróbuj!", 26 | "Show/Hide":"Pokaż/Ukryj", 27 | "List Operations":"Lista Operacji", 28 | "Expand Operations":"Rozwiń Operacje", 29 | "Raw":"Nieprzetworzone", 30 | "can't parse JSON. Raw result":"nie można przetworzyć pliku JSON. Nieprzetworzone dane", 31 | "Model Schema":"Schemat Modelu", 32 | "Model":"Model", 33 | "apply":"użyj", 34 | "Username":"Nazwa użytkownika", 35 | "Password":"Hasło", 36 | "Terms of service":"Warunki używania", 37 | "Created by":"Utworzone przez", 38 | "See more at":"Zobacz więcej na", 39 | "Contact the developer":"Kontakt z deweloperem", 40 | "api version":"wersja api", 41 | "Response Content Type":"Typ Zasobu Odpowiedzi", 42 | "fetching resource":"ładowanie zasobu", 43 | "fetching resource list":"ładowanie listy zasobów", 44 | "Explore":"Eksploruj", 45 | "Show Swagger Petstore Example Apis":"Pokaż Przykładowe Api Swagger Petstore", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Brak połączenia z serwerem. Może on nie mieć odpowiednich ustawień access-control-origin.", 47 | "Please specify the protocol for":"Proszę podać protokół dla", 48 | "Can't read swagger JSON from":"Nie można odczytać swagger JSON z", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Ukończono Ładowanie Informacji o Zasobie. Renderowanie Swagger UI", 50 | "Unable to read api":"Nie można odczytać api", 51 | "from path":"ze ścieżki", 52 | "server returned":"serwer zwrócił" 53 | }); 54 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/pt.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Aviso: Depreciado", 6 | "Implementation Notes":"Notas de Implementação", 7 | "Response Class":"Classe de resposta", 8 | "Status":"Status", 9 | "Parameters":"Parâmetros", 10 | "Parameter":"Parâmetro", 11 | "Value":"Valor", 12 | "Description":"Descrição", 13 | "Parameter Type":"Tipo de parâmetro", 14 | "Data Type":"Tipo de dados", 15 | "Response Messages":"Mensagens de resposta", 16 | "HTTP Status Code":"Código de status HTTP", 17 | "Reason":"Razão", 18 | "Response Model":"Modelo resposta", 19 | "Request URL":"URL requisição", 20 | "Response Body":"Corpo da resposta", 21 | "Response Code":"Código da resposta", 22 | "Response Headers":"Cabeçalho da resposta", 23 | "Headers":"Cabeçalhos", 24 | "Hide Response":"Esconder resposta", 25 | "Try it out!":"Tente agora!", 26 | "Show/Hide":"Mostrar/Esconder", 27 | "List Operations":"Listar operações", 28 | "Expand Operations":"Expandir operações", 29 | "Raw":"Cru", 30 | "can't parse JSON. Raw result":"Falha ao analisar JSON. Resulto cru", 31 | "Model Schema":"Modelo esquema", 32 | "Model":"Modelo", 33 | "apply":"Aplicar", 34 | "Username":"Usuário", 35 | "Password":"Senha", 36 | "Terms of service":"Termos do serviço", 37 | "Created by":"Criado por", 38 | "See more at":"Veja mais em", 39 | "Contact the developer":"Contate o desenvolvedor", 40 | "api version":"Versão api", 41 | "Response Content Type":"Tipo de conteúdo da resposta", 42 | "fetching resource":"busca recurso", 43 | "fetching resource list":"buscando lista de recursos", 44 | "Explore":"Explorar", 45 | "Show Swagger Petstore Example Apis":"Show Swagger Petstore Example Apis", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Não é possível ler do servidor. Pode não ter as apropriadas configurações access-control-origin", 47 | "Please specify the protocol for":"Por favor especifique o protocolo", 48 | "Can't read swagger JSON from":"Não é possível ler o JSON Swagger de", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Carregar informação de recurso finalizada. Renderizando Swagger UI", 50 | "Unable to read api":"Não foi possível ler api", 51 | "from path":"do caminho", 52 | "server returned":"servidor retornou" 53 | }); 54 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/ru.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Предупреждение: Устарело", 6 | "Implementation Notes":"Заметки", 7 | "Response Class":"Пример ответа", 8 | "Status":"Статус", 9 | "Parameters":"Параметры", 10 | "Parameter":"Параметр", 11 | "Value":"Значение", 12 | "Description":"Описание", 13 | "Parameter Type":"Тип параметра", 14 | "Data Type":"Тип данных", 15 | "HTTP Status Code":"HTTP код", 16 | "Reason":"Причина", 17 | "Response Model":"Структура ответа", 18 | "Request URL":"URL запроса", 19 | "Response Body":"Тело ответа", 20 | "Response Code":"HTTP код ответа", 21 | "Response Headers":"Заголовки ответа", 22 | "Hide Response":"Спрятать ответ", 23 | "Headers":"Заголовки", 24 | "Response Messages":"Что может прийти в ответ", 25 | "Try it out!":"Попробовать!", 26 | "Show/Hide":"Показать/Скрыть", 27 | "List Operations":"Операции кратко", 28 | "Expand Operations":"Операции подробно", 29 | "Raw":"В сыром виде", 30 | "can't parse JSON. Raw result":"Не удается распарсить ответ:", 31 | "Example Value":"Пример", 32 | "Model Schema":"Структура", 33 | "Model":"Описание", 34 | "Click to set as parameter value":"Нажмите, чтобы испльзовать в качестве значения параметра", 35 | "apply":"применить", 36 | "Username":"Имя пользователя", 37 | "Password":"Пароль", 38 | "Terms of service":"Условия использования", 39 | "Created by":"Разработано", 40 | "See more at":"Еще тут", 41 | "Contact the developer":"Связаться с разработчиком", 42 | "api version":"Версия API", 43 | "Response Content Type":"Content Type ответа", 44 | "Parameter content type:":"Content Type параметра:", 45 | "fetching resource":"Получение ресурса", 46 | "fetching resource list":"Получение ресурсов", 47 | "Explore":"Показать", 48 | "Show Swagger Petstore Example Apis":"Показать примеры АПИ", 49 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Не удается получить ответ от сервера. Возможно, проблема с настройками доступа", 50 | "Please specify the protocol for":"Пожалуйста, укажите протокол для", 51 | "Can't read swagger JSON from":"Не получается прочитать swagger json из", 52 | "Finished Loading Resource Information. Rendering Swagger UI":"Загрузка информации о ресурсах завершена. Рендерим", 53 | "Unable to read api":"Не удалось прочитать api", 54 | "from path":"по адресу", 55 | "server returned":"сервер сказал" 56 | }); 57 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/tr.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Uyarı: Deprecated", 6 | "Implementation Notes":"Gerçekleştirim Notları", 7 | "Response Class":"Dönen Sınıf", 8 | "Status":"Statü", 9 | "Parameters":"Parametreler", 10 | "Parameter":"Parametre", 11 | "Value":"Değer", 12 | "Description":"Açıklama", 13 | "Parameter Type":"Parametre Tipi", 14 | "Data Type":"Veri Tipi", 15 | "Response Messages":"Dönüş Mesajı", 16 | "HTTP Status Code":"HTTP Statü Kodu", 17 | "Reason":"Gerekçe", 18 | "Response Model":"Dönüş Modeli", 19 | "Request URL":"İstek URL", 20 | "Response Body":"Dönüş İçeriği", 21 | "Response Code":"Dönüş Kodu", 22 | "Response Headers":"Dönüş Üst Bilgileri", 23 | "Hide Response":"Dönüşü Gizle", 24 | "Headers":"Üst Bilgiler", 25 | "Try it out!":"Dene!", 26 | "Show/Hide":"Göster/Gizle", 27 | "List Operations":"Operasyonları Listele", 28 | "Expand Operations":"Operasyonları Aç", 29 | "Raw":"Ham", 30 | "can't parse JSON. Raw result":"JSON çözümlenemiyor. Ham sonuç", 31 | "Model Schema":"Model Şema", 32 | "Model":"Model", 33 | "apply":"uygula", 34 | "Username":"Kullanıcı Adı", 35 | "Password":"Parola", 36 | "Terms of service":"Servis şartları", 37 | "Created by":"Oluşturan", 38 | "See more at":"Daha fazlası için", 39 | "Contact the developer":"Geliştirici ile İletişime Geçin", 40 | "api version":"api versiyon", 41 | "Response Content Type":"Dönüş İçerik Tipi", 42 | "fetching resource":"kaynak getiriliyor", 43 | "fetching resource list":"kaynak listesi getiriliyor", 44 | "Explore":"Keşfet", 45 | "Show Swagger Petstore Example Apis":"Swagger Petstore Örnek Api'yi Gör", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Sunucudan okuma yapılamıyor. Sunucu access-control-origin ayarlarınızı kontrol edin.", 47 | "Please specify the protocol for":"Lütfen istenen adres için protokol belirtiniz", 48 | "Can't read swagger JSON from":"Swagger JSON bu kaynaktan okunamıyor", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Kaynak baglantısı tamamlandı. Swagger UI gösterime hazırlanıyor", 50 | "Unable to read api":"api okunamadı", 51 | "from path":"yoldan", 52 | "server returned":"sunucuya dönüldü" 53 | }); 54 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/translator.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Translator for documentation pages. 5 | * 6 | * To enable translation you should include one of language-files in your index.html 7 | * after . 8 | * For example - 9 | * 10 | * If you wish to translate some new texts you should do two things: 11 | * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too. 12 | * 2. Mark that text it templates this way New Phrase or . 13 | * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate. 14 | * 15 | */ 16 | window.SwaggerTranslator = { 17 | 18 | _words:[], 19 | 20 | translate: function(sel) { 21 | var $this = this; 22 | sel = sel || '[data-sw-translate]'; 23 | 24 | $(sel).each(function() { 25 | $(this).html($this._tryTranslate($(this).html())); 26 | 27 | $(this).val($this._tryTranslate($(this).val())); 28 | $(this).attr('title', $this._tryTranslate($(this).attr('title'))); 29 | }); 30 | }, 31 | 32 | _tryTranslate: function(word) { 33 | return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word; 34 | }, 35 | 36 | learn: function(wordsMap) { 37 | this._words = wordsMap; 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lang/zh-cn.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"警告:已过时", 6 | "Implementation Notes":"实现备注", 7 | "Response Class":"响应类", 8 | "Status":"状态", 9 | "Parameters":"参数", 10 | "Parameter":"参数", 11 | "Value":"值", 12 | "Description":"描述", 13 | "Parameter Type":"参数类型", 14 | "Data Type":"数据类型", 15 | "Response Messages":"响应消息", 16 | "HTTP Status Code":"HTTP状态码", 17 | "Reason":"原因", 18 | "Response Model":"响应模型", 19 | "Request URL":"请求URL", 20 | "Response Body":"响应体", 21 | "Response Code":"响应码", 22 | "Response Headers":"响应头", 23 | "Hide Response":"隐藏响应", 24 | "Headers":"头", 25 | "Try it out!":"试一下!", 26 | "Show/Hide":"显示/隐藏", 27 | "List Operations":"显示操作", 28 | "Expand Operations":"展开操作", 29 | "Raw":"原始", 30 | "can't parse JSON. Raw result":"无法解析JSON. 原始结果", 31 | "Example Value":"示例", 32 | "Click to set as parameter value":"点击设置参数", 33 | "Model Schema":"模型架构", 34 | "Model":"模型", 35 | "apply":"应用", 36 | "Username":"用户名", 37 | "Password":"密码", 38 | "Terms of service":"服务条款", 39 | "Created by":"创建者", 40 | "See more at":"查看更多:", 41 | "Contact the developer":"联系开发者", 42 | "api version":"api版本", 43 | "Response Content Type":"响应Content Type", 44 | "Parameter content type:":"参数类型:", 45 | "fetching resource":"正在获取资源", 46 | "fetching resource list":"正在获取资源列表", 47 | "Explore":"浏览", 48 | "Show Swagger Petstore Example Apis":"显示 Swagger Petstore 示例 Apis", 49 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"无法从服务器读取。可能没有正确设置access-control-origin。", 50 | "Please specify the protocol for":"请指定协议:", 51 | "Can't read swagger JSON from":"无法读取swagger JSON于", 52 | "Finished Loading Resource Information. Rendering Swagger UI":"已加载资源信息。正在渲染Swagger UI", 53 | "Unable to read api":"无法读取api", 54 | "from path":"从路径", 55 | "server returned":"服务器返回" 56 | }); 57 | -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lib/highlight.9.1.0.pack_extended.js: -------------------------------------------------------------------------------- 1 | "use strict";!function(){var h,l;h=hljs.configure,hljs.configure=function(l){var i=l.highlightSizeThreshold;hljs.highlightSizeThreshold=i===+i?i:null,h.call(this,l)},l=hljs.highlightBlock,hljs.highlightBlock=function(h){var i=h.innerHTML,g=hljs.highlightSizeThreshold;(null==g||g>i.length)&&l.call(hljs,h)}}(); -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lib/jquery.ba-bbq.min.js: -------------------------------------------------------------------------------- 1 | !function(e,t){function n(e){return"string"==typeof e}function r(e){var t=g.call(arguments,1);return function(){return e.apply(this,t.concat(g.call(arguments)))}}function o(e){return e.replace(/^[^#]*#?(.*)$/,"$1")}function a(e){return e.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function i(r,o,a,i,c){var u,s,p,h,d;return i!==f?(p=a.match(r?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/),d=p[3]||"",2===c&&n(i)?s=i.replace(r?R:E,""):(h=l(p[2]),i=n(i)?l[r?A:w](i):i,s=2===c?i:1===c?e.extend({},i,h):e.extend({},h,i),s=b(s),r&&(s=s.replace(m,y))),u=p[1]+(r?"#":s||!p[1]?"?":"")+s+d):u=o(a!==f?a:t[S][q]),u}function c(e,t,r){return t===f||"boolean"==typeof t?(r=t,t=b[e?A:w]()):t=n(t)?t.replace(e?R:E,""):t,l(t,r)}function u(t,r,o,a){return n(o)||"object"==typeof o||(a=o,o=r,r=f),this.each(function(){var n=e(this),i=r||v()[(this.nodeName||"").toLowerCase()]||"",c=i&&n.attr(i)||"";n.attr(i,b[t](c,o,a))})}var f,s,l,p,h,d,v,m,g=Array.prototype.slice,y=decodeURIComponent,b=e.param,$=e.bbq=e.bbq||{},x=e.event.special,j="hashchange",w="querystring",A="fragment",N="elemUrlAttr",S="location",q="href",C="src",E=/^.*\?|#.*$/g,R=/^.*\#/,U={};b[w]=r(i,0,a),b[A]=s=r(i,1,o),s.noEscape=function(t){t=t||"";var n=e.map(t.split(""),encodeURIComponent);m=new RegExp(n.join("|"),"g")},s.noEscape(",/"),e.deparam=l=function(t,n){var r={},o={"true":!0,"false":!1,"null":null};return e.each(t.replace(/\+/g," ").split("&"),function(t,a){var i,c=a.split("="),u=y(c[0]),s=r,l=0,p=u.split("]["),h=p.length-1;if(/\[/.test(p[0])&&/\]$/.test(p[h])?(p[h]=p[h].replace(/\]$/,""),p=p.shift().split("[").concat(p),h=p.length-1):h=0,2===c.length)if(i=y(c[1]),n&&(i=i&&!isNaN(i)?+i:"undefined"===i?f:o[i]!==f?o[i]:i),h)for(;l<=h;l++)u=""===p[l]?s.length:p[l],s=s[u]=l').hide().insertAfter("body")[0].contentWindow,s=function(){return r(a.document[i][u])},(f=function(e,t){if(e!==t){var n=a.document;n.open().close(),n[i].hash="#"+e}})(r()))}var o,a,f,s,p={};return p.start=function(){if(!o){var a=r();f||n(),function l(){var n=r(),p=s(a);n!==a?(f(a=n,p),e(t).trigger(c)):p!==a&&(t[i][u]=t[i][u].replace(/#.*/,"")+"#"+p),o=setTimeout(l,e[c+"Delay"])}()}},p.stop=function(){a||(o&&clearTimeout(o),o=0)},p}()}(jQuery,this); -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lib/jquery.slideto.min.js: -------------------------------------------------------------------------------- 1 | !function(i){i.fn.slideto=function(o){return o=i.extend({slide_duration:"slow",highlight_duration:3e3,highlight:!0,highlight_color:"#FFFF99"},o),this.each(function(){obj=i(this),i("body").animate({scrollTop:obj.offset().top},o.slide_duration,function(){o.highlight&&i.ui.version&&obj.effect("highlight",{color:o.highlight_color},o.highlight_duration)})})}}(jQuery); -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lib/jquery.wiggle.min.js: -------------------------------------------------------------------------------- 1 | jQuery.fn.wiggle=function(e){var a={speed:50,wiggles:3,travel:5,callback:null},e=jQuery.extend(a,e);return this.each(function(){var a=this,l=(jQuery(this).wrap('
').css("position","relative"),0);for(i=1;i<=e.wiggles;i++)jQuery(this).animate({left:"-="+e.travel},e.speed).animate({left:"+="+2*e.travel},2*e.speed).animate({left:"-="+e.travel},e.speed,function(){l++,jQuery(a).parent().hasClass("wiggle-wrap")&&jQuery(a).parent().replaceWith(a),l==e.wiggles&&jQuery.isFunction(e.callback)&&e.callback()})})}; -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/lib/object-assign-pollyfill.js: -------------------------------------------------------------------------------- 1 | "function"!=typeof Object.assign&&!function(){Object.assign=function(n){"use strict";if(void 0===n||null===n)throw new TypeError("Cannot convert undefined or null to object");for(var t=Object(n),o=1;o','
Select OAuth2.0 Scopes
','
',"

Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.",'Learn how to use',"

","

"+appName+" API requires the following scopes. Select which ones you want to grant to Swagger UI.

",'
    ',"
",'

','
',"
",""].join("")),$(document.body).append(popupDialog),popup=popupDialog.find("ul.api-popup-scopes").empty(),p=0;p",popup.append(str);var r=$(window),s=r.width(),c=r.height(),l=r.scrollTop(),d=popupDialog.outerWidth(),u=popupDialog.outerHeight(),h=(c-u)/2+l,g=(s-d)/2;popupDialog.css({top:(h<0?0:h)+"px",left:(g<0?0:g)+"px"}),popupDialog.find("button.api-popup-cancel").click(function(){popupMask.hide(),popupDialog.hide(),popupDialog.empty(),popupDialog=[]}),$("button.api-popup-authbtn").unbind(),popupDialog.find("button.api-popup-authbtn").click(function(){function e(e){return e.vendorExtensions["x-tokenName"]||e.tokenName}popupMask.hide(),popupDialog.hide();var o,i=window.swaggerUi.api.authSchemes,n=window.location,a=location.pathname.substring(0,location.pathname.lastIndexOf("/")),t=n.protocol+"//"+n.host+a+"/o2c.html",p=window.oAuthRedirectUrl||t,r=null,s=[],c=popup.find("input:checked"),l=[];for(k=0;k0?void log("auth unable initialize oauth: "+i):($("pre code").each(function(e,o){hljs.highlightBlock(o)}),$(".api-ic").unbind(),void $(".api-ic").click(function(e){$(e.target).hasClass("ic-off")?handleLogin():handleLogout()}))}function clientCredentialsFlow(e,o,i){var n={client_id:clientId,client_secret:clientSecret,scope:e.join(" "),grant_type:"client_credentials"};$.ajax({url:o,type:"POST",data:n,success:function(e,o,n){onOAuthComplete(e,i)},error:function(e,o,i){onOAuthComplete("")}})}var appName,popupMask,popupDialog,clientId,realm,redirect_uri,clientSecret,scopeSeparator,additionalQueryStringParams;window.processOAuthCode=function(e){var o=e.state,i=window.location,n=location.pathname.substring(0,location.pathname.lastIndexOf("/")),a=i.protocol+"//"+i.host+n+"/o2c.html",t=window.oAuthRedirectUrl||a,p={client_id:clientId,code:e.code,grant_type:"authorization_code",redirect_uri:t};clientSecret&&(p.client_secret=clientSecret),$.ajax({url:window.swaggerUiAuth.tokenUrl,type:"POST",data:p,success:function(e,i,n){onOAuthComplete(e,o)},error:function(e,o,i){onOAuthComplete("")}})},window.onOAuthComplete=function(e,o){if(e)if(e.error){var i=$("input[type=checkbox],.secured");i.each(function(e){i[e].checked=!1}),alert(e.error)}else{var n=e[window.swaggerUiAuth.tokenName];if(o||(o=e.state),n){var a=null;$.each($(".auth .api-ic .api_information_panel"),function(e,o){var i=o;if(i&&i.childNodes){var n=[];$.each(i.childNodes,function(e,o){var i=o.innerHTML;i&&n.push(i)});for(var t=[],p=0;p0?(a=o.parentNode.parentNode,$(a.parentNode).find(".api-ic.ic-on").addClass("ic-off"),$(a.parentNode).find(".api-ic.ic-on").removeClass("ic-on"),$(a).find(".api-ic").addClass("ic-warning"),$(a).find(".api-ic").removeClass("ic-error")):(a=o.parentNode.parentNode,$(a.parentNode).find(".api-ic.ic-off").addClass("ic-on"),$(a.parentNode).find(".api-ic.ic-off").removeClass("ic-off"),$(a).find(".api-ic").addClass("ic-info"),$(a).find(".api-ic").removeClass("ic-warning"),$(a).find(".api-ic").removeClass("ic-error"))}}),"undefined"!=typeof window.swaggerUi&&(window.swaggerUi.api.clientAuthorizations.add(window.swaggerUiAuth.OAuthSchemeKey,new SwaggerClient.ApiKeyAuthorization("Authorization","Bearer "+n,"header")),window.swaggerUi.load())}}}; -------------------------------------------------------------------------------- /src/main/resources/swagger-ui/o2c.html: -------------------------------------------------------------------------------- 1 | 21 | --------------------------------------------------------------------------------