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
d6a7578c
Commit
d6a7578c
authored
Nov 02, 2022
by
刘凯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加remote remoteImpl等生成文件
parent
6eec11b4
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
83 additions
and
46 deletions
+83
-46
build.gradle
build.gradle
+1
-1
MybatisGenerator.java
...n/java/cn/com/duiba/mysql/generator/MybatisGenerator.java
+42
-20
GeneratorConfig.java
.../cn/com/duiba/mysql/generator/entity/GeneratorConfig.java
+14
-6
java_dao_impl.ftl
src/main/resources/tpls/java_dao_impl.ftl
+12
-6
java_dto.ftl
src/main/resources/tpls/java_dto.ftl
+1
-0
java_remote_service.ftl
src/main/resources/tpls/java_remote_service.ftl
+2
-2
java_remote_service.impl.ftl
src/main/resources/tpls/java_remote_service.impl.ftl
+5
-5
java_service.ftl
src/main/resources/tpls/java_service.ftl
+2
-2
java_service.impl.ftl
src/main/resources/tpls/java_service.impl.ftl
+4
-4
No files found.
build.gradle
View file @
d6a7578c
...
@@ -18,7 +18,7 @@ apply plugin: "idea"
...
@@ -18,7 +18,7 @@ apply plugin: "idea"
apply
plugin:
"eclipse"
apply
plugin:
"eclipse"
group
=
"cn.com.duiba"
group
=
"cn.com.duiba"
version
=
"0.2.0"
version
=
"0.2.
1
0"
sourceCompatibility
=
1.8
sourceCompatibility
=
1.8
targetCompatibility
=
1.8
targetCompatibility
=
1.8
...
...
src/main/java/cn/com/duiba/mysql/generator/MybatisGenerator.java
View file @
d6a7578c
...
@@ -42,30 +42,36 @@ public class MybatisGenerator {
...
@@ -42,30 +42,36 @@ public class MybatisGenerator {
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
DuibaGeneratorException
(
e
);
throw
new
DuibaGeneratorException
(
e
);
}
}
//生成dto文件
JavaDtoGenerator
dtoGenerator
=
new
JavaDtoGenerator
(
freemarkerService
,
tableEntity
,
config
);
dtoGenerator
.
gen
();
//生成entity文件
//生成entity文件
if
(
StringUtils
.
isNotBlank
(
config
.
getEntityPackage
()))
{
JavaEntityGenerator
doGenerator
=
new
JavaEntityGenerator
(
freemarkerService
,
tableEntity
,
config
);
JavaEntityGenerator
doGenerator
=
new
JavaEntityGenerator
(
freemarkerService
,
tableEntity
,
config
);
doGenerator
.
gen
();
doGenerator
.
gen
();
}
//生成dao文件
//生成dao文件
if
(
StringUtils
.
isNotBlank
(
config
.
getDaoPackage
()))
{
JavaDaoGenerator
daoGenerator
=
new
JavaDaoGenerator
(
freemarkerService
,
tableEntity
,
config
);
JavaDaoGenerator
daoGenerator
=
new
JavaDaoGenerator
(
freemarkerService
,
tableEntity
,
config
);
daoGenerator
.
gen
();
daoGenerator
.
gen
();
}
//生成daoImpl文件
//生成daoImpl文件
if
(
StringUtils
.
isNotBlank
(
config
.
getDaoPackage
()))
{
JavaDaoImplGenerator
daoImplGenerator
=
new
JavaDaoImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
JavaDaoImplGenerator
daoImplGenerator
=
new
JavaDaoImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
daoImplGenerator
.
gen
();
daoImplGenerator
.
gen
();
}
//生成remote接口文件
//生成remote接口文件
JavaRemoteServiceInterfaceGenerator
remoteInterfaceGenerator
=
new
JavaRemoteServiceInterfaceGenerator
(
freemarkerService
,
tableEntity
,
config
);
if
(
StringUtils
.
isNotBlank
(
config
.
getRemoteImplLocation
()))
{
remoteInterfaceGenerator
.
gen
();
//生成remoteImpl接口文件
JavaRemoteServiceInterfaceImplGenerator
remoteImplGenerator
=
new
JavaRemoteServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
JavaRemoteServiceInterfaceImplGenerator
remoteImplGenerator
=
new
JavaRemoteServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
remoteImplGenerator
.
gen
();
remoteImplGenerator
.
gen
();
}
//生成Service接口文件
//生成Service接口文件
if
(
StringUtils
.
isNotBlank
(
config
.
getServiceLocation
()))
{
JavaServiceInterfaceGenerator
serviceInterfaceGenerator
=
new
JavaServiceInterfaceGenerator
(
freemarkerService
,
tableEntity
,
config
);
JavaServiceInterfaceGenerator
serviceInterfaceGenerator
=
new
JavaServiceInterfaceGenerator
(
freemarkerService
,
tableEntity
,
config
);
serviceInterfaceGenerator
.
gen
();
serviceInterfaceGenerator
.
gen
();
}
//生成ServiceImpl接口文件
//生成ServiceImpl接口文件
if
(
StringUtils
.
isNotBlank
(
config
.
getServiceImplLocation
()))
{
JavaServiceInterfaceImplGenerator
serviceImplGenerator
=
new
JavaServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
JavaServiceInterfaceImplGenerator
serviceImplGenerator
=
new
JavaServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
serviceImplGenerator
.
gen
();
serviceImplGenerator
.
gen
();
}
//生成web层-Controller接口文件
//生成web层-Controller接口文件
// JavaControllerImplGenerator controllerGenerator = new JavaControllerImplGenerator(freemarkerService, tableEntity, config);
// JavaControllerImplGenerator controllerGenerator = new JavaControllerImplGenerator(freemarkerService, tableEntity, config);
// controllerGenerator.gen();
// controllerGenerator.gen();
...
@@ -75,9 +81,25 @@ public class MybatisGenerator {
...
@@ -75,9 +81,25 @@ public class MybatisGenerator {
voImplGenerator
.
gen
();
voImplGenerator
.
gen
();
}
}
//生成xml文件
//生成xml文件
if
(
StringUtils
.
isNotBlank
(
config
.
getXmlLocation
())){
SQLXmlGenerator
sqlXmlGenerator
=
new
SQLXmlGenerator
(
freemarkerService
,
tableEntity
,
config
);
SQLXmlGenerator
sqlXmlGenerator
=
new
SQLXmlGenerator
(
freemarkerService
,
tableEntity
,
config
);
sqlXmlGenerator
.
gen
();
sqlXmlGenerator
.
gen
();
}
}
if
(
StringUtils
.
isNotBlank
(
config
.
getApiModuleName
())){
config
.
setModuleName
(
config
.
getApiModuleName
());
}
//生成dto文件
if
(
StringUtils
.
isNotBlank
(
config
.
getDtoPackage
()))
{
JavaDtoGenerator
dtoGenerator
=
new
JavaDtoGenerator
(
freemarkerService
,
tableEntity
,
config
);
dtoGenerator
.
gen
();
}
//生成remoteImpl接口文件
if
(
StringUtils
.
isNotBlank
(
config
.
getRemotePackage
()))
{
JavaRemoteServiceInterfaceGenerator
remoteInterfaceGenerator
=
new
JavaRemoteServiceInterfaceGenerator
(
freemarkerService
,
tableEntity
,
config
);
remoteInterfaceGenerator
.
gen
();
}
}
private
static
void
check
(
GeneratorConfig
config
)
{
private
static
void
check
(
GeneratorConfig
config
)
{
if
(
config
==
null
){
if
(
config
==
null
){
...
...
src/main/java/cn/com/duiba/mysql/generator/entity/GeneratorConfig.java
View file @
d6a7578c
...
@@ -58,6 +58,11 @@ public class GeneratorConfig {
...
@@ -58,6 +58,11 @@ public class GeneratorConfig {
*/
*/
private
String
moduleName
;
private
String
moduleName
;
/**
* 模块名称
*/
private
String
apiModuleName
;
/**
/**
* true:以测试用例执行生成代码的方式
* true:以测试用例执行生成代码的方式
*/
*/
...
@@ -135,14 +140,17 @@ public class GeneratorConfig {
...
@@ -135,14 +140,17 @@ public class GeneratorConfig {
if
(
StringUtils
.
isEmpty
(
serviceImplLocation
))
{
if
(
StringUtils
.
isEmpty
(
serviceImplLocation
))
{
throw
new
DuibaGeneratorException
(
"serviceImplLocation is null"
);
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
getApiModuleName
()
{
return
apiModuleName
;
}
}
public
void
setApiModuleName
(
String
apiModuleName
)
{
this
.
apiModuleName
=
apiModuleName
;
}
}
public
String
getTablePrefix
()
{
public
String
getTablePrefix
()
{
...
...
src/main/resources/tpls/java_dao_impl.ftl
View file @
d6a7578c
...
@@ -23,7 +23,7 @@ public class ${table.className}DaoImpl extends BaseDao implements ${table.classN
...
@@ -23,7 +23,7 @@ public class ${table.className}DaoImpl extends BaseDao implements ${table.classN
@
Override
@
Override
public
Integer
save
(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
public
Integer
save
(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
insert
(
"save"
,${
table
.
classname
}
Entity
);
insert
(
"save"
,${
table
.
classname
}
Entity
);
return
${
table
.
classname
}
Entity
.
getId
()
;
return
${
table
.
classname
}
Entity
.
getId
()
>
0
?
1
:
0
;
}
}
<#
if
pk
??>
<#
if
pk
??>
...
@@ -37,33 +37,39 @@ public class ${table.className}DaoImpl extends BaseDao implements ${table.classN
...
@@ -37,33 +37,39 @@ public class ${table.className}DaoImpl extends BaseDao implements ${table.classN
@
Override
@
Override
public
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
public
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
0
;
Map
data
=
Maps
.
newHashMap
();
data
.
put
(
"${pk.attrName}s"
,${
pk
.
attrname
}
s
);
delete
(
"deleteBatchBy${pk.attrName}"
,
data
);
}
}
@
Override
@
Override
public
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
public
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
return
0
;
return
update
(
"updateBy${pk.attrName}"
,${
table
.
classname
}
Entity
)
;
}
}
@
Override
@
Override
public
${
table
.
className
}
Entity
getBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
public
${
table
.
className
}
Entity
getBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
null
;
return
selectOne
(
"getBy${pk.attrName}"
,${
pk
.
attrname
})
;
}
}
@
Override
@
Override
public
List
<${
table
.
className
}
Entity
>
listBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
public
List
<${
table
.
className
}
Entity
>
listBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
null
;
Map
data
=
Maps
.
newHashMap
();
data
.
put
(
"${pk.attrname}s"
,${
pk
.
attrname
}
s
);
return
selectList
(
"listBy${pk.attrName}s"
,
data
);
}
}
</#
if
>
</#
if
>
<#
list
uks
?
keys
as
key
>
<#
list
uks
?
keys
as
key
>
@
Override
@
Override
public
${
table
.
className
}
Entity
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
>){
public
${
table
.
className
}
Entity
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
>){
//
todo
return
null
;
return
null
;
}
}
@
Override
@
Override
public
List
<${
table
.
className
}
Entity
>
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
>){
public
List
<${
table
.
className
}
Entity
>
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
>){
//
todo
return
null
;
return
null
;
}
}
...
...
src/main/resources/tpls/java_dto.ftl
View file @
d6a7578c
...
@@ -23,6 +23,7 @@ import java.io.Serializable;
...
@@ -23,6 +23,7 @@ import java.io.Serializable;
</#
if
>
</#
if
>
public
class
${
table
.
className
}
Dto
implements
Serializable
{
public
class
${
table
.
className
}
Dto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
8065426618925769915L
;
<#
list
columns
as
column
>
<#
list
columns
as
column
>
...
...
src/main/resources/tpls/java_remote_service.ftl
View file @
d6a7578c
...
@@ -11,9 +11,9 @@ public interface Remote${table.className}Service {
...
@@ -11,9 +11,9 @@ public interface Remote${table.className}Service {
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
)
throws
BizException
;
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
)
throws
BizException
;
<#
if
pk
??>
<#
if
pk
??>
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
})
throws
BizException
;
void
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
})
throws
BizException
;
Integer
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
)
throws
BizException
;
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
)
throws
BizException
;
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
)
throws
BizException
;
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
)
throws
BizException
;
...
...
src/main/resources/tpls/java_remote_service.impl.ftl
View file @
d6a7578c
...
@@ -25,13 +25,13 @@ public class Remote${table.className}ServiceImpl implements Remote${table.classN
...
@@ -25,13 +25,13 @@ public class Remote${table.className}ServiceImpl implements Remote${table.classN
<#
if
pk
??>
<#
if
pk
??>
@
Override
@
Override
public
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
public
void
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
${
table
.
classname
}
Service
.
deleteBy
${
pk
.
attrName
}(${
pk
.
attrname
});
${
table
.
classname
}
Service
.
deleteBy
${
pk
.
attrName
}(${
pk
.
attrname
});
}
}
@
Override
@
Override
public
Integer
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
public
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
${
table
.
classname
}
Service
.
deleteBatchBy
${
pk
.
attrName
}(${
pk
.
attrname
}
s
);
${
table
.
classname
}
Service
.
deleteBatchBy
${
pk
.
attrName
}(${
pk
.
attrname
}
s
);
}
}
@
Override
@
Override
...
...
src/main/resources/tpls/java_service.ftl
View file @
d6a7578c
...
@@ -9,9 +9,9 @@ public interface ${table.className}Service {
...
@@ -9,9 +9,9 @@ public interface ${table.className}Service {
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
);
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
);
<#
if
pk
??>
<#
if
pk
??>
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
});
void
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
});
Integer
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
);
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
);
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
);
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
);
...
...
src/main/resources/tpls/java_service.impl.ftl
View file @
d6a7578c
...
@@ -29,13 +29,13 @@ public class ${table.className}ServiceImpl implements ${table.className}Service{
...
@@ -29,13 +29,13 @@ public class ${table.className}ServiceImpl implements ${table.className}Service{
<#
if
pk
??>
<#
if
pk
??>
@
Override
@
Override
public
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
public
void
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
${
table
.
classname
}
Dao
.
deleteBy
${
pk
.
attrName
}(${
pk
.
attrname
});
${
table
.
classname
}
Dao
.
deleteBy
${
pk
.
attrName
}(${
pk
.
attrname
});
}
}
@
Override
@
Override
public
Integer
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
public
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
return
${
table
.
classname
}
Dao
.
deleteBatchBy
${
pk
.
attrName
}
(${
pk
.
attrname
}
s
);
${
table
.
classname
}
Dao
.
deleteBatchBy
${
pk
.
attrName
}
s
(${
pk
.
attrname
}
s
);
}
}
@
Override
@
Override
...
...
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