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
fa5d5b6a
Commit
fa5d5b6a
authored
May 08, 2017
by
fsn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构模板
parent
1f2ca6dd
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
184 additions
and
99 deletions
+184
-99
src/main/baseResources/gunsTemplate/Controller.java.btl
+38
-37
src/main/java/com/stylefeng/guns/core/template/config/ContextConfig.java
+38
-0
src/main/java/com/stylefeng/guns/core/template/config/ControllerConfig.java
+11
-20
src/main/java/com/stylefeng/guns/core/template/engine/AbstractTemplateEngine.java
+33
-0
src/main/java/com/stylefeng/guns/core/template/engine/GunsEngine.java
+0
-42
src/main/java/com/stylefeng/guns/core/template/engine/GunsTemplateEngine.java
+64
-0
No files found.
src/main/baseResources/gunsTemplate/Controller.java.btl
View file @
fa5d5b6a
package
${
packageName
};
package
${
controller
.
packageName
};
@
for
(
import
in
imports
!){
<%
for
(
import
in
controller
.
imports
!){ %>
import
${
import
};
import
${
import
};
@}
<%
}
%>
/**
/**
*
${
bizChName
}
控制器
*
${
context
.
bizChName
}
控制器
*
*
*
\
@
author
fengshuonan
*
@
author
fengshuonan
*
\
@
Date
${
tool
.
currentTime
()}
*
@
Date
${
tool
.
currentTime
()}
*/
*/
\
@
Controller
@
Controller
\@
RequestMapping
(
"/${
bizEnName}"
)
@
RequestMapping
(
"/${context.
bizEnName}"
)
public
class
${
tool
.
firstLetterToUpper
(
bizEnName
)}
Controller
extends
BaseController
{
public
class
${
tool
.
firstLetterToUpper
(
context
.
bizEnName
)}
Controller
extends
BaseController
{
private
String
PREFIX
=
"/system/${bizEnName}/"
;
private
String
PREFIX
=
"/system/${
context.
bizEnName}/"
;
/**
/**
*
跳转到
${
bizChName
}
首页
*
跳转到
${
context
.
bizChName
}
首页
*/
*/
\
@
RequestMapping
(
""
)
@
RequestMapping
(
""
)
public
String
index
()
{
public
String
index
()
{
return
PREFIX
+
"${bizEnName}.html"
;
return
PREFIX
+
"${
context.
bizEnName}.html"
;
}
}
/**
/**
*
跳转到添加
${
bizChName
}
*
跳转到添加
${
context
.
bizChName
}
*/
*/
\@
RequestMapping
(
"/${
bizEnName}_add"
)
@
RequestMapping
(
"/${context.
bizEnName}_add"
)
public
String
${
bizEnName
}
Add
()
{
public
String
${
context
.
bizEnName
}
Add
()
{
return
PREFIX
+
"${bizEnName}_add.html"
;
return
PREFIX
+
"${
context.
bizEnName}_add.html"
;
}
}
/**
/**
*
跳转到修改
${
bizChName
}
*
跳转到修改
${
context
.
bizChName
}
*/
*/
\@
RequestMapping
(
"/${
bizEnName}_update"
)
@
RequestMapping
(
"/${context.
bizEnName}_update"
)
public
String
${
bizEnName
}
Update
()
{
public
String
${
context
.
bizEnName
}
Update
()
{
return
PREFIX
+
"${bizEnName}_edit.html"
;
return
PREFIX
+
"${
context.
bizEnName}_edit.html"
;
}
}
/**
/**
*
新增
${
bizChName
}
*
新增
${
context
.
bizChName
}
*/
*/
\
@
RequestMapping
(
value
=
"/add"
)
@
RequestMapping
(
value
=
"/add"
)
\
@
ResponseBody
@
ResponseBody
public
Object
add
()
{
public
Object
add
()
{
return
super
.
SUCCESS_TIP
;
return
super
.
SUCCESS_TIP
;
}
}
/**
/**
*
${
bizChName
}
详情
*
删除
${
context
.
bizChName
}
*/
*/
\@
RequestMapping
(
value
=
"/detail
"
)
@
RequestMapping
(
value
=
"/delete
"
)
\
@
ResponseBody
@
ResponseBody
public
Object
de
tail
()
{
public
Object
de
lete
()
{
return
null
;
return
SUCCESS_TIP
;
}
}
/**
/**
*
修改
${
bizChName
}
*
修改
${
context
.
bizChName
}
*/
*/
\
@
RequestMapping
(
value
=
"/update"
)
@
RequestMapping
(
value
=
"/update"
)
\
@
ResponseBody
@
ResponseBody
public
Object
update
()
{
public
Object
update
()
{
return
super
.
SUCCESS_TIP
;
return
super
.
SUCCESS_TIP
;
}
}
/**
/**
*
删除
${
bizChName
}
*
${
context
.
bizChName
}
详情
*/
*/
\@
RequestMapping
(
value
=
"/delete
"
)
@
RequestMapping
(
value
=
"/detail
"
)
\
@
ResponseBody
@
ResponseBody
public
Object
de
lete
()
{
public
Object
de
tail
()
{
return
SUCCESS_TIP
;
return
null
;
}
}
}
}
src/main/java/com/stylefeng/guns/core/template/config/ContextConfig.java
0 → 100644
View file @
fa5d5b6a
package
com
.
stylefeng
.
guns
.
core
.
template
.
config
;
/**
* 全局配置
*
* @author fengshuonan
* @date 2017-05-08 20:21
*/
public
class
ContextConfig
{
private
String
projectPath
=
"D:\\ideaSpace\\guns"
;
//模板输出的项目目录
private
String
bizChName
;
//业务名称
private
String
bizEnName
;
//业务英文名称
public
String
getBizChName
()
{
return
bizChName
;
}
public
void
setBizChName
(
String
bizChName
)
{
this
.
bizChName
=
bizChName
;
}
public
String
getBizEnName
()
{
return
bizEnName
;
}
public
void
setBizEnName
(
String
bizEnName
)
{
this
.
bizEnName
=
bizEnName
;
}
public
String
getProjectPath
()
{
return
projectPath
;
}
public
void
setProjectPath
(
String
projectPath
)
{
this
.
projectPath
=
projectPath
;
}
}
src/main/java/com/stylefeng/guns/core/template/config/ControllerConfig.java
View file @
fa5d5b6a
...
@@ -11,10 +11,9 @@ import java.util.List;
...
@@ -11,10 +11,9 @@ import java.util.List;
*/
*/
public
class
ControllerConfig
{
public
class
ControllerConfig
{
private
String
bizChName
;
private
String
controllerPathTemplate
=
"\\src\\main\\java\\com\\stylefeng\\guns\\modular\\system\\controller\\{}Controller.java"
;
private
String
bizEnName
;
private
String
packageName
;
//包名称
private
String
packageName
;
private
List
<
String
>
imports
;
//所引入的包
private
List
<
String
>
imports
;
public
ControllerConfig
(){
public
ControllerConfig
(){
init
();
init
();
...
@@ -30,22 +29,6 @@ public class ControllerConfig {
...
@@ -30,22 +29,6 @@ public class ControllerConfig {
this
.
packageName
=
"com.stylefeng.guns.modular.system.controller"
;
this
.
packageName
=
"com.stylefeng.guns.modular.system.controller"
;
}
}
public
String
getBizChName
()
{
return
bizChName
;
}
public
void
setBizChName
(
String
bizChName
)
{
this
.
bizChName
=
bizChName
;
}
public
String
getBizEnName
()
{
return
bizEnName
;
}
public
void
setBizEnName
(
String
bizEnName
)
{
this
.
bizEnName
=
bizEnName
;
}
public
String
getPackageName
()
{
public
String
getPackageName
()
{
return
packageName
;
return
packageName
;
}
}
...
@@ -61,4 +44,12 @@ public class ControllerConfig {
...
@@ -61,4 +44,12 @@ public class ControllerConfig {
public
void
setImports
(
List
<
String
>
imports
)
{
public
void
setImports
(
List
<
String
>
imports
)
{
this
.
imports
=
imports
;
this
.
imports
=
imports
;
}
}
public
String
getControllerPathTemplate
()
{
return
controllerPathTemplate
;
}
public
void
setControllerPathTemplate
(
String
controllerPathTemplate
)
{
this
.
controllerPathTemplate
=
controllerPathTemplate
;
}
}
}
src/main/java/com/stylefeng/guns/core/template/engine/AbstractTemplateEngine.java
0 → 100644
View file @
fa5d5b6a
package
com
.
stylefeng
.
guns
.
core
.
template
.
engine
;
import
com.stylefeng.guns.core.template.config.ContextConfig
;
import
com.stylefeng.guns.core.template.config.ControllerConfig
;
/**
* 模板生成父类
*
* @author fengshuonan
* @date 2017-05-08 20:17
*/
public
class
AbstractTemplateEngine
{
private
ContextConfig
contextConfig
=
new
ContextConfig
();
//全局配置
private
ControllerConfig
controllerConfig
=
new
ControllerConfig
();
//控制器的配置
public
ContextConfig
getContextConfig
()
{
return
contextConfig
;
}
public
void
setContextConfig
(
ContextConfig
contextConfig
)
{
this
.
contextConfig
=
contextConfig
;
}
public
ControllerConfig
getControllerConfig
()
{
return
controllerConfig
;
}
public
void
setControllerConfig
(
ControllerConfig
controllerConfig
)
{
this
.
controllerConfig
=
controllerConfig
;
}
}
src/main/java/com/stylefeng/guns/core/template/engine/GunsEngine.java
deleted
100644 → 0
View file @
1f2ca6dd
package
com
.
stylefeng
.
guns
.
core
.
template
.
engine
;
import
com.stylefeng.guns.core.support.BeanKit
;
import
com.stylefeng.guns.core.template.config.ControllerConfig
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
org.beetl.core.Configuration
;
import
org.beetl.core.GroupTemplate
;
import
org.beetl.core.Template
;
import
org.beetl.core.resource.ClasspathResourceLoader
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.Properties
;
/**
* guns项目模板生成 引擎
*
* @author fengshuonan
* @date 2017-05-07 22:15
*/
public
class
GunsEngine
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"RESOURCE.root"
,
""
);
ControllerConfig
controllerConfig
=
new
ControllerConfig
();
controllerConfig
.
setBizChName
(
"测试"
);
controllerConfig
.
setBizEnName
(
"test"
);
ClasspathResourceLoader
resourceLoader
=
new
ClasspathResourceLoader
();
Configuration
cfg
=
new
Configuration
(
properties
);
GroupTemplate
groupTemplate
=
new
GroupTemplate
(
resourceLoader
,
cfg
);
groupTemplate
.
registerFunctionPackage
(
"tool"
,
new
ToolUtil
());
Template
template
=
groupTemplate
.
getTemplate
(
"gunsTemplate/Controller.java.btl"
);
template
.
binding
(
BeanKit
.
beanToMap
(
controllerConfig
));
String
render
=
template
.
render
();
template
.
renderTo
(
new
FileOutputStream
(
"D:\\ideaSpace\\guns\\src\\main\\java\\com\\stylefeng\\guns\\modular\\system\\controller\\TestController.java"
));
System
.
out
.
println
(
render
);
}
}
src/main/java/com/stylefeng/guns/core/template/engine/GunsTemplateEngine.java
0 → 100644
View file @
fa5d5b6a
package
com
.
stylefeng
.
guns
.
core
.
template
.
engine
;
import
com.stylefeng.guns.core.template.config.ContextConfig
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
org.beetl.core.Configuration
;
import
org.beetl.core.GroupTemplate
;
import
org.beetl.core.Template
;
import
org.beetl.core.resource.ClasspathResourceLoader
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.Properties
;
/**
* guns项目模板生成 引擎
*
* @author fengshuonan
* @date 2017-05-07 22:15
*/
public
class
GunsTemplateEngine
extends
AbstractTemplateEngine
{
private
GroupTemplate
groupTemplate
;
public
GunsTemplateEngine
()
{
initBeetlEngine
();
}
public
void
initBeetlEngine
()
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"RESOURCE.root"
,
""
);
properties
.
put
(
"DELIMITER_STATEMENT_START"
,
"<%"
);
properties
.
put
(
"DELIMITER_STATEMENT_END"
,
"%>"
);
Configuration
cfg
=
null
;
try
{
cfg
=
new
Configuration
(
properties
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
ClasspathResourceLoader
resourceLoader
=
new
ClasspathResourceLoader
();
groupTemplate
=
new
GroupTemplate
(
resourceLoader
,
cfg
);
groupTemplate
.
registerFunctionPackage
(
"tool"
,
new
ToolUtil
());
}
public
void
start
()
throws
IOException
{
//初始化控制器模板
Template
template
=
groupTemplate
.
getTemplate
(
"gunsTemplate/Controller.java.btl"
);
template
.
binding
(
"controller"
,
super
.
getControllerConfig
());
template
.
binding
(
"context"
,
super
.
getContextConfig
());
String
format
=
ToolUtil
.
format
(
super
.
getContextConfig
().
getProjectPath
()
+
super
.
getControllerConfig
().
getControllerPathTemplate
(),
ToolUtil
.
firstLetterToUpper
(
super
.
getContextConfig
().
getBizEnName
()));
template
.
renderTo
(
new
FileOutputStream
(
format
));
System
.
out
.
println
(
"生成控制器成功!"
);
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
ContextConfig
contextConfig
=
new
ContextConfig
();
contextConfig
.
setBizChName
(
"测试"
);
contextConfig
.
setBizEnName
(
"test"
);
GunsTemplateEngine
gunsTemplateEngine
=
new
GunsTemplateEngine
();
gunsTemplateEngine
.
setContextConfig
(
contextConfig
);
gunsTemplateEngine
.
start
();
}
}
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