Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl-generator
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
余保谷
ydl-generator
Commits
1f4595d7
Commit
1f4595d7
authored
Apr 09, 2019
by
flying-cattle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善驼峰命名,注释,去掉过时的方法
parent
fcbd61c8
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
227 additions
and
83 deletions
+227
-83
DateType.java
src/main/java/com/github/mybatis/fl/convert/DateType.java
+15
-18
DbColumnType.java
src/main/java/com/github/mybatis/fl/convert/DbColumnType.java
+5
-7
IColumnType.java
src/main/java/com/github/mybatis/fl/convert/IColumnType.java
+5
-8
ITypeConvert.java
src/main/java/com/github/mybatis/fl/convert/ITypeConvert.java
+2
-6
MySqlTypeConvert.java
src/main/java/com/github/mybatis/fl/convert/MySqlTypeConvert.java
+11
-14
BasisInfo.java
src/main/java/com/github/mybatis/fl/entity/BasisInfo.java
+18
-0
GeneratorFileUrl.java
src/main/java/com/github/mybatis/fl/entity/GeneratorFileUrl.java
+18
-0
JsonResult.java
src/main/java/com/github/mybatis/fl/entity/JsonResult.java
+19
-0
PropertyInfo.java
src/main/java/com/github/mybatis/fl/entity/PropertyInfo.java
+18
-0
TestMain.java
src/main/java/com/github/mybatis/fl/test/TestMain.java
+6
-0
EntityInfoUtil.java
src/main/java/com/github/mybatis/fl/util/EntityInfoUtil.java
+18
-22
FreemarkerUtil.java
src/main/java/com/github/mybatis/fl/util/FreemarkerUtil.java
+19
-1
Generator.java
src/main/java/com/github/mybatis/fl/util/Generator.java
+46
-6
MySqlToJavaUtil.java
src/main/java/com/github/mybatis/fl/util/MySqlToJavaUtil.java
+27
-1
No files found.
src/main/java/com/github/mybatis/fl/convert/DateType.java
View file @
1f4595d7
/**
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
*
* @Package: com.github.mybatis.fl.convert
* @Package: com.github.mybatis.fl.convert
* @author: flying-cattle
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
* @date: 2019年4月9日 下午8:15:25
...
@@ -8,31 +7,29 @@
...
@@ -8,31 +7,29 @@
package
com
.
github
.
mybatis
.
fl
.
convert
;
package
com
.
github
.
mybatis
.
fl
.
convert
;
/**
/**
* Copyright: Copyright (c) 2019
* Copyright: Copyright (c) 2019
*
*
* @ClassName: DateType.java
* <p>说明: 数据库时间类型 到 实体类时间类型 对应策略</P>
* @Description: 数据库时间类型 到 实体类时间类型 对应策略
* @version: v2.1.0
*
* @author: flying-cattle
* @version: v1.0.0
*
* @author: flying-cattle
* Modification History:
* @date: 2019年4月9日 下午8:13:13
* Date Author Version Description
*
*---------------------------------------------------------------*
* Modification History:
* 2019年4月9日 flying-cattle v2.1.0 initialize
* Date Author Version Description
*/
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.0.1 initialize
*/
public
enum
DateType
{
public
enum
DateType
{
/**
/**
* @Description: 只使用 java.util.date 代替
*
* <p>只使用 java.util.date 代替</p>
*/
*/
ONLY_DATE
,
ONLY_DATE
,
/**
/**
*
@Description: 使用 java.sql 包下的
*
<p>使用 java.sql 包下的</p>
*/
*/
SQL_PACK
,
SQL_PACK
,
/**
/**
*
@Description: 使用 java.time 包下的
*
<p>使用 java.time 包下的</p>
* <p>java8 新的时间类型</p>
* <p>java8 新的时间类型</p>
*/
*/
TIME_PACK
TIME_PACK
...
...
src/main/java/com/github/mybatis/fl/convert/DbColumnType.java
View file @
1f4595d7
...
@@ -10,17 +10,15 @@ package com.github.mybatis.fl.convert;
...
@@ -10,17 +10,15 @@ package com.github.mybatis.fl.convert;
/**
/**
* Copyright: Copyright (c) 2019
* Copyright: Copyright (c) 2019
*
*
* @ClassName: DbColumnType.java
* <p>说明:表字段类型</p>
* @Description: 表字段类型
* @version: v2.1.0
*
* @version: v1.0.0
* @author: flying-cattle
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
* @date: 2019年4月9日 下午8:15:25
*
*
* Modification History:
* Modification History:
* Date Author Version Description
* Date Author Version Description
*---------------------------------------------------------------*
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v
1.0
.0 initialize
* 2019年4月9日 flying-cattle v
2.1
.0 initialize
*/
*/
public
enum
DbColumnType
implements
IColumnType
{
public
enum
DbColumnType
implements
IColumnType
{
// 基本类型
// 基本类型
...
@@ -66,12 +64,12 @@ public enum DbColumnType implements IColumnType {
...
@@ -66,12 +64,12 @@ public enum DbColumnType implements IColumnType {
BIG_DECIMAL
(
"BigDecimal"
,
"java.math.BigDecimal"
);
BIG_DECIMAL
(
"BigDecimal"
,
"java.math.BigDecimal"
);
/**
/**
*
类型
*
<p>类型</p>
*/
*/
private
final
String
type
;
private
final
String
type
;
/**
/**
*
包路径
*
<p>包路径</p>
*/
*/
private
final
String
pkg
;
private
final
String
pkg
;
...
...
src/main/java/com/github/mybatis/fl/convert/IColumnType.java
View file @
1f4595d7
...
@@ -12,28 +12,25 @@ package com.github.mybatis.fl.convert;
...
@@ -12,28 +12,25 @@ package com.github.mybatis.fl.convert;
/**
/**
* Copyright: Copyright (c) 2019
* Copyright: Copyright (c) 2019
*
*
* @ClassName: IColumnType.java
* <p>说明: 获取实体类字段属性类信息接口</p>
* @Description: 获取实体类字段属性类信息接口
* @version: v2.1.0
*
* @version: v1.0.0
* @author: flying-cattle
* @author: flying-cattle
* @date: 2019年4月9日 下午8:09:35
*
*
* Modification History:
* Modification History:
* Date Author Version Description
* Date Author Version Description
*---------------------------------------------------------------*
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.
0.1
initialize
* 2019年4月9日 flying-cattle v2.
1.0
initialize
*/
*/
public
interface
IColumnType
{
public
interface
IColumnType
{
/**
/**
*
@Description: 获取字段类型
*
<p>获取字段类型</p>
*
*
* @return 字段类型
* @return 字段类型
*/
*/
String
getType
();
String
getType
();
/**
/**
*
@Description: 获取字段类型完整名
*
<p> 获取字段类型完整名</p>
*
*
* @return 字段类型完整名
* @return 字段类型完整名
*/
*/
...
...
src/main/java/com/github/mybatis/fl/convert/ITypeConvert.java
View file @
1f4595d7
...
@@ -12,12 +12,9 @@ package com.github.mybatis.fl.convert;
...
@@ -12,12 +12,9 @@ package com.github.mybatis.fl.convert;
/**
/**
* Copyright: Copyright (c) 2019
* Copyright: Copyright (c) 2019
*
*
* @ClassName: ITypeConvert.java
* <p>说明: 该类的功能描述</p>
* @Description: 该类的功能描述
*
* @version: v1.0.0
* @version: v1.0.0
* @author: flying-cattle
* @author: flying-cattle
* @date: 2019年4月9日 下午8:06:16
*
*
* Modification History:
* Modification History:
* Date Author Version Description
* Date Author Version Description
...
@@ -26,8 +23,7 @@ package com.github.mybatis.fl.convert;
...
@@ -26,8 +23,7 @@ package com.github.mybatis.fl.convert;
*/
*/
public
interface
ITypeConvert
{
public
interface
ITypeConvert
{
/**
/**
* @Description: 执行类型转换
* <p>说明:执行类型转换</p>
*
* @param globalConfig 全局配置
* @param globalConfig 全局配置
* @param fieldType 字段类型
* @param fieldType 字段类型
* @return ignore
* @return ignore
...
...
src/main/java/com/github/mybatis/fl/convert/MySqlTypeConvert.java
View file @
1f4595d7
...
@@ -9,20 +9,17 @@ package com.github.mybatis.fl.convert;
...
@@ -9,20 +9,17 @@ package com.github.mybatis.fl.convert;
import
com.github.mybatis.fl.convert.ITypeConvert
;
import
com.github.mybatis.fl.convert.ITypeConvert
;
/**
/**
* Copyright: Copyright (c) 2019
* Copyright: Copyright (c) 2019
*
*
* @ClassName: MySqlTypeConvert.java
* <p>说明:MYSQL 数据库字段类型转换</p>
* @Description: MYSQL 数据库字段类型转换
* @version: v1.0.0
*
* @author: flying-cattle
* @version: v1.0.0
*
* @author: flying-cattle
* Modification History:
* @date: 2019年4月9日 下午8:13:13
* Date Author Version Description
*
*---------------------------------------------------------------*
* Modification History:
* 2019年4月9日 flying-cattle v2.0.1 initialize
* Date Author Version Description
*/
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.0.1 initialize
*/
public
class
MySqlTypeConvert
implements
ITypeConvert
{
public
class
MySqlTypeConvert
implements
ITypeConvert
{
@Override
@Override
...
...
src/main/java/com/github/mybatis/fl/entity/BasisInfo.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.entity
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
entity
;
package
com
.
github
.
mybatis
.
fl
.
entity
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
@@ -7,6 +13,18 @@ import lombok.AllArgsConstructor;
...
@@ -7,6 +13,18 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
/**
* Copyright: Copyright (c) 2019
*
* <p>说明: 自动生成需要的基本信息</P>
* @version: v2.1.0
* @author: flying-cattle
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.1.0 initialize
*/
@Data
@Data
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
...
...
src/main/java/com/github/mybatis/fl/entity/GeneratorFileUrl.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.entity
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
entity
;
package
com
.
github
.
mybatis
.
fl
.
entity
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
@@ -5,6 +11,18 @@ import lombok.AllArgsConstructor;
...
@@ -5,6 +11,18 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
/**
* Copyright: Copyright (c) 2019
*
* <p>说明: 自动生成文件路径</P>
* @version: v2.1.0
* @author: flying-cattle
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.1.0 initialize
*/
@Data
@Data
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
...
...
src/main/java/com/github/mybatis/fl/entity/JsonResult.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.entity
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
entity
;
package
com
.
github
.
mybatis
.
fl
.
entity
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
@@ -6,6 +12,19 @@ import lombok.AllArgsConstructor;
...
@@ -6,6 +12,19 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
/**
* Copyright: Copyright (c) 2019
*
* <p>说明: 返回结果json对象</P>
* @version: v2.1.0
* @author: flying-cattle
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.1.0 initialize
*/
@Data
@Data
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
...
...
src/main/java/com/github/mybatis/fl/entity/PropertyInfo.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.entity
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
entity
;
package
com
.
github
.
mybatis
.
fl
.
entity
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
@@ -6,6 +12,18 @@ import lombok.AllArgsConstructor;
...
@@ -6,6 +12,18 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
/**
* Copyright: Copyright (c) 2019
*
* <p>说明: 获取到数据库的信息</P>
* @version: v2.1.0
* @author: flying-cattle
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.1.0 initialize
*/
@Data
@Data
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
...
...
src/main/java/com/github/mybatis/fl/test/TestMain.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.convert
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
test
;
package
com
.
github
.
mybatis
.
fl
.
test
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
...
...
src/main/java/com/github/mybatis/fl/util/EntityInfoUtil.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.util
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
util
;
package
com
.
github
.
mybatis
.
fl
.
util
;
import
java.sql.Connection
;
import
java.sql.Connection
;
...
@@ -10,7 +16,18 @@ import java.util.List;
...
@@ -10,7 +16,18 @@ import java.util.List;
import
com.github.mybatis.fl.entity.BasisInfo
;
import
com.github.mybatis.fl.entity.BasisInfo
;
import
com.github.mybatis.fl.entity.PropertyInfo
;
import
com.github.mybatis.fl.entity.PropertyInfo
;
/**
* Copyright: Copyright (c) 2019
*
* <p>说明: 链接数据库并获取表信息</P>
* @version: v2.1.0
* @author: flying-cattle
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.1.0 initialize
*/
public
class
EntityInfoUtil
{
public
class
EntityInfoUtil
{
public
static
BasisInfo
getInfo
(
BasisInfo
bi
)
throws
SQLException
{
public
static
BasisInfo
getInfo
(
BasisInfo
bi
)
throws
SQLException
{
List
<
PropertyInfo
>
columns
=
new
ArrayList
<
PropertyInfo
>();
List
<
PropertyInfo
>
columns
=
new
ArrayList
<
PropertyInfo
>();
...
@@ -56,25 +73,4 @@ public class EntityInfoUtil {
...
@@ -56,25 +73,4 @@ public class EntityInfoUtil {
con
.
close
();
con
.
close
();
}
}
}
}
public
static
String
getGeneratorFileUrl
(
String
url
,
String
packageUrl
,
String
entityName
,
String
type
){
if
(
type
.
equals
(
"entity"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
".java"
;
}
else
if
(
type
.
equals
(
"dao"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Dao.java"
;
}
else
if
(
type
.
equals
(
"daoImpl"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Mapper.xml"
;
}
else
if
(
type
.
equals
(
"service"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Service.java"
;
}
else
if
(
type
.
equals
(
"serviceImpl"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"ServiceImpl.java"
;
}
else
if
(
type
.
equals
(
"controller"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Controller.java"
;
}
return
null
;
}
public
static
String
pageToUrl
(
String
url
)
{
return
url
.
replace
(
"."
,
"/"
)+
"/"
;
}
}
}
src/main/java/com/github/mybatis/fl/util/FreemarkerUtil.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.convert
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
util
;
package
com
.
github
.
mybatis
.
fl
.
util
;
import
java.io.File
;
import
java.io.File
;
...
@@ -10,6 +16,18 @@ import com.github.mybatis.fl.entity.JsonResult;
...
@@ -10,6 +16,18 @@ import com.github.mybatis.fl.entity.JsonResult;
import
freemarker.template.Configuration
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
freemarker.template.Template
;
/**
* Copyright: Copyright (c) 2019
*
* <p>说明: 创建文件</P>
* @version: v2.1.0
* @author: flying-cattle
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.1.0 initialize
*/
public
class
FreemarkerUtil
{
public
class
FreemarkerUtil
{
public
static
JsonResult
createFile
(
BasisInfo
dataModel
,
String
templateName
,
String
filePath
)
{
public
static
JsonResult
createFile
(
BasisInfo
dataModel
,
String
templateName
,
String
filePath
)
{
...
@@ -18,7 +36,7 @@ public class FreemarkerUtil {
...
@@ -18,7 +36,7 @@ public class FreemarkerUtil {
String
fileName
=
dataModel
.
getEntityName
()+
messageStr
(
templateName
);
String
fileName
=
dataModel
.
getEntityName
()+
messageStr
(
templateName
);
try
{
try
{
// 通过FreeMarker的Confuguration读取相应的模板文件
// 通过FreeMarker的Confuguration读取相应的模板文件
Configuration
configuration
=
new
Configuration
();
Configuration
configuration
=
new
Configuration
(
Configuration
.
VERSION_2_3_28
);
// 设置模板路径
// 设置模板路径
configuration
.
setClassForTemplateLoading
(
FreemarkerUtil
.
class
,
"/freemarker/ftl"
);
configuration
.
setClassForTemplateLoading
(
FreemarkerUtil
.
class
,
"/freemarker/ftl"
);
// 设置默认字体
// 设置默认字体
...
...
src/main/java/com/github/mybatis/fl/util/Generator.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.convert
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
util
;
package
com
.
github
.
mybatis
.
fl
.
util
;
import
java.util.List
;
import
java.util.List
;
...
@@ -6,6 +12,18 @@ import com.github.mybatis.fl.entity.BasisInfo;
...
@@ -6,6 +12,18 @@ import com.github.mybatis.fl.entity.BasisInfo;
import
com.github.mybatis.fl.entity.JsonResult
;
import
com.github.mybatis.fl.entity.JsonResult
;
import
com.github.mybatis.fl.entity.PropertyInfo
;
import
com.github.mybatis.fl.entity.PropertyInfo
;
/**
* Copyright: Copyright (c) 2019
*
* <p>说明: 获取文件路径调用创建文件</P>
* @version: v2.1.0
* @author: flying-cattle
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.1.0 initialize
*/
public
class
Generator
{
public
class
Generator
{
//路径信息
//路径信息
public
static
final
String
ENTITY
=
"entity"
;
public
static
final
String
ENTITY
=
"entity"
;
...
@@ -18,19 +36,19 @@ public class Generator {
...
@@ -18,19 +36,19 @@ public class Generator {
//①创建实体类
//①创建实体类
public
static
JsonResult
createEntity
(
String
url
,
BasisInfo
bi
)
{
public
static
JsonResult
createEntity
(
String
url
,
BasisInfo
bi
)
{
String
fileUrl
=
EntityInfoUtil
.
getGeneratorFileUrl
(
url
,
bi
.
getEntityUrl
(),
bi
.
getEntityName
(),
ENTITY
);
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getEntityUrl
(),
bi
.
getEntityName
(),
ENTITY
);
return
FreemarkerUtil
.
createFile
(
bi
,
"entity.ftl"
,
fileUrl
);
return
FreemarkerUtil
.
createFile
(
bi
,
"entity.ftl"
,
fileUrl
);
}
}
//②创建DAO
//②创建DAO
public
static
JsonResult
createDao
(
String
url
,
BasisInfo
bi
)
{
public
static
JsonResult
createDao
(
String
url
,
BasisInfo
bi
)
{
String
fileUrl
=
EntityInfoUtil
.
getGeneratorFileUrl
(
url
,
bi
.
getDaoUrl
(),
bi
.
getEntityName
(),
DAO
);
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getDaoUrl
(),
bi
.
getEntityName
(),
DAO
);
return
FreemarkerUtil
.
createFile
(
bi
,
"dao.ftl"
,
fileUrl
);
return
FreemarkerUtil
.
createFile
(
bi
,
"dao.ftl"
,
fileUrl
);
}
}
//③创建mapper配置文件
//③创建mapper配置文件
public
static
JsonResult
createDaoImpl
(
String
url
,
BasisInfo
bi
)
{
public
static
JsonResult
createDaoImpl
(
String
url
,
BasisInfo
bi
)
{
String
fileUrl
=
EntityInfoUtil
.
getGeneratorFileUrl
(
url
,
bi
.
getMapperUrl
(),
bi
.
getEntityName
(),
DAO_IMPL
);
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getMapperUrl
(),
bi
.
getEntityName
(),
DAO_IMPL
);
List
<
PropertyInfo
>
list
=
bi
.
getCis
();
List
<
PropertyInfo
>
list
=
bi
.
getCis
();
String
agile
=
""
;
String
agile
=
""
;
for
(
PropertyInfo
propertyInfo
:
list
)
{
for
(
PropertyInfo
propertyInfo
:
list
)
{
...
@@ -43,19 +61,41 @@ public class Generator {
...
@@ -43,19 +61,41 @@ public class Generator {
//④创建SERVICE
//④创建SERVICE
public
static
JsonResult
createService
(
String
url
,
BasisInfo
bi
)
{
public
static
JsonResult
createService
(
String
url
,
BasisInfo
bi
)
{
String
fileUrl
=
EntityInfoUtil
.
getGeneratorFileUrl
(
url
,
bi
.
getServiceUrl
(),
bi
.
getEntityName
(),
SERVICE
);
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getServiceUrl
(),
bi
.
getEntityName
(),
SERVICE
);
return
FreemarkerUtil
.
createFile
(
bi
,
"service.ftl"
,
fileUrl
);
return
FreemarkerUtil
.
createFile
(
bi
,
"service.ftl"
,
fileUrl
);
}
}
//⑤创建SERVICE_IMPL
//⑤创建SERVICE_IMPL
public
static
JsonResult
createServiceImpl
(
String
url
,
BasisInfo
bi
)
{
public
static
JsonResult
createServiceImpl
(
String
url
,
BasisInfo
bi
)
{
String
fileUrl
=
EntityInfoUtil
.
getGeneratorFileUrl
(
url
,
bi
.
getServiceImplUrl
(),
bi
.
getEntityName
(),
SERVICE_IMPL
);
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getServiceImplUrl
(),
bi
.
getEntityName
(),
SERVICE_IMPL
);
return
FreemarkerUtil
.
createFile
(
bi
,
"serviceImpl.ftl"
,
fileUrl
);
return
FreemarkerUtil
.
createFile
(
bi
,
"serviceImpl.ftl"
,
fileUrl
);
}
}
//⑥创建CONTROLLER
//⑥创建CONTROLLER
public
static
JsonResult
createController
(
String
url
,
BasisInfo
bi
)
{
public
static
JsonResult
createController
(
String
url
,
BasisInfo
bi
)
{
String
fileUrl
=
EntityInfoUtil
.
getGeneratorFileUrl
(
url
,
bi
.
getControllerUrl
(),
bi
.
getEntityName
(),
CONTROLLER
);
String
fileUrl
=
getGeneratorFileUrl
(
url
,
bi
.
getControllerUrl
(),
bi
.
getEntityName
(),
CONTROLLER
);
return
FreemarkerUtil
.
createFile
(
bi
,
"controller.ftl"
,
fileUrl
);
return
FreemarkerUtil
.
createFile
(
bi
,
"controller.ftl"
,
fileUrl
);
}
}
//生成文件
public
static
String
getGeneratorFileUrl
(
String
url
,
String
packageUrl
,
String
entityName
,
String
type
){
if
(
type
.
equals
(
"entity"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
".java"
;
}
else
if
(
type
.
equals
(
"dao"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Dao.java"
;
}
else
if
(
type
.
equals
(
"daoImpl"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Mapper.xml"
;
}
else
if
(
type
.
equals
(
"service"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Service.java"
;
}
else
if
(
type
.
equals
(
"serviceImpl"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"ServiceImpl.java"
;
}
else
if
(
type
.
equals
(
"controller"
))
{
return
url
+
pageToUrl
(
packageUrl
)+
entityName
+
"Controller.java"
;
}
return
null
;
}
public
static
String
pageToUrl
(
String
url
)
{
return
url
.
replace
(
"."
,
"/"
)+
"/"
;
}
}
}
src/main/java/com/github/mybatis/fl/util/MySqlToJavaUtil.java
View file @
1f4595d7
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* @Package: com.github.mybatis.fl.util
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*/
package
com
.
github
.
mybatis
.
fl
.
util
;
package
com
.
github
.
mybatis
.
fl
.
util
;
import
com.github.mybatis.fl.convert.DateType
;
import
com.github.mybatis.fl.convert.DateType
;
import
com.github.mybatis.fl.convert.MySqlTypeConvert
;
import
com.github.mybatis.fl.convert.MySqlTypeConvert
;
/**
* Copyright: Copyright (c) 2019
*
* <p>说明: 获奖java中需要的驼峰命名</P>
* @version: v2.1.0
* @author: flying-cattle
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.1.0 initialize
*/
public
class
MySqlToJavaUtil
{
public
class
MySqlToJavaUtil
{
/**
* <p>获取java类名</p>
*/
public
static
String
getClassName
(
String
table
)
{
public
static
String
getClassName
(
String
table
)
{
table
=
changeToJavaFiled
(
table
);
table
=
changeToJavaFiled
(
table
);
StringBuilder
sbuilder
=
new
StringBuilder
();
StringBuilder
sbuilder
=
new
StringBuilder
();
...
@@ -14,6 +34,9 @@ public class MySqlToJavaUtil {
...
@@ -14,6 +34,9 @@ public class MySqlToJavaUtil {
return
sbuilder
.
toString
();
return
sbuilder
.
toString
();
}
}
/**
* <p>获取字段名,把"_"后面字母变大写</p>
*/
public
static
String
changeToJavaFiled
(
String
field
)
{
public
static
String
changeToJavaFiled
(
String
field
)
{
String
[]
fields
=
field
.
split
(
"_"
);
String
[]
fields
=
field
.
split
(
"_"
);
StringBuilder
sbuilder
=
new
StringBuilder
(
fields
[
0
]);
StringBuilder
sbuilder
=
new
StringBuilder
(
fields
[
0
]);
...
@@ -25,6 +48,9 @@ public class MySqlToJavaUtil {
...
@@ -25,6 +48,9 @@ public class MySqlToJavaUtil {
return
sbuilder
.
toString
();
return
sbuilder
.
toString
();
}
}
/**
* <p>把sql的数据类型转为java需要的类型</p>
*/
public
static
String
jdbcTypeToJavaType
(
String
sqlType
)
{
public
static
String
jdbcTypeToJavaType
(
String
sqlType
)
{
MySqlTypeConvert
typeConvert
=
new
MySqlTypeConvert
();
MySqlTypeConvert
typeConvert
=
new
MySqlTypeConvert
();
return
typeConvert
.
processTypeConvert
(
DateType
.
ONLY_DATE
,
sqlType
).
getType
();
return
typeConvert
.
processTypeConvert
(
DateType
.
ONLY_DATE
,
sqlType
).
getType
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment