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
Hide 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"
apply
plugin:
"eclipse"
group
=
"cn.com.duiba"
version
=
"0.2.0"
version
=
"0.2.
1
0"
sourceCompatibility
=
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 {
}
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
();
if
(
StringUtils
.
isNotBlank
(
config
.
getEntityPackage
()))
{
JavaEntityGenerator
doGenerator
=
new
JavaEntityGenerator
(
freemarkerService
,
tableEntity
,
config
);
doGenerator
.
gen
();
}
//生成dao文件
JavaDaoGenerator
daoGenerator
=
new
JavaDaoGenerator
(
freemarkerService
,
tableEntity
,
config
);
daoGenerator
.
gen
();
if
(
StringUtils
.
isNotBlank
(
config
.
getDaoPackage
()))
{
JavaDaoGenerator
daoGenerator
=
new
JavaDaoGenerator
(
freemarkerService
,
tableEntity
,
config
);
daoGenerator
.
gen
();
}
//生成daoImpl文件
JavaDaoImplGenerator
daoImplGenerator
=
new
JavaDaoImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
daoImplGenerator
.
gen
();
if
(
StringUtils
.
isNotBlank
(
config
.
getDaoPackage
()))
{
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
();
if
(
StringUtils
.
isNotBlank
(
config
.
getRemoteImplLocation
()))
{
JavaRemoteServiceInterfaceImplGenerator
remoteImplGenerator
=
new
JavaRemoteServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
remoteImplGenerator
.
gen
();
}
//生成Service接口文件
JavaServiceInterfaceGenerator
serviceInterfaceGenerator
=
new
JavaServiceInterfaceGenerator
(
freemarkerService
,
tableEntity
,
config
);
serviceInterfaceGenerator
.
gen
();
if
(
StringUtils
.
isNotBlank
(
config
.
getServiceLocation
()))
{
JavaServiceInterfaceGenerator
serviceInterfaceGenerator
=
new
JavaServiceInterfaceGenerator
(
freemarkerService
,
tableEntity
,
config
);
serviceInterfaceGenerator
.
gen
();
}
//生成ServiceImpl接口文件
JavaServiceInterfaceImplGenerator
serviceImplGenerator
=
new
JavaServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
serviceImplGenerator
.
gen
();
if
(
StringUtils
.
isNotBlank
(
config
.
getServiceImplLocation
()))
{
JavaServiceInterfaceImplGenerator
serviceImplGenerator
=
new
JavaServiceInterfaceImplGenerator
(
freemarkerService
,
tableEntity
,
config
);
serviceImplGenerator
.
gen
();
}
//生成web层-Controller接口文件
// JavaControllerImplGenerator controllerGenerator = new JavaControllerImplGenerator(freemarkerService, tableEntity, config);
// controllerGenerator.gen();
...
...
@@ -75,8 +81,24 @@ public class MybatisGenerator {
voImplGenerator
.
gen
();
}
//生成xml文件
SQLXmlGenerator
sqlXmlGenerator
=
new
SQLXmlGenerator
(
freemarkerService
,
tableEntity
,
config
);
sqlXmlGenerator
.
gen
();
if
(
StringUtils
.
isNotBlank
(
config
.
getXmlLocation
())){
SQLXmlGenerator
sqlXmlGenerator
=
new
SQLXmlGenerator
(
freemarkerService
,
tableEntity
,
config
);
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
)
{
...
...
src/main/java/cn/com/duiba/mysql/generator/entity/GeneratorConfig.java
View file @
d6a7578c
...
...
@@ -58,6 +58,11 @@ public class GeneratorConfig {
*/
private
String
moduleName
;
/**
* 模块名称
*/
private
String
apiModuleName
;
/**
* true:以测试用例执行生成代码的方式
*/
...
...
@@ -135,16 +140,19 @@ public class GeneratorConfig {
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
getApiModuleName
()
{
return
apiModuleName
;
}
public
void
setApiModuleName
(
String
apiModuleName
)
{
this
.
apiModuleName
=
apiModuleName
;
}
public
String
getTablePrefix
()
{
return
tablePrefix
;
}
...
...
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
@
Override
public
Integer
save
(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
insert
(
"save"
,${
table
.
classname
}
Entity
);
return
${
table
.
classname
}
Entity
.
getId
()
;
return
${
table
.
classname
}
Entity
.
getId
()
>
0
?
1
:
0
;
}
<#
if
pk
??>
...
...
@@ -37,33 +37,39 @@ public class ${table.className}DaoImpl extends BaseDao implements ${table.classN
@
Override
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
public
Integer
updateBy
${
pk
.
attrName
}(${
table
.
className
}
Entity
${
table
.
classname
}
Entity
){
return
0
;
return
update
(
"updateBy${pk.attrName}"
,${
table
.
classname
}
Entity
)
;
}
@
Override
public
${
table
.
className
}
Entity
getBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
null
;
return
selectOne
(
"getBy${pk.attrName}"
,${
pk
.
attrname
})
;
}
@
Override
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
>
<#
list
uks
?
keys
as
key
>
@
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
>){
return
null
;
//
todo
return
null
;
}
@
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
>){
//
todo
return
null
;
}
...
...
src/main/resources/tpls/java_dto.ftl
View file @
d6a7578c
...
...
@@ -23,6 +23,7 @@ import java.io.Serializable;
</#
if
>
public
class
${
table
.
className
}
Dto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
8065426618925769915L
;
<#
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 {
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
)
throws
BizException
;
<#
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
;
...
...
src/main/resources/tpls/java_remote_service.impl.ftl
View file @
d6a7578c
...
...
@@ -25,18 +25,18 @@ public class Remote${table.className}ServiceImpl implements Remote${table.classN
<#
if
pk
??>
@
Override
public
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
${
table
.
classname
}
Service
.
deleteBy
${
pk
.
attrName
}(${
pk
.
attrname
});
public
void
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
${
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
);
public
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
${
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
);
return
${
table
.
classname
}
Service
.
updateBy
${
pk
.
attrName
}(${
table
.
classname
}
Dto
);
}
@
Override
...
...
src/main/resources/tpls/java_service.ftl
View file @
d6a7578c
...
...
@@ -9,9 +9,9 @@ public interface ${table.className}Service {
Integer
save
(${
table
.
className
}
Dto
${
table
.
classname
}
Dto
);
<#
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
);
...
...
src/main/resources/tpls/java_service.impl.ftl
View file @
d6a7578c
...
...
@@ -29,13 +29,13 @@ public class ${table.className}ServiceImpl implements ${table.className}Service{
<#
if
pk
??>
@
Override
public
Integer
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
return
${
table
.
classname
}
Dao
.
deleteBy
${
pk
.
attrName
}(${
pk
.
attrname
});
public
void
deleteBy
${
pk
.
attrName
}(${
pk
.
attrType
}
${
pk
.
attrname
}){
${
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
);
public
void
deleteBatchBy
${
pk
.
attrName
}
s
(
List
<${
pk
.
attrType
}>
${
pk
.
attrname
}
s
){
${
table
.
classname
}
Dao
.
deleteBatchBy
${
pk
.
attrName
}
s
(${
pk
.
attrname
}
s
);
}
@
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