Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mysql-generator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
孙长纪
mysql-generator
Commits
6eec11b4
Commit
6eec11b4
authored
Nov 02, 2022
by
刘凯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加remote remoteImpl等生成文件
parent
5790bc8c
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
691 additions
and
24 deletions
+691
-24
fileHashes.bin
.gradle/4.6/fileHashes/fileHashes.bin
+0
-0
fileHashes.lock
.gradle/4.6/fileHashes/fileHashes.lock
+0
-0
gradle.xml
.idea/gradle.xml
+2
-2
misc.xml
.idea/misc.xml
+4
-1
build.gradle
build.gradle
+4
-0
MybatisGenerator.java
...n/java/cn/com/duiba/mysql/generator/MybatisGenerator.java
+30
-0
GeneratorConfig.java
.../cn/com/duiba/mysql/generator/entity/GeneratorConfig.java
+135
-4
AbstractGenerator.java
.../com/duiba/mysql/generator/gencode/AbstractGenerator.java
+7
-0
JavaDtoGenerator.java
...n/com/duiba/mysql/generator/gencode/JavaDtoGenerator.java
+32
-0
JavaRemoteServiceInterfaceGenerator.java
...enerator/gencode/JavaRemoteServiceInterfaceGenerator.java
+28
-0
JavaRemoteServiceInterfaceImplGenerator.java
...ator/gencode/JavaRemoteServiceInterfaceImplGenerator.java
+28
-0
JavaServiceInterfaceGenerator.java
...ysql/generator/gencode/JavaServiceInterfaceGenerator.java
+28
-0
JavaServiceInterfaceImplGenerator.java
.../generator/gencode/JavaServiceInterfaceImplGenerator.java
+28
-0
JavaVoGenerator.java
...cn/com/duiba/mysql/generator/gencode/JavaVoGenerator.java
+32
-0
java_dao.ftl
src/main/resources/tpls/java_dao.ftl
+4
-4
java_dao_impl.ftl
src/main/resources/tpls/java_dao_impl.ftl
+24
-8
java_dto.ftl
src/main/resources/tpls/java_dto.ftl
+49
-0
java_remote_service.ftl
src/main/resources/tpls/java_remote_service.ftl
+31
-0
java_remote_service.impl.ftl
src/main/resources/tpls/java_remote_service.impl.ftl
+65
-0
java_service.ftl
src/main/resources/tpls/java_service.ftl
+29
-0
java_service.impl.ftl
src/main/resources/tpls/java_service.impl.ftl
+70
-0
java_vo.ftl
src/main/resources/tpls/java_vo.ftl
+48
-0
CodeGeneratorTest.java
.../java/cn/com/duiba/mysql/generator/CodeGeneratorTest.java
+13
-5
No files found.
.gradle/4.6/fileHashes/fileHashes.bin
deleted
100644 → 0
View file @
5790bc8c
File deleted
.gradle/4.6/fileHashes/fileHashes.lock
deleted
100644 → 0
View file @
5790bc8c
File deleted
.idea/gradle.xml
View file @
6eec11b4
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"GradleMigrationSettings"
migrationVersion=
"1"
/>
<component
name=
"GradleSettings"
>
<option
name=
"linkedExternalProjectsSettings"
>
<GradleProjectSettings>
<option
name=
"distributionType"
value=
"LOCAL"
/>
<option
name=
"externalProjectPath"
value=
"$PROJECT_DIR$"
/>
<option
name=
"gradleHome"
value=
"$
PROJECT_DIR$/../..
/software/gradle-4.6"
/>
<option
name=
"gradleHome"
value=
"$
USER_HOME$
/software/gradle-4.6"
/>
<option
name=
"gradleJvm"
value=
"1.8"
/>
<option
name=
"modules"
>
<set>
<option
value=
"$PROJECT_DIR$"
/>
</set>
</option>
<option
name=
"useAutoImport"
value=
"true"
/>
</GradleProjectSettings>
</option>
</component>
...
...
.idea/misc.xml
View file @
6eec11b4
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"FrameworkDetectionExcludesConfiguration"
>
<file
type=
"web"
url=
"file://$PROJECT_DIR$"
/>
</component>
<component
name=
"ProjectInspectionProfilesVisibleTreeState"
>
<entry
key=
"Project Default"
>
<profile-state>
...
...
@@ -353,7 +356,7 @@
</profile-state>
</entry>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_8"
default=
"true"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/out"
/>
</component>
<component
name=
"masterDetails"
>
...
...
build.gradle
View file @
6eec11b4
...
...
@@ -36,11 +36,15 @@ repositories {
}
dependencies
{
compile
(
"mysql:mysql-connector-java:5.1.46"
)
compile
(
"commons-io:commons-io:2.4"
)
compile
(
"commons-lang:commons-lang:2.6"
)
compile
(
"org.freemarker:freemarker:2.3.19"
)
compile
(
"commons-dbutils:commons-dbutils:1.7"
)
compile
"org.projectlombok:lombok:1.18.4"
}
uploadArchives
{
...
...
src/main/java/cn/com/duiba/mysql/generator/MybatisGenerator.java
View file @
6eec11b4
...
...
@@ -5,10 +5,17 @@ import cn.com.duiba.mysql.generator.entity.TableEntity;
import
cn.com.duiba.mysql.generator.exceptions.DuibaGeneratorException
;
import
cn.com.duiba.mysql.generator.gencode.JavaDaoGenerator
;
import
cn.com.duiba.mysql.generator.gencode.JavaDaoImplGenerator
;
import
cn.com.duiba.mysql.generator.gencode.JavaDtoGenerator
;
import
cn.com.duiba.mysql.generator.gencode.JavaEntityGenerator
;
import
cn.com.duiba.mysql.generator.gencode.JavaRemoteServiceInterfaceGenerator
;
import
cn.com.duiba.mysql.generator.gencode.JavaRemoteServiceInterfaceImplGenerator
;
import
cn.com.duiba.mysql.generator.gencode.JavaServiceInterfaceGenerator
;
import
cn.com.duiba.mysql.generator.gencode.JavaServiceInterfaceImplGenerator
;
import
cn.com.duiba.mysql.generator.gencode.JavaVoGenerator
;
import
cn.com.duiba.mysql.generator.gencode.SQLXmlGenerator
;
import
cn.com.duiba.mysql.generator.service.DuibaFreemarkerService
;
import
cn.com.duiba.mysql.generator.utils.DBUtils
;
import
org.apache.commons.lang.StringUtils
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
...
...
@@ -35,6 +42,9 @@ public class MybatisGenerator {
}
catch
(
SQLException
e
)
{
throw
new
DuibaGeneratorException
(
e
);
}
//生成dto文件
JavaDtoGenerator
dtoGenerator
=
new
JavaDtoGenerator
(
freemarkerService
,
tableEntity
,
config
);
dtoGenerator
.
gen
();
//生成entity文件
JavaEntityGenerator
doGenerator
=
new
JavaEntityGenerator
(
freemarkerService
,
tableEntity
,
config
);
doGenerator
.
gen
();
...
...
@@ -44,6 +54,26 @@ public class MybatisGenerator {
//生成daoImpl文件
JavaDaoImplGenerator
daoImplGenerator
=
new
JavaDaoImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
daoImplGenerator
.
gen
();
//生成remote接口文件
JavaRemoteServiceInterfaceGenerator
remoteInterfaceGenerator
=
new
JavaRemoteServiceInterfaceGenerator
(
freemarkerService
,
tableEntity
,
config
);
remoteInterfaceGenerator
.
gen
();
//生成remoteImpl接口文件
JavaRemoteServiceInterfaceImplGenerator
remoteImplGenerator
=
new
JavaRemoteServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
remoteImplGenerator
.
gen
();
//生成Service接口文件
JavaServiceInterfaceGenerator
serviceInterfaceGenerator
=
new
JavaServiceInterfaceGenerator
(
freemarkerService
,
tableEntity
,
config
);
serviceInterfaceGenerator
.
gen
();
//生成ServiceImpl接口文件
JavaServiceInterfaceImplGenerator
serviceImplGenerator
=
new
JavaServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
serviceImplGenerator
.
gen
();
//生成web层-Controller接口文件
// JavaControllerImplGenerator controllerGenerator = new JavaControllerImplGenerator(freemarkerService, tableEntity, config);
// controllerGenerator.gen();
//生成web层-Vo接口文件
if
(
StringUtils
.
isNotBlank
(
config
.
getVoLocation
())){
JavaVoGenerator
voImplGenerator
=
new
JavaVoGenerator
(
freemarkerService
,
tableEntity
,
config
);
voImplGenerator
.
gen
();
}
//生成xml文件
SQLXmlGenerator
sqlXmlGenerator
=
new
SQLXmlGenerator
(
freemarkerService
,
tableEntity
,
config
);
sqlXmlGenerator
.
gen
();
...
...
src/main/java/cn/com/duiba/mysql/generator/entity/GeneratorConfig.java
View file @
6eec11b4
...
...
@@ -2,6 +2,7 @@ package cn.com.duiba.mysql.generator.entity;
import
cn.com.duiba.mysql.generator.MybatisGenerator
;
import
cn.com.duiba.mysql.generator.exceptions.DuibaGeneratorException
;
import
lombok.Data
;
import
org.apache.commons.lang.StringUtils
;
import
java.sql.Connection
;
...
...
@@ -9,6 +10,7 @@ import java.sql.Connection;
/**
* 代码生成器配置类
*/
//@Data
public
class
GeneratorConfig
{
/**
...
...
@@ -46,6 +48,11 @@ public class GeneratorConfig {
*/
private
String
entityPackage
;
/**
* entity包名,要生成的数据库对应实体包名
*/
private
String
dtoPackage
;
/**
* 模块名称
*/
...
...
@@ -56,6 +63,45 @@ public class GeneratorConfig {
*/
private
boolean
exeTest
=
true
;
/**
* true:以测试用例执行生成代码的方式
*/
private
boolean
needWebFile
=
false
;
/**
* true:以测试用例执行生成代码的方式
*/
private
String
remotePackage
;
/**
* true:以测试用例执行生成代码的方式
*/
private
String
remoteImplLocation
;
/**
* true:以测试用例执行生成代码的方式
*/
private
String
serviceLocation
;
/**
* true:以测试用例执行生成代码的方式
*/
private
String
serviceImplLocation
;
/**
* true:以测试用例执行生成代码的方式
*/
private
String
voLocation
;
/**
* true:以测试用例执行生成代码的方式
*/
private
String
controllerLocation
;
public
GeneratorConfig
(
String
dtoPackage
)
{
this
.
dtoPackage
=
dtoPackage
;
}
public
GeneratorConfig
(
String
dbUrl
,
String
dbUserName
,
String
dbPasswd
)
{
this
.
connection
=
MybatisGenerator
.
getConnection
(
dbUrl
,
dbUserName
,
dbPasswd
);
}
...
...
@@ -76,6 +122,27 @@ public class GeneratorConfig {
if
(
StringUtils
.
isEmpty
(
xmlLocation
))
{
throw
new
DuibaGeneratorException
(
"xmlLocation is null"
);
}
if
(
needWebFile
){
if
(
StringUtils
.
isEmpty
(
remotePackage
))
{
throw
new
DuibaGeneratorException
(
"remotePackage is null"
);
}
if
(
StringUtils
.
isEmpty
(
remoteImplLocation
))
{
throw
new
DuibaGeneratorException
(
"remoteImplLocation is null"
);
}
if
(
StringUtils
.
isEmpty
(
serviceLocation
))
{
throw
new
DuibaGeneratorException
(
"serviceLocation is null"
);
}
if
(
StringUtils
.
isEmpty
(
serviceImplLocation
))
{
throw
new
DuibaGeneratorException
(
"serviceImplLocation is null"
);
}
if
(
StringUtils
.
isEmpty
(
voLocation
))
{
throw
new
DuibaGeneratorException
(
"voLocation is null"
);
}
if
(
StringUtils
.
isEmpty
(
controllerLocation
))
{
throw
new
DuibaGeneratorException
(
"controllerLocation is null"
);
}
}
}
public
String
getTablePrefix
()
{
...
...
@@ -102,6 +169,14 @@ public class GeneratorConfig {
this
.
tableName
=
tableName
;
}
public
String
getTableSchema
()
{
return
tableSchema
;
}
public
void
setTableSchema
(
String
tableSchema
)
{
this
.
tableSchema
=
tableSchema
;
}
public
String
getDaoPackage
()
{
return
daoPackage
;
}
...
...
@@ -126,12 +201,12 @@ public class GeneratorConfig {
this
.
entityPackage
=
entityPackage
;
}
public
String
get
TableSchema
()
{
return
tableSchema
;
public
String
get
DtoPackage
()
{
return
dtoPackage
;
}
public
void
set
TableSchema
(
String
tableSchema
)
{
this
.
tableSchema
=
tableSchema
;
public
void
set
DtoPackage
(
String
dtoPackage
)
{
this
.
dtoPackage
=
dtoPackage
;
}
public
String
getModuleName
()
{
...
...
@@ -149,4 +224,60 @@ public class GeneratorConfig {
public
void
setExeTest
(
boolean
exeTest
)
{
this
.
exeTest
=
exeTest
;
}
public
boolean
isNeedWebFile
()
{
return
needWebFile
;
}
public
void
setNeedWebFile
(
boolean
needWebFile
)
{
this
.
needWebFile
=
needWebFile
;
}
public
String
getRemotePackage
()
{
return
remotePackage
;
}
public
void
setRemotePackage
(
String
remotePackage
)
{
this
.
remotePackage
=
remotePackage
;
}
public
String
getRemoteImplLocation
()
{
return
remoteImplLocation
;
}
public
void
setRemoteImplLocation
(
String
remoteImplLocation
)
{
this
.
remoteImplLocation
=
remoteImplLocation
;
}
public
String
getServiceLocation
()
{
return
serviceLocation
;
}
public
void
setServiceLocation
(
String
serviceLocation
)
{
this
.
serviceLocation
=
serviceLocation
;
}
public
String
getServiceImplLocation
()
{
return
serviceImplLocation
;
}
public
void
setServiceImplLocation
(
String
serviceImplLocation
)
{
this
.
serviceImplLocation
=
serviceImplLocation
;
}
public
String
getVoLocation
()
{
return
voLocation
;
}
public
void
setVoLocation
(
String
voLocation
)
{
this
.
voLocation
=
voLocation
;
}
public
String
getControllerLocation
()
{
return
controllerLocation
;
}
public
void
setControllerLocation
(
String
controllerLocation
)
{
this
.
controllerLocation
=
controllerLocation
;
}
}
src/main/java/cn/com/duiba/mysql/generator/gencode/AbstractGenerator.java
View file @
6eec11b4
...
...
@@ -35,8 +35,15 @@ public abstract class AbstractGenerator {
params
.
put
(
"pathName"
,
tableEntity
.
getClassname
().
toLowerCase
());
params
.
put
(
"columns"
,
tableEntity
.
getColumns
());
params
.
put
(
"entityPackage"
,
config
.
getEntityPackage
());
params
.
put
(
"dtoPackage"
,
config
.
getDtoPackage
());
params
.
put
(
"daoPackage"
,
config
.
getDaoPackage
());
params
.
put
(
"voPackage"
,
config
.
getVoLocation
());
params
.
put
(
"controllerLocation"
,
config
.
getControllerLocation
());
params
.
put
(
"serviceLocation"
,
config
.
getServiceLocation
());
params
.
put
(
"remoteImplLocation"
,
config
.
getRemoteImplLocation
());
params
.
put
(
"remotePackage"
,
config
.
getRemotePackage
());
params
.
put
(
"uks"
,
tableEntity
.
getUniqueKeyMap
());
params
.
put
(
"tableSchema"
,
tableEntity
.
getTableSchema
());
params
.
put
(
"pre"
,
"#{"
);
params
.
put
(
"end"
,
"}"
);
...
...
src/main/java/cn/com/duiba/mysql/generator/gencode/JavaDtoGenerator.java
0 → 100644
View file @
6eec11b4
package
cn
.
com
.
duiba
.
mysql
.
generator
.
gencode
;
import
cn.com.duiba.mysql.generator.entity.GeneratorConfig
;
import
cn.com.duiba.mysql.generator.entity.TableEntity
;
import
cn.com.duiba.mysql.generator.service.DuibaFreemarkerService
;
import
cn.com.duiba.mysql.generator.utils.PathUtils
;
/**
* @author sunchangji
*/
public
class
JavaDtoGenerator
extends
AbstractGenerator
{
public
JavaDtoGenerator
(
DuibaFreemarkerService
freemarkerService
,
TableEntity
tableEntity
,
GeneratorConfig
config
){
super
(
freemarkerService
,
tableEntity
,
config
);
}
@Override
public
String
getFTL
()
{
return
"java_dto"
;
}
@Override
public
String
genFileName
()
{
return
tableEntity
.
getClassName
()
+
"Dto.java"
;
}
@Override
protected
String
genFilePath
()
{
return
PathUtils
.
getPathByPackage
(
config
.
getDtoPackage
(),
config
);
}
}
src/main/java/cn/com/duiba/mysql/generator/gencode/JavaRemoteServiceInterfaceGenerator.java
0 → 100644
View file @
6eec11b4
package
cn
.
com
.
duiba
.
mysql
.
generator
.
gencode
;
import
cn.com.duiba.mysql.generator.entity.GeneratorConfig
;
import
cn.com.duiba.mysql.generator.entity.TableEntity
;
import
cn.com.duiba.mysql.generator.service.DuibaFreemarkerService
;
import
cn.com.duiba.mysql.generator.utils.PathUtils
;
public
class
JavaRemoteServiceInterfaceGenerator
extends
AbstractGenerator
{
public
JavaRemoteServiceInterfaceGenerator
(
DuibaFreemarkerService
freemarkerService
,
TableEntity
tableEntity
,
GeneratorConfig
config
)
{
super
(
freemarkerService
,
tableEntity
,
config
);
}
@Override
public
String
getFTL
()
{
return
"java_remote_service"
;
}
@Override
public
String
genFileName
()
{
return
"Remote"
+
tableEntity
.
getClassName
()
+
"Service.java"
;
}
@Override
protected
String
genFilePath
()
{
return
PathUtils
.
getPathByPackage
(
config
.
getRemotePackage
(),
config
);
}
}
src/main/java/cn/com/duiba/mysql/generator/gencode/JavaRemoteServiceInterfaceImplGenerator.java
0 → 100644
View file @
6eec11b4
package
cn
.
com
.
duiba
.
mysql
.
generator
.
gencode
;
import
cn.com.duiba.mysql.generator.entity.GeneratorConfig
;
import
cn.com.duiba.mysql.generator.entity.TableEntity
;
import
cn.com.duiba.mysql.generator.service.DuibaFreemarkerService
;
import
cn.com.duiba.mysql.generator.utils.PathUtils
;
public
class
JavaRemoteServiceInterfaceImplGenerator
extends
AbstractGenerator
{
public
JavaRemoteServiceInterfaceImplGenerator
(
DuibaFreemarkerService
freemarkerService
,
TableEntity
tableEntity
,
GeneratorConfig
config
)
{
super
(
freemarkerService
,
tableEntity
,
config
);
}
@Override
public
String
getFTL
()
{
return
"java_remote_service.impl"
;
}
@Override
public
String
genFileName
()
{
return
"Remote"
+
tableEntity
.
getClassName
()
+
"ServiceImpl.java"
;
}
@Override
protected
String
genFilePath
()
{
return
PathUtils
.
getPathByPackage
(
config
.
getRemoteImplLocation
(),
config
);
}
}
src/main/java/cn/com/duiba/mysql/generator/gencode/JavaServiceInterfaceGenerator.java
0 → 100644
View file @
6eec11b4
package
cn
.
com
.
duiba
.
mysql
.
generator
.
gencode
;
import
cn.com.duiba.mysql.generator.entity.GeneratorConfig
;
import
cn.com.duiba.mysql.generator.entity.TableEntity
;
import
cn.com.duiba.mysql.generator.service.DuibaFreemarkerService
;
import
cn.com.duiba.mysql.generator.utils.PathUtils
;
public
class
JavaServiceInterfaceGenerator
extends
AbstractGenerator
{
public
JavaServiceInterfaceGenerator
(
DuibaFreemarkerService
freemarkerService
,
TableEntity
tableEntity
,
GeneratorConfig
config
)
{
super
(
freemarkerService
,
tableEntity
,
config
);
}
@Override
public
String
getFTL
()
{
return
"java_service"
;
}
@Override
public
String
genFileName
()
{
return
tableEntity
.
getClassName
()
+
"Service.java"
;
}
@Override
protected
String
genFilePath
()
{
return
PathUtils
.
getPathByPackage
(
config
.
getServiceLocation
(),
config
);
}
}
src/main/java/cn/com/duiba/mysql/generator/gencode/JavaServiceInterfaceImplGenerator.java
0 → 100644
View file @
6eec11b4
package
cn
.
com
.
duiba
.
mysql
.
generator
.
gencode
;
import
cn.com.duiba.mysql.generator.entity.GeneratorConfig
;
import
cn.com.duiba.mysql.generator.entity.TableEntity
;
import
cn.com.duiba.mysql.generator.service.DuibaFreemarkerService
;
import
cn.com.duiba.mysql.generator.utils.PathUtils
;
public
class
JavaServiceInterfaceImplGenerator
extends
AbstractGenerator
{
public
JavaServiceInterfaceImplGenerator
(
DuibaFreemarkerService
freemarkerService
,
TableEntity
tableEntity
,
GeneratorConfig
config
)
{
super
(
freemarkerService
,
tableEntity
,
config
);
}
@Override
public
String
getFTL
()
{
return
"java_service.impl"
;
}
@Override
public
String
genFileName
()
{
return
tableEntity
.
getClassName
()
+
"ServiceImpl.java"
;
}
@Override
protected
String
genFilePath
()
{
return
PathUtils
.
getPathByPackage
(
config
.
getServiceImplLocation
(),
config
);
}
}
src/main/java/cn/com/duiba/mysql/generator/gencode/JavaVoGenerator.java
0 → 100644
View file @
6eec11b4
package
cn
.
com
.
duiba
.
mysql
.
generator
.
gencode
;
import
cn.com.duiba.mysql.generator.entity.GeneratorConfig
;
import
cn.com.duiba.mysql.generator.entity.TableEntity
;
import
cn.com.duiba.mysql.generator.service.DuibaFreemarkerService
;
import
cn.com.duiba.mysql.generator.utils.PathUtils
;
/**
* @author sunchangji
*/
public
class
JavaVoGenerator
extends
AbstractGenerator
{
public
JavaVoGenerator
(
DuibaFreemarkerService
freemarkerService
,
TableEntity
tableEntity
,
GeneratorConfig
config
){
super
(
freemarkerService
,
tableEntity
,
config
);
}
@Override
public
String
getFTL
()
{
return
"java_vo"
;
}
@Override
public
String
genFileName
()
{
return
tableEntity
.
getClassName
()
+
"Vo.java"
;
}
@Override
protected
String
genFilePath
()
{
return
PathUtils
.
getPathByPackage
(
config
.
getVoLocation
(),
config
);
}
}
src/main/resources/tpls/java_dao.ftl
View file @
6eec11b4
...
...
@@ -5,14 +5,14 @@ import java.util.List;
public
interface
${
table
.
className
}
Dao
{
int
save
(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
);
Integer
save
(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
);
<#
if
pk
??>
int
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
});
void
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
});
int
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
);
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
);
int
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
);
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
);
${
table
.
className
}
Entity
getBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
});
...
...
src/main/resources/tpls/java_dao_impl.ftl
View file @
6eec11b4
...
...
@@ -4,28 +4,44 @@ import ${daoPackage}.${table.className}Dao;
import
${
entityPackage
}.${
table
.
className
}
Entity
;
import
java
.
util
.
List
;
import
org
.
springframework
.
stereotype
.
Repository
;
import
cn
.
com
.
duiba
.
developer
.
center
.
common
.
dao
.
BaseDao
;
import
cn
.
com
.
duiba
.
developer
.
center
.
common
.
dao
.
DatabaseSchema
;
import
javax
.
annotation
.
PostConstruct
;
import
java
.
util
.
Map
;
import
com
.
google
.
common
.
collect
.
Maps
;
@
Repository
public
class
${
table
.
className
}
DaoImpl
implements
${
table
.
className
}
Dao
{
public
class
${
table
.
className
}
DaoImpl
extends
BaseDao
implements
${
table
.
className
}
Dao
{
@
Override
public
int
save
(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
return
0
;
@
PostConstruct
private
void
init
()
{
this
.
databaseSchema
=
DatabaseSchema
.${
tableSchema
?
upper_case
};
}
@
Override
public
Integer
save
(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
insert
(
"save"
,${
table
.
classname
}
Entity
);
return
${
table
.
classname
}
Entity
.
getId
();
}
<#
if
pk
??>
@
Override
public
int
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
0
;
public
void
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
Map
data
=
Maps
.
newHashMap
();
data
.
put
(
"id"
,${
pk
.
attrname
});
delete
(
"deleteBatchBy${pk.attrName}"
,
data
);
}
@
Override
public
int
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
public
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
0
;
}
@
Override
public
int
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
public
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
return
0
;
}
...
...
src/main/resources/tpls/java_dto.ftl
0 → 100644
View file @
6eec11b4
package
${
dtoPackage
};
<#
assign
hasBigDecimal
=
0
,
hasDate
=
0
>
<#
list
columns
as
c
>
<#
if
c
.
attrType
==
'BigDecimal'
>
<#
assign
hasBigDecimal
=
hasBigDecimal
+
1
>
<#
elseif
c
.
attrType
==
'Date'
>
<#
assign
hasDate
=
hasDate
+
1
>
</#
if
>
</#
list
>
<#
if
(
hasBigDecimal
>
0
)
>
import
java
.
math
.
BigDecimal
;
</#
if
>
<#
if
(
hasDate
>
0
)>
import
java
.
util
.
Date
;
</#
if
>
import
java
.
io
.
Serializable
;
<#
if
table
.
comments
??
>
/**
*
${
table
.
comments
}
*/
</#
if
>
public
class
${
table
.
className
}
Dto
implements
Serializable
{
<#
list
columns
as
column
>
<#
if
column
.
comments
??
>
/**
*
${
column
.
comments
}
*/
</#
if
>
private
${
column
.
attrType
}
${
column
.
attrname
};
</#
list
>
<#
list
columns
as
column
>
public
void
set
${
column
.
attrName
}(${
column
.
attrType
}
${
column
.
attrname
})
{
this
.${
column
.
attrname
}
=
${
column
.
attrname
};
}
public
${
column
.
attrType
}
get
${
column
.
attrName
}()
{
return
${
column
.
attrname
};
}
</#
list
>
}
src/main/resources/tpls/java_remote_service.ftl
0 → 100644
View file @
6eec11b4
package
${
remotePackage
};
import
${
dtoPackage
}.${
table
.
className
}
Dto
;
import
java
.
util
.
List
;
import
cn
.
com
.
duiba
.
boot
.
exception
.
BizException
;
import
cn
.
com
.
duiba
.
boot
.
netflix
.
feign
.
AdvancedFeignClient
;
@
AdvancedFeignClient
public
interface
Remote
${
table
.
className
}
Service
{
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
)
throws
BizException
;
<#
if
pk
??>
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
})
throws
BizException
;
Integer
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
)
throws
BizException
;
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
)
throws
BizException
;
${
table
.
className
}
Dto
getBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
})
throws
BizException
;
List
<${
table
.
className
}
Dto
>
listBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
)
throws
BizException
;
</#
if
>
<#
list
uks
?
keys
as
key
>
${
table
.
className
}
Dto
getBy
${
key
}(<#
assign
idx
=
0
><#
list
uks
[
key
]
as
uk
>${
uk
.
attrType
}
${
uk
.
attrname
}<#
assign
idx
=
idx
+
1
><#
if
(
idx
<
uks
[
key
]?
size
)>,</#
if
></#
list
>)
throws
BizException
;
List
<${
table
.
className
}
Dto
>
listBy
${
key
}
s
(<#
assign
idx
=
0
><#
list
uks
[
key
]
as
uk
>
List
<${
uk
.
attrType
}>
${
uk
.
attrname
}
s
<#
assign
idx
=
idx
+
1
><#
if
(
idx
<
uks
[
key
]?
size
)>,</#
if
></#
list
>)
throws
BizException
;
</#
list
>
}
src/main/resources/tpls/java_remote_service.impl.ftl
0 → 100644
View file @
6eec11b4
package
${
remoteImplLocation
};
import
${
dtoPackage
}.${
table
.
className
}
Dto
;
import
${
remotePackage
}.
Remote
${
table
.
className
}
Service
;
import
${
serviceLocation
}.${
table
.
className
}
Service
;
import
java
.
util
.
List
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
RestController
;
import
org
.
slf4j
.
Logger
;
import
org
.
slf4j
.
LoggerFactory
;
@
RestController
public
class
Remote
${
table
.
className
}
ServiceImpl
implements
Remote
${
table
.
className
}
Service
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Remote
${
table
.
className
}
ServiceImpl
.
class
);
@
Autowired
private
${
table
.
className
}
Service
${
table
.
classname
}
Service
;
@
Override
public
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
){
return
${
table
.
classname
}
Service
.
save
(${
table
.
classname
}
Dto
);
}
<#
if
pk
??>
@
Override
public
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
${
table
.
classname
}
Service
.
deleteBy
${
pk
.
attrName
}(${
pk
.
attrname
});
}
@
Override
public
Integer
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
${
table
.
classname
}
Service
.
deleteBatchBy
${
pk
.
attrName
}(${
pk
.
attrname
}
s
);
}
@
Override
public
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
){
return
${
table
.
classname
}
Service
.
updateBy
${
pk
.
attrName
}(${
table
.
classname
}
Dto
);
}
@
Override
public
${
table
.
className
}
Dto
getBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
${
table
.
classname
}
Service
.
getBy
${
pk
.
attrName
}(${
pk
.
attrname
});
}
@
Override
public
List
<${
table
.
className
}
Dto
>
listBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
${
table
.
classname
}
Service
.
listBy
${
pk
.
attrName
}
s
(${
pk
.
attrname
}
s
);
}
</#
if
>
<#
list
uks
?
keys
as
key
>
@
Override
public
${
table
.
className
}
Dto
getBy
${
key
}(<#
assign
idx
=
0
><#
list
uks
[
key
]
as
uk
>${
uk
.
attrType
}
${
uk
.
attrname
}<#
assign
idx
=
idx
+
1
><#
if
(
idx
<
uks
[
key
]?
size
)>,</#
if
></#
list
>){
return
${
table
.
classNclassnameame
}
Service
.
getBy
${
key
}(${
uk
.
attrname
});
}
@
Override
public
List
<${
table
.
className
}
Dto
>
listBy
${
key
}
s
(<#
assign
idx
=
0
><#
list
uks
[
key
]
as
uk
>
List
<${
uk
.
attrType
}>
${
uk
.
attrname
}
s
<#
assign
idx
=
idx
+
1
><#
if
(
idx
<
uks
[
key
]?
size
)>,</#
if
></#
list
>){
return
${
table
.
classname
}
Service
.
listBy
${
key
}
s
(${
uk
.
attrname
}
s
);
}
</#
list
>
}
src/main/resources/tpls/java_service.ftl
0 → 100644
View file @
6eec11b4
package
${
serviceLocation
};
import
${
dtoPackage
}.${
table
.
className
}
Dto
;
import
java
.
util
.
List
;
public
interface
${
table
.
className
}
Service
{
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
);
<#
if
pk
??>
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
});
Integer
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
);
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
);
${
table
.
className
}
Dto
getBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
});
List
<${
table
.
className
}
Dto
>
listBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
);
</#
if
>
<#
list
uks
?
keys
as
key
>
${
table
.
className
}
Dto
getBy
${
key
}(<#
assign
idx
=
0
><#
list
uks
[
key
]
as
uk
>${
uk
.
attrType
}
${
uk
.
attrname
}<#
assign
idx
=
idx
+
1
><#
if
(
idx
<
uks
[
key
]?
size
)>,</#
if
></#
list
>);
List
<${
table
.
className
}
Dto
>
listBy
${
key
}
s
(<#
assign
idx
=
0
><#
list
uks
[
key
]
as
uk
>
List
<${
uk
.
attrType
}>
${
uk
.
attrname
}
s
<#
assign
idx
=
idx
+
1
><#
if
(
idx
<
uks
[
key
]?
size
)>,</#
if
></#
list
>);
</#
list
>
}
src/main/resources/tpls/java_service.impl.ftl
0 → 100644
View file @
6eec11b4
package
${
serviceLocation
}.
impl
;
import
${
serviceLocation
}.${
table
.
className
}
Service
;
import
${
dtoPackage
}.${
table
.
className
}
Dto
;
import
${
daoPackage
}.${
table
.
className
}
Dao
;
import
${
entityPackage
}.${
table
.
className
}
Entity
;
import
java
.
util
.
List
;
import
org
.
slf4j
.
Logger
;
import
org
.
slf4j
.
LoggerFactory
;
import
org
.
springframework
.
stereotype
.
Repository
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
stereotype
.
Service
;
import
org
.
springframework
.
transaction
.
annotation
.
Transactional
;
import
cn
.
com
.
duiba
.
wolf
.
utils
.
BeanUtils
;
@
Service
public
class
${
table
.
className
}
ServiceImpl
implements
${
table
.
className
}
Service
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(${
table
.
className
}
ServiceImpl
.
class
);
@
Autowired
private
${
table
.
className
}
Dao
${
table
.
classname
}
Dao
;
@
Override
public
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
){
return
${
table
.
classname
}
Dao
.
save
(
BeanUtils
.
copy
(${
table
.
classname
}
Dto
,
${
table
.
className
}
Entity
.
class
));
}
<#
if
pk
??>
@
Override
public
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
${
table
.
classname
}
Dao
.
deleteBy
${
pk
.
attrName
}(${
pk
.
attrname
});
}
@
Override
public
Integer
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
${
table
.
classname
}
Dao
.
deleteBatchBy
${
pk
.
attrName
}(${
pk
.
attrname
}
s
);
}
@
Override
public
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
){
return
${
table
.
classname
}
Dao
.
updateBy
${
pk
.
attrName
}(
BeanUtils
.
copy
(${
table
.
classname
}
Dto
,
${
table
.
className
}
Entity
.
class
));
}
@
Override
public
${
table
.
className
}
Dto
getBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
BeanUtils
.
copy
(${
table
.
classname
}
Dao
.
getBy
${
pk
.
attrName
}(${
pk
.
attrname
}),
${
table
.
className
}
Dto
.
class
);
}
@
Override
public
List
<${
table
.
className
}
Dto
>
listBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
BeanUtils
.
copyList
(${
table
.
classname
}
Dao
.
listBy
${
pk
.
attrName
}
s
(${
pk
.
attrname
}
s
),
${
table
.
className
}
Dto
.
class
);
}
</#
if
>
<#
list
uks
?
keys
as
key
>
@
Override
public
${
table
.
className
}
Dto
getBy
${
key
}(<#
assign
idx
=
0
><#
list
uks
[
key
]
as
uk
>${
uk
.
attrType
}
${
uk
.
attrname
}<#
assign
idx
=
idx
+
1
><#
if
(
idx
<
uks
[
key
]?
size
)>,</#
if
></#
list
>){
return
BeanUtils
.
copy
(${
table
.
classname
}
Dao
.
getBy
${
key
}(${
uk
.
attrname
}),
${
table
.
className
}
Dto
.
class
);
}
@
Override
public
List
<${
table
.
className
}
Dto
>
listBy
${
key
}
s
(<#
assign
idx
=
0
><#
list
uks
[
key
]
as
uk
>
List
<${
uk
.
attrType
}>
${
uk
.
attrname
}
s
<#
assign
idx
=
idx
+
1
><#
if
(
idx
<
uks
[
key
]?
size
)>,</#
if
></#
list
>){
return
BeanUtils
.
copyList
(${
table
.
classname
}
Dao
.
listBy
${
key
}
s
(${
uk
.
attrname
}
s
),
${
table
.
className
}
Dto
.
class
);
}
</#
list
>
}
src/main/resources/tpls/java_vo.ftl
0 → 100644
View file @
6eec11b4
package
${
voPackage
};
<#
assign
hasBigDecimal
=
0
,
hasDate
=
0
>
<#
list
columns
as
c
>
<#
if
c
.
attrType
==
'BigDecimal'
>
<#
assign
hasBigDecimal
=
hasBigDecimal
+
1
>
<#
elseif
c
.
attrType
==
'Date'
>
<#
assign
hasDate
=
hasDate
+
1
>
</#
if
>
</#
list
>
<#
if
(
hasBigDecimal
>
0
)
>
import
java
.
math
.
BigDecimal
;
</#
if
>
<#
if
(
hasDate
>
0
)>
import
java
.
util
.
Date
;
</#
if
>
<#
if
table
.
comments
??
>
/**
*
${
table
.
comments
}
*/
</#
if
>
public
class
${
table
.
className
}
Vo
{
<#
list
columns
as
column
>
<#
if
column
.
comments
??
>
/**
*
${
column
.
comments
}
*/
</#
if
>
private
${
column
.
attrType
}
${
column
.
attrname
};
</#
list
>
<#
list
columns
as
column
>
public
void
set
${
column
.
attrName
}(${
column
.
attrType
}
${
column
.
attrname
})
{
this
.${
column
.
attrname
}
=
${
column
.
attrname
};
}
public
${
column
.
attrType
}
get
${
column
.
attrName
}()
{
return
${
column
.
attrname
};
}
</#
list
>
}
src/test/java/cn/com/duiba/mysql/generator/CodeGeneratorTest.java
View file @
6eec11b4
...
...
@@ -6,16 +6,24 @@ public class CodeGeneratorTest {
public
static
void
main
(
String
[]
args
)
{
String
DB_URL
=
"jdbc:mysql://
dev.config.duibar.com:3306/act_com_conf
?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&connectTimeout=5000&socketTimeout=60000"
;
String
user
=
"
dev
"
;
String
pwd
=
"
dev_fas015
"
;
String
DB_URL
=
"jdbc:mysql://
43.142.41.164:3307/ad_project
?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&connectTimeout=5000&socketTimeout=60000"
;
String
user
=
"
root
"
;
String
pwd
=
"
liukai6651
"
;
GeneratorConfig
config
=
new
GeneratorConfig
(
DB_URL
,
user
,
pwd
);
config
.
setDaoPackage
(
"cn.com.duiba.mysql.generator.test.dao"
);
config
.
setEntityPackage
(
"cn.com.duiba.mysql.generator.test.entity"
);
config
.
setXmlLocation
(
"src/main/resources/mappers"
);
config
.
setTableSchema
(
"act_com_conf"
);
config
.
setTableName
(
"tb_duiba_brick_config"
);
config
.
setServiceLocation
(
"cn.com.duiba.mysql.generator.test.service"
);
config
.
setServiceImplLocation
(
"cn.com.duiba.mysql.generator.test.service.impl"
);
config
.
setDtoPackage
(
"cn.com.duiba.mysql.generator.test.dto"
);
config
.
setRemotePackage
(
"cn.com.duiba.mysql.generator.test.remote"
);
config
.
setRemoteImplLocation
(
"cn.com.duiba.mysql.generator.test.remoteImpl"
);
config
.
setVoLocation
(
"cn.com.duiba.mysql.generator.test.vo"
);
config
.
setTableSchema
(
"ad_project"
);
config
.
setTableName
(
"ad_account_of_facebook"
);
config
.
setTablePrefix
(
"tb"
);
config
.
setModuleName
(
""
);
...
...
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