Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
renren-generator
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴迪
renren-generator
Commits
69698d27
Commit
69698d27
authored
Sep 13, 2017
by
WOSHINPC
Committed by
独孤求胜
Sep 13, 2017
Browse files
Options
Browse Files
Download
Plain Diff
!1 修复BigDecimal未导包问题,添加moduleName、mainPath配置
Merge pull request !1 from WOSHINPC/dev
parents
f1bbec38
4bdfca59
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
231 additions
and
223 deletions
+231
-223
GenUtils.java
src/main/java/io/renren/utils/GenUtils.java
+186
-180
generator.properties
src/main/resources/generator.properties
+3
-1
Controller.java.vm
src/main/resources/template/Controller.java.vm
+12
-12
Dao.java.vm
src/main/resources/template/Dao.java.vm
+3
-3
Dao.xml.vm
src/main/resources/template/Dao.xml.vm
+6
-6
Entity.java.vm
src/main/resources/template/Entity.java.vm
+1
-2
Service.java.vm
src/main/resources/template/Service.java.vm
+2
-2
ServiceImpl.java.vm
src/main/resources/template/ServiceImpl.java.vm
+4
-4
list.html.vm
src/main/resources/template/list.html.vm
+5
-4
list.js.vm
src/main/resources/template/list.js.vm
+4
-4
menu.sql.vm
src/main/resources/template/menu.sql.vm
+5
-5
No files found.
src/main/java/io/renren/utils/GenUtils.java
View file @
69698d27
...
@@ -21,192 +21,198 @@ import java.util.zip.ZipOutputStream;
...
@@ -21,192 +21,198 @@ import java.util.zip.ZipOutputStream;
/**
/**
* 代码生成器 工具类
* 代码生成器 工具类
*
*
* @author chenshun
* @author chenshun
* @email sunlightcs@gmail.com
* @email sunlightcs@gmail.com
* @date 2016年12月19日 下午11:40:24
* @date 2016年12月19日 下午11:40:24
*/
*/
public
class
GenUtils
{
public
class
GenUtils
{
public
static
List
<
String
>
getTemplates
(){
public
static
List
<
String
>
getTemplates
(){
List
<
String
>
templates
=
new
ArrayList
<
String
>();
List
<
String
>
templates
=
new
ArrayList
<
String
>();
templates
.
add
(
"template/Entity.java.vm"
);
templates
.
add
(
"template/Entity.java.vm"
);
templates
.
add
(
"template/Dao.java.vm"
);
templates
.
add
(
"template/Dao.java.vm"
);
templates
.
add
(
"template/Dao.xml.vm"
);
templates
.
add
(
"template/Dao.xml.vm"
);
templates
.
add
(
"template/Service.java.vm"
);
templates
.
add
(
"template/Service.java.vm"
);
templates
.
add
(
"template/ServiceImpl.java.vm"
);
templates
.
add
(
"template/ServiceImpl.java.vm"
);
templates
.
add
(
"template/Controller.java.vm"
);
templates
.
add
(
"template/Controller.java.vm"
);
templates
.
add
(
"template/list.html.vm"
);
templates
.
add
(
"template/list.html.vm"
);
templates
.
add
(
"template/list.js.vm"
);
templates
.
add
(
"template/list.js.vm"
);
templates
.
add
(
"template/menu.sql.vm"
);
templates
.
add
(
"template/menu.sql.vm"
);
return
templates
;
return
templates
;
}
}
/**
/**
* 生成代码
* 生成代码
*/
*/
public
static
void
generatorCode
(
Map
<
String
,
String
>
table
,
public
static
void
generatorCode
(
Map
<
String
,
String
>
table
,
List
<
Map
<
String
,
String
>>
columns
,
ZipOutputStream
zip
){
List
<
Map
<
String
,
String
>>
columns
,
ZipOutputStream
zip
)
{
//配置信息
//配置信息
Configuration
config
=
getConfig
();
Configuration
config
=
getConfig
();
boolean
hasBigDecimal
=
false
;
//表信息
//表信息
TableEntity
tableEntity
=
new
TableEntity
();
TableEntity
tableEntity
=
new
TableEntity
();
tableEntity
.
setTableName
(
table
.
get
(
"tableName"
));
tableEntity
.
setTableName
(
table
.
get
(
"tableName"
));
tableEntity
.
setComments
(
table
.
get
(
"tableComment"
));
tableEntity
.
setComments
(
table
.
get
(
"tableComment"
));
//表名转换成Java类名
//表名转换成Java类名
String
className
=
tableToJava
(
tableEntity
.
getTableName
(),
config
.
getString
(
"tablePrefix"
));
String
className
=
tableToJava
(
tableEntity
.
getTableName
(),
config
.
getString
(
"tablePrefix"
));
tableEntity
.
setClassName
(
className
);
tableEntity
.
setClassName
(
className
);
tableEntity
.
setClassname
(
StringUtils
.
uncapitalize
(
className
));
tableEntity
.
setClassname
(
StringUtils
.
uncapitalize
(
className
));
//列信息
//列信息
List
<
ColumnEntity
>
columsList
=
new
ArrayList
<>();
List
<
ColumnEntity
>
columsList
=
new
ArrayList
<>();
for
(
Map
<
String
,
String
>
column
:
columns
){
for
(
Map
<
String
,
String
>
column
:
columns
){
ColumnEntity
columnEntity
=
new
ColumnEntity
();
ColumnEntity
columnEntity
=
new
ColumnEntity
();
columnEntity
.
setColumnName
(
column
.
get
(
"columnName"
));
columnEntity
.
setColumnName
(
column
.
get
(
"columnName"
));
columnEntity
.
setDataType
(
column
.
get
(
"dataType"
));
columnEntity
.
setDataType
(
column
.
get
(
"dataType"
));
columnEntity
.
setComments
(
column
.
get
(
"columnComment"
));
columnEntity
.
setComments
(
column
.
get
(
"columnComment"
));
columnEntity
.
setExtra
(
column
.
get
(
"extra"
));
columnEntity
.
setExtra
(
column
.
get
(
"extra"
));
//列名转换成Java属性名
//列名转换成Java属性名
String
attrName
=
columnToJava
(
columnEntity
.
getColumnName
());
String
attrName
=
columnToJava
(
columnEntity
.
getColumnName
());
columnEntity
.
setAttrName
(
attrName
);
columnEntity
.
setAttrName
(
attrName
);
columnEntity
.
setAttrname
(
StringUtils
.
uncapitalize
(
attrName
));
columnEntity
.
setAttrname
(
StringUtils
.
uncapitalize
(
attrName
));
//列的数据类型,转换成Java类型
//列的数据类型,转换成Java类型
String
attrType
=
config
.
getString
(
columnEntity
.
getDataType
(),
"unknowType"
);
String
attrType
=
config
.
getString
(
columnEntity
.
getDataType
(),
"unknowType"
);
columnEntity
.
setAttrType
(
attrType
);
columnEntity
.
setAttrType
(
attrType
);
if
(!
hasBigDecimal
&&
attrType
.
equals
(
"BigDecimal"
))
{
//是否主键
hasBigDecimal
=
true
;
if
(
"PRI"
.
equalsIgnoreCase
(
column
.
get
(
"columnKey"
))
&&
tableEntity
.
getPk
()
==
null
){
}
tableEntity
.
setPk
(
columnEntity
);
//是否主键
}
if
(
"PRI"
.
equalsIgnoreCase
(
column
.
get
(
"columnKey"
))
&&
tableEntity
.
getPk
()
==
null
)
{
tableEntity
.
setPk
(
columnEntity
);
columsList
.
add
(
columnEntity
);
}
}
tableEntity
.
setColumns
(
columsList
);
columsList
.
add
(
columnEntity
);
}
//没主键,则第一个字段为主键
tableEntity
.
setColumns
(
columsList
);
if
(
tableEntity
.
getPk
()
==
null
){
tableEntity
.
setPk
(
tableEntity
.
getColumns
().
get
(
0
));
//没主键,则第一个字段为主键
}
if
(
tableEntity
.
getPk
()
==
null
)
{
tableEntity
.
setPk
(
tableEntity
.
getColumns
().
get
(
0
));
//设置velocity资源加载器
}
Properties
prop
=
new
Properties
();
prop
.
put
(
"file.resource.loader.class"
,
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"
);
//设置velocity资源加载器
Velocity
.
init
(
prop
);
Properties
prop
=
new
Properties
();
prop
.
put
(
"file.resource.loader.class"
,
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"
);
//封装模板数据
Velocity
.
init
(
prop
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
String
mainPath
=
config
.
getString
(
"mainPath"
);
map
.
put
(
"tableName"
,
tableEntity
.
getTableName
());
mainPath
=
StringUtils
.
isBlank
(
mainPath
)
?
"io.renren"
:
mainPath
;
map
.
put
(
"comments"
,
tableEntity
.
getComments
());
//封装模板数据
map
.
put
(
"pk"
,
tableEntity
.
getPk
());
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"className"
,
tableEntity
.
getClassName
());
map
.
put
(
"tableName"
,
tableEntity
.
getTableName
());
map
.
put
(
"classname"
,
tableEntity
.
getClassname
());
map
.
put
(
"comments"
,
tableEntity
.
getComments
());
map
.
put
(
"pathName"
,
tableEntity
.
getClassname
().
toLowerCase
());
map
.
put
(
"pk"
,
tableEntity
.
getPk
());
map
.
put
(
"columns"
,
tableEntity
.
getColumns
());
map
.
put
(
"className"
,
tableEntity
.
getClassName
());
map
.
put
(
"package"
,
config
.
getString
(
"package"
));
map
.
put
(
"classname"
,
tableEntity
.
getClassname
());
map
.
put
(
"author"
,
config
.
getString
(
"author"
));
map
.
put
(
"pathName"
,
tableEntity
.
getClassname
().
toLowerCase
());
map
.
put
(
"email"
,
config
.
getString
(
"email"
));
map
.
put
(
"columns"
,
tableEntity
.
getColumns
());
map
.
put
(
"datetime"
,
DateUtils
.
format
(
new
Date
(),
DateUtils
.
DATE_TIME_PATTERN
));
map
.
put
(
"hasBigDecimal"
,
hasBigDecimal
);
map
.
put
(
"mainPath"
,
mainPath
);
map
.
put
(
"package"
,
config
.
getString
(
"package"
));
map
.
put
(
"moduleName"
,
config
.
getString
(
"moduleName"
));
map
.
put
(
"author"
,
config
.
getString
(
"author"
));
map
.
put
(
"email"
,
config
.
getString
(
"email"
));
map
.
put
(
"datetime"
,
DateUtils
.
format
(
new
Date
(),
DateUtils
.
DATE_TIME_PATTERN
));
VelocityContext
context
=
new
VelocityContext
(
map
);
VelocityContext
context
=
new
VelocityContext
(
map
);
//获取模板列表
//获取模板列表
List
<
String
>
templates
=
getTemplates
();
List
<
String
>
templates
=
getTemplates
();
for
(
String
template
:
templates
)
{
for
(
String
template
:
templates
)
{
//渲染模板
//渲染模板
StringWriter
sw
=
new
StringWriter
();
StringWriter
sw
=
new
StringWriter
();
Template
tpl
=
Velocity
.
getTemplate
(
template
,
"UTF-8"
);
Template
tpl
=
Velocity
.
getTemplate
(
template
,
"UTF-8"
);
tpl
.
merge
(
context
,
sw
);
tpl
.
merge
(
context
,
sw
);
try
{
try
{
//添加到zip
//添加到zip
zip
.
putNextEntry
(
new
ZipEntry
(
getFileName
(
template
,
tableEntity
.
getClassName
(),
config
.
getString
(
"package"
))));
zip
.
putNextEntry
(
new
ZipEntry
(
getFileName
(
template
,
tableEntity
.
getClassName
(),
config
.
getString
(
"package"
),
config
.
getString
(
"moduleName"
))));
IOUtils
.
write
(
sw
.
toString
(),
zip
,
"UTF-8"
);
IOUtils
.
write
(
sw
.
toString
(),
zip
,
"UTF-8"
);
IOUtils
.
closeQuietly
(
sw
);
IOUtils
.
closeQuietly
(
sw
);
zip
.
closeEntry
();
zip
.
closeEntry
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
RRException
(
"渲染模板失败,表名:"
+
tableEntity
.
getTableName
(),
e
);
throw
new
RRException
(
"渲染模板失败,表名:"
+
tableEntity
.
getTableName
(),
e
);
}
}
}
}
}
}
/**
/**
* 列名转换成Java属性名
* 列名转换成Java属性名
*/
*/
public
static
String
columnToJava
(
String
columnName
)
{
public
static
String
columnToJava
(
String
columnName
)
{
return
WordUtils
.
capitalizeFully
(
columnName
,
new
char
[]{
'_'
}).
replace
(
"_"
,
""
);
return
WordUtils
.
capitalizeFully
(
columnName
,
new
char
[]{
'_'
}).
replace
(
"_"
,
""
);
}
}
/**
/**
* 表名转换成Java类名
* 表名转换成Java类名
*/
*/
public
static
String
tableToJava
(
String
tableName
,
String
tablePrefix
)
{
public
static
String
tableToJava
(
String
tableName
,
String
tablePrefix
)
{
if
(
StringUtils
.
isNotBlank
(
tablePrefix
))
{
if
(
StringUtils
.
isNotBlank
(
tablePrefix
))
{
tableName
=
tableName
.
replace
(
tablePrefix
,
""
);
tableName
=
tableName
.
replace
(
tablePrefix
,
""
);
}
}
return
columnToJava
(
tableName
);
return
columnToJava
(
tableName
);
}
}
/**
/**
* 获取配置信息
* 获取配置信息
*/
*/
public
static
Configuration
getConfig
()
{
public
static
Configuration
getConfig
()
{
try
{
try
{
return
new
PropertiesConfiguration
(
"generator.properties"
);
return
new
PropertiesConfiguration
(
"generator.properties"
);
}
catch
(
ConfigurationException
e
)
{
}
catch
(
ConfigurationException
e
)
{
throw
new
RRException
(
"获取配置文件失败,"
,
e
);
throw
new
RRException
(
"获取配置文件失败,"
,
e
);
}
}
}
}
/**
/**
* 获取文件名
* 获取文件名
*/
*/
public
static
String
getFileName
(
String
template
,
String
className
,
String
packageName
)
{
public
static
String
getFileName
(
String
template
,
String
className
,
String
packageName
,
String
moduleName
)
{
String
packagePath
=
"main"
+
File
.
separator
+
"java"
+
File
.
separator
;
String
packagePath
=
"main"
+
File
.
separator
+
"java"
+
File
.
separator
;
if
(
StringUtils
.
isNotBlank
(
packageName
))
{
if
(
StringUtils
.
isNotBlank
(
packageName
))
{
packagePath
+=
packageName
.
replace
(
"."
,
File
.
separator
)
+
File
.
separator
;
packagePath
+=
packageName
.
replace
(
"."
,
File
.
separator
)
+
File
.
separator
+
moduleName
+
File
.
separator
;
}
}
if
(
template
.
contains
(
"Entity.java.vm"
))
{
if
(
template
.
contains
(
"Entity.java.vm"
))
{
return
packagePath
+
"entity"
+
File
.
separator
+
className
+
"Entity.java"
;
return
packagePath
+
"entity"
+
File
.
separator
+
className
+
"Entity.java"
;
}
}
if
(
template
.
contains
(
"Dao.java.vm"
))
{
if
(
template
.
contains
(
"Dao.java.vm"
))
{
return
packagePath
+
"dao"
+
File
.
separator
+
className
+
"Dao.java"
;
return
packagePath
+
"dao"
+
File
.
separator
+
className
+
"Dao.java"
;
}
}
if
(
template
.
contains
(
"Service.java.vm"
))
{
if
(
template
.
contains
(
"Service.java.vm"
))
{
return
packagePath
+
"service"
+
File
.
separator
+
className
+
"Service.java"
;
return
packagePath
+
"service"
+
File
.
separator
+
className
+
"Service.java"
;
}
}
if
(
template
.
contains
(
"ServiceImpl.java.vm"
))
{
if
(
template
.
contains
(
"ServiceImpl.java.vm"
))
{
return
packagePath
+
"service"
+
File
.
separator
+
"impl"
+
File
.
separator
+
className
+
"ServiceImpl.java"
;
return
packagePath
+
"service"
+
File
.
separator
+
"impl"
+
File
.
separator
+
className
+
"ServiceImpl.java"
;
}
}
if
(
template
.
contains
(
"Controller.java.vm"
))
{
if
(
template
.
contains
(
"Controller.java.vm"
))
{
return
packagePath
+
"controller"
+
File
.
separator
+
className
+
"Controller.java"
;
return
packagePath
+
"controller"
+
File
.
separator
+
className
+
"Controller.java"
;
}
}
if
(
template
.
contains
(
"Dao.xml.vm"
))
{
if
(
template
.
contains
(
"Dao.xml.vm"
))
{
return
"main"
+
File
.
separator
+
"resources"
+
File
.
separator
+
"mapper"
+
File
.
separator
+
"generator"
+
File
.
separator
+
className
+
"Dao.xml"
;
return
"main"
+
File
.
separator
+
"resources"
+
File
.
separator
+
"mapper"
+
File
.
separator
+
moduleName
+
File
.
separator
+
className
+
"Dao.xml"
;
}
}
if
(
template
.
contains
(
"list.html.vm"
))
{
if
(
template
.
contains
(
"list.html.vm"
))
{
return
"main"
+
File
.
separator
+
"resources"
+
File
.
separator
+
"views"
+
File
.
separator
return
"main"
+
File
.
separator
+
"resources"
+
File
.
separator
+
"views"
+
File
.
separator
+
"modules"
+
File
.
separator
+
"generator"
+
File
.
separator
+
className
.
toLowerCase
()
+
".html"
;
+
"modules"
+
File
.
separator
+
moduleName
+
File
.
separator
+
className
.
toLowerCase
()
+
".html"
;
}
}
if
(
template
.
contains
(
"list.js.vm"
))
{
if
(
template
.
contains
(
"list.js.vm"
))
{
return
"main"
+
File
.
separator
+
"resources"
+
File
.
separator
+
"static"
+
File
.
separator
+
"js"
+
File
.
separator
return
"main"
+
File
.
separator
+
"resources"
+
File
.
separator
+
"static"
+
File
.
separator
+
"js"
+
File
.
separator
+
"modules"
+
File
.
separator
+
"generator"
+
File
.
separator
+
className
.
toLowerCase
()
+
".js"
;
+
"modules"
+
File
.
separator
+
moduleName
+
File
.
separator
+
className
.
toLowerCase
()
+
".js"
;
}
}
if
(
template
.
contains
(
"menu.sql.vm"
))
{
if
(
template
.
contains
(
"menu.sql.vm"
))
{
return
className
.
toLowerCase
()
+
"_menu.sql"
;
return
className
.
toLowerCase
()
+
"_menu.sql"
;
}
}
return
null
;
return
null
;
}
}
}
}
src/main/resources/generator.properties
View file @
69698d27
#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F
#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F
mainPath
=
io.renren
#\u5305\u540D
#\u5305\u540D
package
=
io.renren.modules.generator
package
=
io.renren.modules
moduleName
=
generator
#\u4F5C\u8005
#\u4F5C\u8005
author
=
chenshun
author
=
chenshun
#Email
#Email
...
...
src/main/resources/template/Controller.java.vm
View file @
69698d27
package
${
package
}.
controller
;
package
${
package
}.
${
moduleName
}.
controller
;
import
java
.
util
.
List
;
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
import
java
.
util
.
Map
;
...
@@ -11,11 +11,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -11,11 +11,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org
.
springframework
.
web
.
bind
.
annotation
.
RequestParam
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
RequestParam
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
RestController
;
import
org
.
springframework
.
web
.
bind
.
annotation
.
RestController
;
import
${
package
}.
entity
.${
className
}
Entity
;
import
${
package
}.
${
moduleName
}.
entity
.${
className
}
Entity
;
import
${
package
}.
service
.${
className
}
Service
;
import
${
package
}.
${
moduleName
}.
service
.${
className
}
Service
;
import
io
.
renren
.
common
.
utils
.
PageUtils
;
import
${
mainPath
}
.
common
.
utils
.
PageUtils
;
import
io
.
renren
.
common
.
utils
.
Query
;
import
${
mainPath
}
.
common
.
utils
.
Query
;
import
io
.
renren
.
common
.
utils
.
R
;
import
${
mainPath
}
.
common
.
utils
.
R
;
...
@@ -28,7 +28,7 @@ import io.renren.common.utils.R;
...
@@ -28,7 +28,7 @@ import io.renren.common.utils.R;
*
@
date
${
datetime
}
*
@
date
${
datetime
}
*/
*/
@
RestController
@
RestController
@
RequestMapping
(
"${pathName}"
)
@
RequestMapping
(
"
/${moduleName}/
${pathName}"
)
public
class
${
className
}
Controller
{
public
class
${
className
}
Controller
{
@
Autowired
@
Autowired
private
${
className
}
Service
${
classname
}
Service
;
private
${
className
}
Service
${
classname
}
Service
;
...
@@ -37,7 +37,7 @@ public class ${className}Controller {
...
@@ -37,7 +37,7 @@ public class ${className}Controller {
*
列表
*
列表
*/
*/
@
RequestMapping
(
"/list"
)
@
RequestMapping
(
"/list"
)
@
RequiresPermissions
(
"${pathName}:list"
)
@
RequiresPermissions
(
"${
moduleName}:${
pathName}:list"
)
public
R
list
(@
RequestParam
Map
<
String
,
Object
>
params
){
public
R
list
(@
RequestParam
Map
<
String
,
Object
>
params
){
//
查询列表数据
//
查询列表数据
Query
query
=
new
Query
(
params
);
Query
query
=
new
Query
(
params
);
...
@@ -55,7 +55,7 @@ public class ${className}Controller {
...
@@ -55,7 +55,7 @@ public class ${className}Controller {
*
信息
*
信息
*/
*/
@
RequestMapping
(
"/info/{${pk.attrname}}"
)
@
RequestMapping
(
"/info/{${pk.attrname}}"
)
@
RequiresPermissions
(
"${pathName}:info"
)
@
RequiresPermissions
(
"${
moduleName}:${
pathName}:info"
)
public
R
info
(@
PathVariable
(
"${pk.attrname}"
)
${
pk
.
attrType
}
${
pk
.
attrname
}){
public
R
info
(@
PathVariable
(
"${pk.attrname}"
)
${
pk
.
attrType
}
${
pk
.
attrname
}){
${
className
}
Entity
${
classname
}
=
${
classname
}
Service
.
queryObject
(${
pk
.
attrname
});
${
className
}
Entity
${
classname
}
=
${
classname
}
Service
.
queryObject
(${
pk
.
attrname
});
...
@@ -66,7 +66,7 @@ public class ${className}Controller {
...
@@ -66,7 +66,7 @@ public class ${className}Controller {
*
保存
*
保存
*/
*/
@
RequestMapping
(
"/save"
)
@
RequestMapping
(
"/save"
)
@
RequiresPermissions
(
"${pathName}:save"
)
@
RequiresPermissions
(
"${
moduleName}:${
pathName}:save"
)
public
R
save
(@
RequestBody
${
className
}
Entity
${
classname
}){
public
R
save
(@
RequestBody
${
className
}
Entity
${
classname
}){
${
classname
}
Service
.
save
(${
classname
});
${
classname
}
Service
.
save
(${
classname
});
...
@@ -77,7 +77,7 @@ public class ${className}Controller {
...
@@ -77,7 +77,7 @@ public class ${className}Controller {
*
修改
*
修改
*/
*/
@
RequestMapping
(
"/update"
)
@
RequestMapping
(
"/update"
)
@
RequiresPermissions
(
"${pathName}:update"
)
@
RequiresPermissions
(
"${
moduleName}:${
pathName}:update"
)
public
R
update
(@
RequestBody
${
className
}
Entity
${
classname
}){
public
R
update
(@
RequestBody
${
className
}
Entity
${
classname
}){
${
classname
}
Service
.
update
(${
classname
});
${
classname
}
Service
.
update
(${
classname
});
...
@@ -88,7 +88,7 @@ public class ${className}Controller {
...
@@ -88,7 +88,7 @@ public class ${className}Controller {
*
删除
*
删除
*/
*/
@
RequestMapping
(
"/delete"
)
@
RequestMapping
(
"/delete"
)
@
RequiresPermissions
(
"${pathName}:delete"
)
@
RequiresPermissions
(
"${
moduleName}:${
pathName}:delete"
)
public
R
delete
(@
RequestBody
${
pk
.
attrType
}[]
${
pk
.
attrname
}
s
){
public
R
delete
(@
RequestBody
${
pk
.
attrType
}[]
${
pk
.
attrname
}
s
){
${
classname
}
Service
.
deleteBatch
(${
pk
.
attrname
}
s
);
${
classname
}
Service
.
deleteBatch
(${
pk
.
attrname
}
s
);
...
...
src/main/resources/template/Dao.java.vm
View file @
69698d27
package
${
package
}.
dao
;
package
${
package
}.
${
moduleName
}.
dao
;
import
${
package
}.
entity
.${
className
}
Entity
;
import
${
package
}.
${
moduleName
}.
entity
.${
className
}
Entity
;
import
io
.
renren
.
modules
.
sys
.
dao
.
BaseDao
;
import
${
mainPath
}
.
modules
.
sys
.
dao
.
BaseDao
;
import
org
.
apache
.
ibatis
.
annotations
.
Mapper
;
import
org
.
apache
.
ibatis
.
annotations
.
Mapper
;
/**
/**
...
...
src/main/resources/template/Dao.xml.vm
View file @
69698d27
<?xml version="1.0" encoding="UTF-8"?>
<?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">
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"${package}.dao.${className}Dao"
>
<mapper
namespace=
"${package}.
${moduleName}.
dao.${className}Dao"
>
<!-- 可根据自己的需求,是否要使用 -->
<!-- 可根据自己的需求,是否要使用 -->
<resultMap
type=
"${package}.entity.${className}Entity"
id=
"${classname}Map"
>
<resultMap
type=
"${package}.
${moduleName}.
entity.${className}Entity"
id=
"${classname}Map"
>
#foreach($column in $columns)
#foreach($column in $columns)
<result
property=
"${column.attrname}"
column=
"${column.columnName}"
/>
<result
property=
"${column.attrname}"
column=
"${column.columnName}"
/>
#end
#end
</resultMap>
</resultMap>
<select
id=
"queryObject"
resultType=
"${package}.entity.${className}Entity"
>
<select
id=
"queryObject"
resultType=
"${package}.
${moduleName}.
entity.${className}Entity"
>
select * from ${tableName} where ${pk.columnName} = #{value}
select * from ${tableName} where ${pk.columnName} = #{value}
</select>
</select>
<select
id=
"queryList"
resultType=
"${package}.entity.${className}Entity"
>
<select
id=
"queryList"
resultType=
"${package}.
${moduleName}.
entity.${className}Entity"
>
select * from ${tableName}
select * from ${tableName}
<choose>
<choose>
<when
test=
"sidx != null and sidx.trim() != ''"
>
<when
test=
"sidx != null and sidx.trim() != ''"
>
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
select count(*) from ${tableName}
select count(*) from ${tableName}
</select>
</select>
<insert
id=
"save"
parameterType=
"${package}.entity.${className}Entity"
#if($
pk.extra =
=
'auto_increment')
useGeneratedKeys=
"true"
keyProperty=
"$pk.attrname"
#end
>
<insert
id=
"save"
parameterType=
"${package}.
${moduleName}.
entity.${className}Entity"
#if($
pk.extra =
=
'auto_increment')
useGeneratedKeys=
"true"
keyProperty=
"$pk.attrname"
#end
>
insert into ${tableName}
insert into ${tableName}
(
(
#foreach($column in $columns)
#foreach($column in $columns)
...
@@ -54,7 +54,7 @@
...
@@ -54,7 +54,7 @@
)
)
</insert>
</insert>
<update
id=
"update"
parameterType=
"${package}.entity.${className}Entity"
>
<update
id=
"update"
parameterType=
"${package}.
${moduleName}.
entity.${className}Entity"
>
update ${tableName}
update ${tableName}
<set>
<set>
#foreach($column in $columns)
#foreach($column in $columns)
...
...
src/main/resources/template/Entity.java.vm
View file @
69698d27
package
${
package
}.
entity
;
package
${
package
}.
${
moduleName
}.
entity
;
import
java
.
io
.
Serializable
;
import
java
.
io
.
Serializable
;
import
java
.
util
.
Date
;
import
java
.
util
.
Date
;
#
if
(${
hasBigDecimal
})
#
if
(${
hasBigDecimal
})
import
java
.
math
.
BigDecimal
;
import
java
.
math
.
BigDecimal
;
#
end
#
end
...
...
src/main/resources/template/Service.java.vm
View file @
69698d27
package
${
package
}.
service
;
package
${
package
}.
${
moduleName
}.
service
;
import
${
package
}.
entity
.${
className
}
Entity
;
import
${
package
}.
${
moduleName
}.
entity
.${
className
}
Entity
;
import
java
.
util
.
List
;
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
import
java
.
util
.
Map
;
...
...
src/main/resources/template/ServiceImpl.java.vm
View file @
69698d27
package
${
package
}.
service
.
impl
;
package
${
package
}.
${
moduleName
}.
service
.
impl
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
stereotype
.
Service
;
import
org
.
springframework
.
stereotype
.
Service
;
...
@@ -6,9 +6,9 @@ import org.springframework.stereotype.Service;
...
@@ -6,9 +6,9 @@ import org.springframework.stereotype.Service;
import
java
.
util
.
List
;
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
import
java
.
util
.
Map
;
import
${
package
}.
dao
.${
className
}
Dao
;
import
${
package
}.
${
moduleName
}.
dao
.${
className
}
Dao
;
import
${
package
}.
entity
.${
className
}
Entity
;
import
${
package
}.
${
moduleName
}.
entity
.${
className
}
Entity
;
import
${
package
}.
service
.${
className
}
Service
;
import
${
package
}.
${
moduleName
}.
service
.${
className
}
Service
;
...
...
src/main/resources/template/list.html.vm
View file @
69698d27
...
@@ -23,9 +23,9 @@
...
@@ -23,9 +23,9 @@
<div
id=
"rrapp"
v-cloak
>
<div
id=
"rrapp"
v-cloak
>
<div
v-show=
"showList"
>
<div
v-show=
"showList"
>
<div
class=
"grid-btn"
>
<div
class=
"grid-btn"
>
<a
v-if=
"hasPermission('${pathName}:save')"
class=
"btn btn-primary"
@
click=
"add"
><i
class=
"fa fa-plus"
></i>
新增
</a>
<a
v-if=
"hasPermission('${
moduleName}:${
pathName}:save')"
class=
"btn btn-primary"
@
click=
"add"
><i
class=
"fa fa-plus"
></i>
新增
</a>
<a
v-if=
"hasPermission('${pathName}:update')"
class=
"btn btn-primary"
@
click=
"update"
><i
class=
"fa fa-pencil-square-o"
></i>
修改
</a>
<a
v-if=
"hasPermission('${
moduleName}:${
pathName}:update')"
class=
"btn btn-primary"
@
click=
"update"
><i
class=
"fa fa-pencil-square-o"
></i>
修改
</a>
<a
v-if=
"hasPermission('${pathName}:delete')"
class=
"btn btn-primary"
@
click=
"del"
><i
class=
"fa fa-trash-o"
></i>
删除
</a>
<a
v-if=
"hasPermission('${
moduleName}:${
pathName}:delete')"
class=
"btn btn-primary"
@
click=
"del"
><i
class=
"fa fa-trash-o"
></i>
删除
</a>
</div>
</div>
<table
id=
"jqGrid"
></table>
<table
id=
"jqGrid"
></table>
<div
id=
"jqGridPager"
></div>
<div
id=
"jqGridPager"
></div>
...
@@ -53,6 +53,6 @@
...
@@ -53,6 +53,6 @@
</div>
</div>
</div>
</div>
<script
src=
"../../js/modules/
generator
/${pathName}.js"
></script>
<script
src=
"../../js/modules/
${moduleName}
/${pathName}.js"
></script>
</body>
</body>
</html>
</html>
\ No newline at end of file
src/main/resources/template/list.js.vm
View file @
69698d27
$(function () {
$(function () {
$("#jqGrid").jqGrid({
$("#jqGrid").jqGrid({
url: baseURL + '${pathName}/list',
url: baseURL + '${
moduleName}/${
pathName}/list',
datatype: "json",
datatype: "json",
colModel: [
colModel: [
#foreach($column in $columns)
#foreach($column in $columns)
...
@@ -66,7 +66,7 @@ var vm = new Vue({
...
@@ -66,7 +66,7 @@ var vm = new Vue({
vm.getInfo(${pk.attrname})
vm.getInfo(${pk.attrname})
},
},
saveOrUpdate: function (event) {
saveOrUpdate: function (event) {
var url = vm.${classname}.${pk.attrname} == null ? "${
pathName}/save" : "
${pathName}/update";
var url = vm.${classname}.${pk.attrname} == null ? "${
moduleName}/${pathName}/save" : "${moduleName}/
${pathName}/update";
$.ajax({
$.ajax({
type: "POST",
type: "POST",
url: baseURL + url,
url: baseURL + url,
...
@@ -92,7 +92,7 @@ var vm = new Vue({
...
@@ -92,7 +92,7 @@ var vm = new Vue({
confirm('确定要删除选中的记录?', function(){
confirm('确定要删除选中的记录?', function(){
$.ajax({
$.ajax({
type: "POST",
type: "POST",
url: baseURL + "${pathName}/delete",
url: baseURL + "${
moduleName}/${
pathName}/delete",
contentType: "application/json",
contentType: "application/json",
data: JSON.stringify(${pk.attrname}s),
data: JSON.stringify(${pk.attrname}s),
success: function(r){
success: function(r){
...
@@ -108,7 +108,7 @@ var vm = new Vue({
...
@@ -108,7 +108,7 @@ var vm = new Vue({
});
});
},
},
getInfo: function(${pk.attrname}){
getInfo: function(${pk.attrname}){
$.get(baseURL + "${pathName}/info/"+${pk.attrname}, function(r){
$.get(baseURL + "${
moduleName}/${
pathName}/info/"+${pk.attrname}, function(r){
vm.${classname} = r.${classname};
vm.${classname} = r.${classname};
});
});
},
},
...
...
src/main/resources/template/menu.sql.vm
View file @
69698d27
-- 菜单SQL
-- 菜单SQL
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
VALUES ('1', '${comments}', 'modules/
generator
/${pathName}.html', NULL, '1', 'fa fa-file-code-o', '6');
VALUES ('1', '${comments}', 'modules/
${moduleName}
/${pathName}.html', NULL, '1', 'fa fa-file-code-o', '6');
-- 按钮父菜单ID
-- 按钮父菜单ID
set @parentId = @@identity;
set @parentId = @@identity;
-- 菜单对应按钮SQL
-- 菜单对应按钮SQL
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
SELECT @parentId, '查看', null, '${pathName}:list,${pathName}:info', '2', null, '6';
SELECT @parentId, '查看', null, '${
moduleName}:${
pathName}:list,${pathName}:info', '2', null, '6';
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
SELECT @parentId, '新增', null, '${pathName}:save', '2', null, '6';
SELECT @parentId, '新增', null, '${
moduleName}:${
pathName}:save', '2', null, '6';
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
SELECT @parentId, '修改', null, '${pathName}:update', '2', null, '6';
SELECT @parentId, '修改', null, '${
moduleName}:${
pathName}:update', '2', null, '6';
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
SELECT @parentId, '删除', null, '${pathName}:delete', '2', null, '6';
SELECT @parentId, '删除', null, '${
moduleName}:${
pathName}:delete', '2', null, '6';
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