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
36459a40
Commit
36459a40
authored
Apr 09, 2019
by
flying-cattle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善mysql数据类型转换工具
parent
9b83c3c2
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
322 additions
and
46 deletions
+322
-46
DateType.java
src/main/java/com/github/mybatis/fl/convert/DateType.java
+40
-0
DbColumnType.java
src/main/java/com/github/mybatis/fl/convert/DbColumnType.java
+92
-0
IColumnType.java
src/main/java/com/github/mybatis/fl/convert/IColumnType.java
+41
-0
ITypeConvert.java
src/main/java/com/github/mybatis/fl/convert/ITypeConvert.java
+36
-0
MySqlTypeConvert.java
src/main/java/com/github/mybatis/fl/convert/MySqlTypeConvert.java
+87
-0
BasisInfo.java
src/main/java/com/github/mybatis/fl/entity/BasisInfo.java
+1
-1
GeneratorFileUrl.java
src/main/java/com/github/mybatis/fl/entity/GeneratorFileUrl.java
+1
-1
JsonResult.java
src/main/java/com/github/mybatis/fl/entity/JsonResult.java
+1
-3
PropertyInfo.java
src/main/java/com/github/mybatis/fl/entity/PropertyInfo.java
+1
-1
TestMain.java
src/main/java/com/github/mybatis/fl/test/TestMain.java
+5
-5
EntityInfoUtil.java
src/main/java/com/github/mybatis/fl/util/EntityInfoUtil.java
+3
-3
FreemarkerUtil.java
src/main/java/com/github/mybatis/fl/util/FreemarkerUtil.java
+4
-3
Generator.java
src/main/java/com/github/mybatis/fl/util/Generator.java
+4
-4
MySqlToJavaUtil.java
src/main/java/com/github/mybatis/fl/util/MySqlToJavaUtil.java
+6
-23
entity.ftl
src/main/resources/freemarker/ftl/entity.ftl
+0
-2
No files found.
src/main/java/com/github/mybatis/fl/convert/DateType.java
0 → 100644
View file @
36459a40
/**
* 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
.
convert
;
/**
* Copyright: Copyright (c) 2019
*
* @ClassName: DateType.java
* @Description: 数据库时间类型 到 实体类时间类型 对应策略
*
* @version: v1.0.0
* @author: flying-cattle
* @date: 2019年4月9日 下午8:13:13
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.0.1 initialize
*/
public
enum
DateType
{
/**
* @Description: 只使用 java.util.date 代替
*/
ONLY_DATE
,
/**
* @Description: 使用 java.sql 包下的
*/
SQL_PACK
,
/**
* @Description: 使用 java.time 包下的
* <p>java8 新的时间类型</p>
*/
TIME_PACK
}
src/main/java/com/github/mybatis/fl/convert/DbColumnType.java
0 → 100644
View file @
36459a40
/**
* 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
.
convert
;
/**
* Copyright: Copyright (c) 2019
*
* @ClassName: DbColumnType.java
* @Description: 表字段类型
*
* @version: v1.0.0
* @author: flying-cattle
* @date: 2019年4月9日 下午8:15:25
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v1.0.0 initialize
*/
public
enum
DbColumnType
implements
IColumnType
{
// 基本类型
BASE_BYTE
(
"byte"
,
null
),
BASE_SHORT
(
"short"
,
null
),
BASE_CHAR
(
"char"
,
null
),
BASE_INT
(
"int"
,
null
),
BASE_LONG
(
"long"
,
null
),
BASE_FLOAT
(
"float"
,
null
),
BASE_DOUBLE
(
"double"
,
null
),
BASE_BOOLEAN
(
"boolean"
,
null
),
// 包装类型
BYTE
(
"Byte"
,
null
),
SHORT
(
"Short"
,
null
),
CHARACTER
(
"Character"
,
null
),
INTEGER
(
"Integer"
,
null
),
LONG
(
"Long"
,
null
),
FLOAT
(
"Float"
,
null
),
DOUBLE
(
"Double"
,
null
),
BOOLEAN
(
"Boolean"
,
null
),
STRING
(
"String"
,
null
),
// sql 包下数据类型
DATE_SQL
(
"Date"
,
"java.sql.Date"
),
TIME
(
"Time"
,
"java.sql.Time"
),
TIMESTAMP
(
"Timestamp"
,
"java.sql.Timestamp"
),
BLOB
(
"Blob"
,
"java.sql.Blob"
),
CLOB
(
"Clob"
,
"java.sql.Clob"
),
// java8 新时间类型
LOCAL_DATE
(
"LocalDate"
,
"java.time.LocalDate"
),
LOCAL_TIME
(
"LocalTime"
,
"java.time.LocalTime"
),
YEAR
(
"Year"
,
"java.time.Year"
),
YEAR_MONTH
(
"YearMonth"
,
"java.time.YearMonth"
),
LOCAL_DATE_TIME
(
"LocalDateTime"
,
"java.time.LocalDateTime"
),
// 其他杂类
BYTE_ARRAY
(
"byte[]"
,
null
),
OBJECT
(
"Object"
,
null
),
DATE
(
"Date"
,
"java.util.Date"
),
BIG_INTEGER
(
"BigInteger"
,
"java.math.BigInteger"
),
BIG_DECIMAL
(
"BigDecimal"
,
"java.math.BigDecimal"
);
/**
* 类型
*/
private
final
String
type
;
/**
* 包路径
*/
private
final
String
pkg
;
DbColumnType
(
final
String
type
,
final
String
pkg
)
{
this
.
type
=
type
;
this
.
pkg
=
pkg
;
}
@Override
public
String
getType
()
{
return
type
;
}
@Override
public
String
getPkg
()
{
return
pkg
;
}
}
src/main/java/com/github/mybatis/fl/convert/IColumnType.java
0 → 100644
View file @
36459a40
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* @Package: com.github.mybatis.fl.convert
* @author: flying-cattle
* @date: 2019年4月9日 下午8:09:35
*/
package
com
.
github
.
mybatis
.
fl
.
convert
;
/**
* Copyright: Copyright (c) 2019
*
* @ClassName: IColumnType.java
* @Description: 获取实体类字段属性类信息接口
*
* @version: v1.0.0
* @author: flying-cattle
* @date: 2019年4月9日 下午8:09:35
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.0.1 initialize
*/
public
interface
IColumnType
{
/**
* @Description: 获取字段类型
*
* @return 字段类型
*/
String
getType
();
/**
* @Description: 获取字段类型完整名
*
* @return 字段类型完整名
*/
String
getPkg
();
}
src/main/java/com/github/mybatis/fl/convert/ITypeConvert.java
0 → 100644
View file @
36459a40
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* @Package: com.github.mybatis.fl.convert
* @author: flying-cattle
* @date: 2019年4月9日 下午8:06:16
*/
package
com
.
github
.
mybatis
.
fl
.
convert
;
/**
* Copyright: Copyright (c) 2019
*
* @ClassName: ITypeConvert.java
* @Description: 该类的功能描述
*
* @version: v1.0.0
* @author: flying-cattle
* @date: 2019年4月9日 下午8:06:16
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.0.1 initialize
*/
public
interface
ITypeConvert
{
/**
* @Description: 执行类型转换
*
* @param globalConfig 全局配置
* @param fieldType 字段类型
* @return ignore
*/
IColumnType
processTypeConvert
(
DateType
dateType
,
String
fieldType
);
}
src/main/java/com/github/mybatis/fl/convert/MySqlTypeConvert.java
0 → 100644
View file @
36459a40
/**
* Copyright © 2019 dream horse Info. Tech Ltd. All rights reserved.
*
* @Package: com.github.mybatis.fl.convert
* @author: flying-cattle
* @date: 2019年4月9日 下午8:13:13
*/
package
com
.
github
.
mybatis
.
fl
.
convert
;
import
com.github.mybatis.fl.convert.ITypeConvert
;
/**
* Copyright: Copyright (c) 2019
*
* @ClassName: MySqlTypeConvert.java
* @Description: MYSQL 数据库字段类型转换
*
* @version: v1.0.0
* @author: flying-cattle
* @date: 2019年4月9日 下午8:13:13
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------------*
* 2019年4月9日 flying-cattle v2.0.1 initialize
*/
public
class
MySqlTypeConvert
implements
ITypeConvert
{
@Override
public
IColumnType
processTypeConvert
(
DateType
dateType
,
String
fieldType
)
{
String
t
=
fieldType
.
toLowerCase
();
if
(
t
.
contains
(
"char"
))
{
return
DbColumnType
.
STRING
;
}
else
if
(
t
.
contains
(
"bigint"
))
{
return
DbColumnType
.
LONG
;
}
else
if
(
t
.
contains
(
"tinyint(1)"
))
{
return
DbColumnType
.
BOOLEAN
;
}
else
if
(
t
.
contains
(
"int"
))
{
return
DbColumnType
.
INTEGER
;
}
else
if
(
t
.
contains
(
"text"
))
{
return
DbColumnType
.
STRING
;
}
else
if
(
t
.
contains
(
"bit"
))
{
return
DbColumnType
.
BOOLEAN
;
}
else
if
(
t
.
contains
(
"decimal"
))
{
return
DbColumnType
.
BIG_DECIMAL
;
}
else
if
(
t
.
contains
(
"clob"
))
{
return
DbColumnType
.
CLOB
;
}
else
if
(
t
.
contains
(
"blob"
))
{
return
DbColumnType
.
BLOB
;
}
else
if
(
t
.
contains
(
"binary"
))
{
return
DbColumnType
.
BYTE_ARRAY
;
}
else
if
(
t
.
contains
(
"float"
))
{
return
DbColumnType
.
FLOAT
;
}
else
if
(
t
.
contains
(
"double"
))
{
return
DbColumnType
.
DOUBLE
;
}
else
if
(
t
.
contains
(
"json"
)
||
t
.
contains
(
"enum"
))
{
return
DbColumnType
.
STRING
;
}
else
if
(
t
.
contains
(
"date"
)
||
t
.
contains
(
"time"
)
||
t
.
contains
(
"year"
))
{
switch
(
dateType
)
{
case
ONLY_DATE:
return
DbColumnType
.
DATE
;
case
SQL_PACK:
switch
(
t
)
{
case
"date"
:
return
DbColumnType
.
DATE_SQL
;
case
"time"
:
return
DbColumnType
.
TIME
;
case
"year"
:
return
DbColumnType
.
DATE_SQL
;
default
:
return
DbColumnType
.
TIMESTAMP
;
}
case
TIME_PACK:
switch
(
t
)
{
case
"date"
:
return
DbColumnType
.
LOCAL_DATE
;
case
"time"
:
return
DbColumnType
.
LOCAL_TIME
;
case
"year"
:
return
DbColumnType
.
YEAR
;
default
:
return
DbColumnType
.
LOCAL_DATE_TIME
;
}
}
}
return
DbColumnType
.
STRING
;
}
}
src/main/java/com/github/mybatis/entity/BasisInfo.java
→
src/main/java/com/github/mybatis/
fl/
entity/BasisInfo.java
View file @
36459a40
package
com
.
github
.
mybatis
.
entity
;
package
com
.
github
.
mybatis
.
fl
.
entity
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
...
...
src/main/java/com/github/mybatis/entity/GeneratorFileUrl.java
→
src/main/java/com/github/mybatis/
fl/
entity/GeneratorFileUrl.java
View file @
36459a40
package
com
.
github
.
mybatis
.
entity
;
package
com
.
github
.
mybatis
.
fl
.
entity
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
...
...
src/main/java/com/github/mybatis/entity/JsonResult.java
→
src/main/java/com/github/mybatis/
fl/
entity/JsonResult.java
View file @
36459a40
package
com
.
github
.
mybatis
.
entity
;
package
com
.
github
.
mybatis
.
fl
.
entity
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
lombok.ToString
;
@Data
@Data
@ToString
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
public
class
JsonResult
implements
Serializable
{
public
class
JsonResult
implements
Serializable
{
...
...
src/main/java/com/github/mybatis/entity/PropertyInfo.java
→
src/main/java/com/github/mybatis/
fl/
entity/PropertyInfo.java
View file @
36459a40
package
com
.
github
.
mybatis
.
entity
;
package
com
.
github
.
mybatis
.
fl
.
entity
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
...
src/main/java/com/github/mybatis/test/TestMain.java
→
src/main/java/com/github/mybatis/
fl/
test/TestMain.java
View file @
36459a40
package
com
.
github
.
mybatis
.
test
;
package
com
.
github
.
mybatis
.
fl
.
test
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.Date
;
import
java.util.Date
;
import
com.github.mybatis.entity.BasisInfo
;
import
com.github.mybatis.
fl.
entity.BasisInfo
;
import
com.github.mybatis.util.EntityInfoUtil
;
import
com.github.mybatis.
fl.
util.EntityInfoUtil
;
import
com.github.mybatis.util.Generator
;
import
com.github.mybatis.
fl.
util.Generator
;
import
com.github.mybatis.util.MySqlToJavaUtil
;
import
com.github.mybatis.
fl.
util.MySqlToJavaUtil
;
public
class
TestMain
{
public
class
TestMain
{
//基础信息
//基础信息
...
...
src/main/java/com/github/mybatis/util/EntityInfoUtil.java
→
src/main/java/com/github/mybatis/
fl/
util/EntityInfoUtil.java
View file @
36459a40
package
com
.
github
.
mybatis
.
util
;
package
com
.
github
.
mybatis
.
fl
.
util
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
...
@@ -8,8 +8,8 @@ import java.sql.SQLException;
...
@@ -8,8 +8,8 @@ import java.sql.SQLException;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
com.github.mybatis.entity.BasisInfo
;
import
com.github.mybatis.
fl.
entity.BasisInfo
;
import
com.github.mybatis.entity.PropertyInfo
;
import
com.github.mybatis.
fl.
entity.PropertyInfo
;
public
class
EntityInfoUtil
{
public
class
EntityInfoUtil
{
public
static
BasisInfo
getInfo
(
BasisInfo
bi
)
throws
SQLException
{
public
static
BasisInfo
getInfo
(
BasisInfo
bi
)
throws
SQLException
{
...
...
src/main/java/com/github/mybatis/util/FreemarkerUtil.java
→
src/main/java/com/github/mybatis/
fl/
util/FreemarkerUtil.java
View file @
36459a40
package
com
.
github
.
mybatis
.
util
;
package
com
.
github
.
mybatis
.
fl
.
util
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.IOException
;
import
com.github.mybatis.entity.BasisInfo
;
import
com.github.mybatis.entity.JsonResult
;
import
com.github.mybatis.fl.entity.BasisInfo
;
import
com.github.mybatis.fl.entity.JsonResult
;
import
freemarker.template.Configuration
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
freemarker.template.Template
;
...
...
src/main/java/com/github/mybatis/util/Generator.java
→
src/main/java/com/github/mybatis/
fl/
util/Generator.java
View file @
36459a40
package
com
.
github
.
mybatis
.
util
;
package
com
.
github
.
mybatis
.
fl
.
util
;
import
java.util.List
;
import
java.util.List
;
import
com.github.mybatis.entity.BasisInfo
;
import
com.github.mybatis.
fl.
entity.BasisInfo
;
import
com.github.mybatis.entity.JsonResult
;
import
com.github.mybatis.
fl.
entity.JsonResult
;
import
com.github.mybatis.entity.PropertyInfo
;
import
com.github.mybatis.
fl.
entity.PropertyInfo
;
public
class
Generator
{
public
class
Generator
{
//路径信息
//路径信息
...
...
src/main/java/com/github/mybatis/util/MySqlToJavaUtil.java
→
src/main/java/com/github/mybatis/
fl/
util/MySqlToJavaUtil.java
View file @
36459a40
package
com
.
github
.
mybatis
.
util
;
package
com
.
github
.
mybatis
.
fl
.
util
;
import
com.github.mybatis.fl.convert.DateType
;
import
com.github.mybatis.fl.convert.MySqlTypeConvert
;
public
class
MySqlToJavaUtil
{
public
class
MySqlToJavaUtil
{
...
@@ -23,27 +26,7 @@ public class MySqlToJavaUtil {
...
@@ -23,27 +26,7 @@ public class MySqlToJavaUtil {
}
}
public
static
String
jdbcTypeToJavaType
(
String
sqlType
)
{
public
static
String
jdbcTypeToJavaType
(
String
sqlType
)
{
if
(
sqlType
.
equalsIgnoreCase
(
"bit"
))
{
MySqlTypeConvert
typeConvert
=
new
MySqlTypeConvert
();
return
"Boolean"
;
return
typeConvert
.
processTypeConvert
(
DateType
.
ONLY_DATE
,
sqlType
).
getType
();
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"tinyint"
))
{
return
"Integer"
;
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"smallint"
))
{
return
"Integer"
;
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"int"
))
{
return
"Integer"
;
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"bigint"
))
{
return
"Long"
;
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"float"
))
{
return
"Float"
;
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"decimal"
)
||
sqlType
.
equalsIgnoreCase
(
"numeric"
)
||
sqlType
.
equalsIgnoreCase
(
"real"
)
||
sqlType
.
equalsIgnoreCase
(
"money"
)
||
sqlType
.
equalsIgnoreCase
(
"smallmoney"
))
{
return
"Double"
;
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"varchar"
)
||
sqlType
.
equalsIgnoreCase
(
"char"
)
||
sqlType
.
equalsIgnoreCase
(
"nvarchar"
)
||
sqlType
.
equalsIgnoreCase
(
"nchar"
)
||
sqlType
.
equalsIgnoreCase
(
"text"
))
{
return
"String"
;
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"datetime"
)
||
sqlType
.
equalsIgnoreCase
(
"date"
)
||
sqlType
.
equalsIgnoreCase
(
"timestamp"
))
{
return
"Date"
;
}
else
if
(
sqlType
.
equalsIgnoreCase
(
"image"
))
{
return
"Blod"
;
}
return
null
;
}
}
}
}
src/main/resources/freemarker/ftl/entity.ftl
View file @
36459a40
...
@@ -13,7 +13,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
...
@@ -13,7 +13,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import
io
.
swagger
.
annotations
.
ApiModelProperty
;
import
io
.
swagger
.
annotations
.
ApiModelProperty
;
import
lombok
.
Data
;
import
lombok
.
Data
;
import
lombok
.
ToString
;
import
lombok
.
NoArgsConstructor
;
import
lombok
.
NoArgsConstructor
;
import
lombok
.
AllArgsConstructor
;
import
lombok
.
AllArgsConstructor
;
...
@@ -26,7 +25,6 @@ import lombok.AllArgsConstructor;
...
@@ -26,7 +25,6 @@ import lombok.AllArgsConstructor;
*
*
*/
*/
@
Data
@
Data
@
ToString
@
AllArgsConstructor
@
AllArgsConstructor
@
NoArgsConstructor
@
NoArgsConstructor
public
class
${
entityName
}
implements
Serializable
{
public
class
${
entityName
}
implements
Serializable
{
...
...
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