Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
c0da9046
Commit
c0da9046
authored
Jun 08, 2017
by
naan1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Guns模板生成器新增Dao和Service生成
parent
5c20c7dd
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
343 additions
and
9 deletions
+343
-9
src/main/java/com/stylefeng/guns/core/template/config/ContextConfig.java
+82
-0
src/main/java/com/stylefeng/guns/core/template/config/DaoConfig.java
+39
-0
src/main/java/com/stylefeng/guns/core/template/config/PageConfig.java
+1
-1
src/main/java/com/stylefeng/guns/core/template/config/ServiceConfig.java
+75
-0
src/main/java/com/stylefeng/guns/core/template/engine/SimpleTemplateEngine.java
+26
-0
src/main/java/com/stylefeng/guns/core/template/engine/base/AbstractTemplateEngine.java
+40
-6
src/main/java/com/stylefeng/guns/core/template/engine/base/GunsTemplateEngine.java
+29
-0
src/main/resources/gunsTemplate/Dao.java.btl
+12
-0
src/main/resources/gunsTemplate/Mapping.xml.btl
+6
-0
src/main/resources/gunsTemplate/Service.java.btl
+11
-0
src/main/resources/gunsTemplate/ServiceImpl.java.btl
+17
-0
src/test/java/com/stylefeng/guns/template/TemplateGenerator.java
+5
-2
No files found.
src/main/java/com/stylefeng/guns/core/template/config/ContextConfig.java
View file @
c0da9046
...
...
@@ -14,6 +14,16 @@ public class ContextConfig {
private
String
bizChName
;
//业务名称
private
String
bizEnName
;
//业务英文名称
private
String
bizEnBigName
;
//业务英文名称(大写)
private
String
moduleName
;
//模块名称
private
Boolean
controllerSwitch
=
true
;
//是否生成控制器代码开关
private
Boolean
indexPageSwitch
=
true
;
//主页
private
Boolean
addPageSwitch
=
true
;
//添加页面
private
Boolean
editPageSwitch
=
true
;
//编辑页面
private
Boolean
jsSwitch
=
true
;
//js
private
Boolean
infoJsSwitch
=
true
;
//详情页面js
private
Boolean
daoSwitch
=
true
;
//dao
private
Boolean
serviceSwitch
=
true
;
//service
public
String
getBizEnBigName
()
{
return
bizEnBigName
;
...
...
@@ -47,4 +57,76 @@ public class ContextConfig {
public
void
setProjectPath
(
String
projectPath
)
{
this
.
projectPath
=
projectPath
;
}
public
String
getModuleName
()
{
return
moduleName
;
}
public
void
setModuleName
(
String
moduleName
)
{
this
.
moduleName
=
moduleName
;
}
public
Boolean
getControllerSwitch
()
{
return
controllerSwitch
;
}
public
void
setControllerSwitch
(
Boolean
controllerSwitch
)
{
this
.
controllerSwitch
=
controllerSwitch
;
}
public
Boolean
getIndexPageSwitch
()
{
return
indexPageSwitch
;
}
public
void
setIndexPageSwitch
(
Boolean
indexPageSwitch
)
{
this
.
indexPageSwitch
=
indexPageSwitch
;
}
public
Boolean
getAddPageSwitch
()
{
return
addPageSwitch
;
}
public
void
setAddPageSwitch
(
Boolean
addPageSwitch
)
{
this
.
addPageSwitch
=
addPageSwitch
;
}
public
Boolean
getEditPageSwitch
()
{
return
editPageSwitch
;
}
public
void
setEditPageSwitch
(
Boolean
editPageSwitch
)
{
this
.
editPageSwitch
=
editPageSwitch
;
}
public
Boolean
getJsSwitch
()
{
return
jsSwitch
;
}
public
void
setJsSwitch
(
Boolean
jsSwitch
)
{
this
.
jsSwitch
=
jsSwitch
;
}
public
Boolean
getInfoJsSwitch
()
{
return
infoJsSwitch
;
}
public
void
setInfoJsSwitch
(
Boolean
infoJsSwitch
)
{
this
.
infoJsSwitch
=
infoJsSwitch
;
}
public
Boolean
getDaoSwitch
()
{
return
daoSwitch
;
}
public
void
setDaoSwitch
(
Boolean
daoSwitch
)
{
this
.
daoSwitch
=
daoSwitch
;
}
public
Boolean
getServiceSwitch
()
{
return
serviceSwitch
;
}
public
void
setServiceSwitch
(
Boolean
serviceSwitch
)
{
this
.
serviceSwitch
=
serviceSwitch
;
}
}
src/main/java/com/stylefeng/guns/core/template/config/DaoConfig.java
0 → 100644
View file @
c0da9046
package
com
.
stylefeng
.
guns
.
core
.
template
.
config
;
/**
* Dao模板生成的配置
*
* @author fengshuonan
* @date 2017-05-07 22:12
*/
public
class
DaoConfig
{
private
String
daoPathTemplate
=
"\\src\\main\\java\\com\\stylefeng\\guns\\modular\\system\\dao\\{}Dao.java"
;
private
String
xmlPathTemplate
=
"\\src\\main\\java\\com\\stylefeng\\guns\\modular\\system\\dao\\mapping\\{}Dao.xml"
;
private
String
packageName
=
"com.stylefeng.guns.modular.system.dao"
;
public
String
getPackageName
()
{
return
packageName
;
}
public
void
setPackageName
(
String
packageName
)
{
this
.
packageName
=
packageName
;
}
public
String
getDaoPathTemplate
()
{
return
daoPathTemplate
;
}
public
void
setDaoPathTemplate
(
String
daoPathTemplate
)
{
this
.
daoPathTemplate
=
daoPathTemplate
;
}
public
String
getXmlPathTemplate
()
{
return
xmlPathTemplate
;
}
public
void
setXmlPathTemplate
(
String
xmlPathTemplate
)
{
this
.
xmlPathTemplate
=
xmlPathTemplate
;
}
}
src/main/java/com/stylefeng/guns/core/template/config/PageConfig.java
View file @
c0da9046
package
com
.
stylefeng
.
guns
.
core
.
template
.
config
;
/**
*
控制器
模板生成的配置
*
页面
模板生成的配置
*
* @author fengshuonan
* @date 2017-05-07 22:12
...
...
src/main/java/com/stylefeng/guns/core/template/config/ServiceConfig.java
0 → 100644
View file @
c0da9046
package
com
.
stylefeng
.
guns
.
core
.
template
.
config
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Service模板生成的配置
*
* @author fengshuonan
* @date 2017-05-07 22:12
*/
public
class
ServiceConfig
{
private
ContextConfig
contextConfig
;
private
String
servicePathTemplate
=
"\\src\\main\\java\\com\\stylefeng\\guns\\modular\\system\\service\\I{}Service.java"
;
private
String
serviceImplPathTemplate
=
"\\src\\main\\java\\com\\stylefeng\\guns\\modular\\system\\service\\impl\\{}ServiceImpl.java"
;
private
String
packageName
=
"com.stylefeng.guns.modular.system.service"
;
private
List
<
String
>
serviceImplImports
;
public
ServiceConfig
(
ContextConfig
contextConfig
)
{
this
.
contextConfig
=
contextConfig
;
init
();
}
private
void
init
()
{
ArrayList
<
String
>
imports
=
new
ArrayList
<>();
imports
.
add
(
"org.springframework.stereotype.Service"
);
imports
.
add
(
"com.stylefeng.guns.modular.system.service.I"
+
contextConfig
.
getBizEnBigName
()
+
"Service"
);
this
.
serviceImplImports
=
imports
;
}
public
String
getServicePathTemplate
()
{
return
servicePathTemplate
;
}
public
void
setServicePathTemplate
(
String
servicePathTemplate
)
{
this
.
servicePathTemplate
=
servicePathTemplate
;
}
public
String
getPackageName
()
{
return
packageName
;
}
public
void
setPackageName
(
String
packageName
)
{
this
.
packageName
=
packageName
;
}
public
String
getServiceImplPathTemplate
()
{
return
serviceImplPathTemplate
;
}
public
void
setServiceImplPathTemplate
(
String
serviceImplPathTemplate
)
{
this
.
serviceImplPathTemplate
=
serviceImplPathTemplate
;
}
public
List
<
String
>
getServiceImplImports
()
{
return
serviceImplImports
;
}
public
void
setServiceImplImports
(
List
<
String
>
serviceImplImports
)
{
this
.
serviceImplImports
=
serviceImplImports
;
}
public
ContextConfig
getContextConfig
()
{
return
contextConfig
;
}
public
void
setContextConfig
(
ContextConfig
contextConfig
)
{
this
.
contextConfig
=
contextConfig
;
}
}
src/main/java/com/stylefeng/guns/core/template/engine/SimpleTemplateEngine.java
View file @
c0da9046
...
...
@@ -58,4 +58,30 @@ public class SimpleTemplateEngine extends GunsTemplateEngine {
generateFile
(
"gunsTemplate/Controller.java.btl"
,
controllerPath
);
System
.
out
.
println
(
"生成控制器成功!"
);
}
@Override
protected
void
generateDao
()
{
String
daoPath
=
ToolUtil
.
format
(
super
.
getContextConfig
().
getProjectPath
()
+
super
.
getDaoConfig
().
getDaoPathTemplate
(),
ToolUtil
.
firstLetterToUpper
(
super
.
getContextConfig
().
getBizEnName
()));
generateFile
(
"gunsTemplate/Dao.java.btl"
,
daoPath
);
System
.
out
.
println
(
"生成Dao成功!"
);
String
mappingPath
=
ToolUtil
.
format
(
super
.
getContextConfig
().
getProjectPath
()
+
super
.
getDaoConfig
().
getXmlPathTemplate
(),
ToolUtil
.
firstLetterToUpper
(
super
.
getContextConfig
().
getBizEnName
()));
generateFile
(
"gunsTemplate/Mapping.xml.btl"
,
mappingPath
);
System
.
out
.
println
(
"生成Dao Mapping xml成功!"
);
}
@Override
protected
void
generateService
()
{
String
servicePath
=
ToolUtil
.
format
(
super
.
getContextConfig
().
getProjectPath
()
+
super
.
getServiceConfig
().
getServicePathTemplate
(),
ToolUtil
.
firstLetterToUpper
(
super
.
getContextConfig
().
getBizEnName
()));
generateFile
(
"gunsTemplate/Service.java.btl"
,
servicePath
);
System
.
out
.
println
(
"生成Service成功!"
);
String
serviceImplPath
=
ToolUtil
.
format
(
super
.
getContextConfig
().
getProjectPath
()
+
super
.
getServiceConfig
().
getServiceImplPathTemplate
(),
ToolUtil
.
firstLetterToUpper
(
super
.
getContextConfig
().
getBizEnName
()));
generateFile
(
"gunsTemplate/ServiceImpl.java.btl"
,
serviceImplPath
);
System
.
out
.
println
(
"生成ServiceImpl成功!"
);
}
}
src/main/java/com/stylefeng/guns/core/template/engine/base/AbstractTemplateEngine.java
View file @
c0da9046
package
com
.
stylefeng
.
guns
.
core
.
template
.
engine
.
base
;
import
com.stylefeng.guns.core.template.config.ContextConfig
;
import
com.stylefeng.guns.core.template.config.ControllerConfig
;
import
com.stylefeng.guns.core.template.config.PageConfig
;
import
com.stylefeng.guns.core.template.config.*
;
/**
* 模板生成父类
...
...
@@ -12,9 +10,29 @@ import com.stylefeng.guns.core.template.config.PageConfig;
*/
public
class
AbstractTemplateEngine
{
private
ContextConfig
contextConfig
=
new
ContextConfig
();
//全局配置
private
ControllerConfig
controllerConfig
=
new
ControllerConfig
();
//控制器的配置
private
PageConfig
pageConfig
=
new
PageConfig
();
//页面的控制器
protected
ContextConfig
contextConfig
;
//全局配置
protected
ControllerConfig
controllerConfig
;
//控制器的配置
protected
PageConfig
pageConfig
;
//页面的控制器
protected
DaoConfig
daoConfig
;
//Dao配置
protected
ServiceConfig
serviceConfig
;
//Service配置
public
void
initConfig
()
{
if
(
this
.
contextConfig
==
null
)
{
contextConfig
=
new
ContextConfig
();
}
if
(
this
.
controllerConfig
==
null
)
{
controllerConfig
=
new
ControllerConfig
();
}
if
(
this
.
pageConfig
==
null
)
{
pageConfig
=
new
PageConfig
();
}
if
(
this
.
daoConfig
==
null
)
{
daoConfig
=
new
DaoConfig
();
}
if
(
this
.
serviceConfig
==
null
)
{
serviceConfig
=
new
ServiceConfig
(
contextConfig
);
}
}
public
PageConfig
getPageConfig
()
{
return
pageConfig
;
...
...
@@ -39,5 +57,21 @@ public class AbstractTemplateEngine {
public
void
setControllerConfig
(
ControllerConfig
controllerConfig
)
{
this
.
controllerConfig
=
controllerConfig
;
}
public
DaoConfig
getDaoConfig
()
{
return
daoConfig
;
}
public
void
setDaoConfig
(
DaoConfig
daoConfig
)
{
this
.
daoConfig
=
daoConfig
;
}
public
ServiceConfig
getServiceConfig
()
{
return
serviceConfig
;
}
public
void
setServiceConfig
(
ServiceConfig
serviceConfig
)
{
this
.
serviceConfig
=
serviceConfig
;
}
}
src/main/java/com/stylefeng/guns/core/template/engine/base/GunsTemplateEngine.java
View file @
c0da9046
...
...
@@ -46,6 +46,8 @@ public abstract class GunsTemplateEngine extends AbstractTemplateEngine {
public
void
configTemplate
(
Template
template
){
template
.
binding
(
"controller"
,
super
.
getControllerConfig
());
template
.
binding
(
"context"
,
super
.
getContextConfig
());
template
.
binding
(
"dao"
,
super
.
getDaoConfig
());
template
.
binding
(
"service"
,
super
.
getServiceConfig
());
}
public
void
generateFile
(
String
template
,
String
filePath
){
...
...
@@ -64,13 +66,36 @@ public abstract class GunsTemplateEngine extends AbstractTemplateEngine {
}
public
void
start
()
{
//配置之间的相互依赖
super
.
initConfig
();
//生成模板
if
(
super
.
contextConfig
.
getControllerSwitch
()){
generateController
();
}
if
(
super
.
contextConfig
.
getIndexPageSwitch
()){
generatePageHtml
();
}
if
(
super
.
contextConfig
.
getAddPageSwitch
()){
generatePageAddHtml
();
}
if
(
super
.
contextConfig
.
getEditPageSwitch
()){
generatePageEditHtml
();
}
if
(
super
.
contextConfig
.
getJsSwitch
()){
generatePageJs
();
}
if
(
super
.
contextConfig
.
getInfoJsSwitch
()){
generatePageInfoJs
();
}
if
(
super
.
contextConfig
.
getDaoSwitch
()){
generateDao
();
}
if
(
super
.
contextConfig
.
getServiceSwitch
()){
generateService
();
}
}
protected
abstract
void
generatePageEditHtml
();
...
...
@@ -84,4 +109,8 @@ public abstract class GunsTemplateEngine extends AbstractTemplateEngine {
protected
abstract
void
generateController
();
protected
abstract
void
generateDao
();
protected
abstract
void
generateService
();
}
src/main/resources/gunsTemplate/Dao.java.btl
0 → 100644
View file @
c0da9046
package
${
dao
.
packageName
};
/**
*
${
context
.
bizChName
}
Dao
*
*
@
author
fengshuonan
*
@
Date
${
tool
.
currentTime
()}
*/
public
interface
${
context
.
bizEnBigName
}
Dao
{
}
src/main/resources/gunsTemplate/Mapping.xml.btl
0 → 100644
View file @
c0da9046
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"${dao.packageName}.${context.bizEnBigName}Dao"
>
</mapper>
\ No newline at end of file
src/main/resources/gunsTemplate/Service.java.btl
0 → 100644
View file @
c0da9046
package
${
service
.
packageName
};
/**
*
${
context
.
bizChName
}
Service
*
*
@
author
fengshuonan
*
@
Date
${
tool
.
currentTime
()}
*/
public
interface
I
${
context
.
bizEnBigName
}
Service
{
}
src/main/resources/gunsTemplate/ServiceImpl.java.btl
0 → 100644
View file @
c0da9046
package
${
service
.
packageName
}.
impl
;
<%
for
(
import
in
service
.
serviceImplImports
!){ %>
import
${
import
};
<%
}
%>
/**
*
${
context
.
bizChName
}
Dao
*
*
@
author
fengshuonan
*
@
Date
${
tool
.
currentTime
()}
*/
@
Service
public
class
${
context
.
bizEnBigName
}
ServiceImpl
implements
I
${
context
.
bizEnBigName
}
Service
{
}
src/test/java/com/stylefeng/guns/template/TemplateGenerator.java
View file @
c0da9046
...
...
@@ -16,8 +16,11 @@ public class TemplateGenerator {
public
static
void
main
(
String
[]
args
)
throws
IOException
{
ContextConfig
contextConfig
=
new
ContextConfig
();
contextConfig
.
setBizChName
(
"代码生成"
);
contextConfig
.
setBizEnName
(
"code"
);
contextConfig
.
setBizChName
(
"啊哈"
);
contextConfig
.
setBizEnName
(
"haha"
);
contextConfig
.
setAddPageSwitch
(
false
);
contextConfig
.
setEditPageSwitch
(
false
);
GunsTemplateEngine
gunsTemplateEngine
=
new
SimpleTemplateEngine
();
gunsTemplateEngine
.
setContextConfig
(
contextConfig
);
...
...
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