image
image-20220905132558698

entity

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
##导入宏定义
$!define

$!prefix

##保存文件(宏定义)
#save("/entity${prefixPathPipe}", "Entity.java")

##包路径(宏定义)
#setPackageSuffix("entity${prefixPathDot}")

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end

##自动导入包(全局变量)
$!autoImport
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.baomidou.mybatisplus.annotation.*;

##表注释(宏定义)
#tableComment("表实体类")
@Data
@ApiModel(value = "#if(${tableInfo.comment})${tableInfo.comment}#end")
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("${tableInfo.obj.name}")
public class $!{tableInfo.name}Entity extends Model<$!{tableInfo.name}Entity> {

private static final long serialVersionUID = $tool.serial();

#foreach($column in $tableInfo.fullColumn)
#if($pk.name == $!{column.name})@TableId(value = "$pk.obj.name", type = IdType.AUTO)#end

@ApiModelProperty(value = "#if(${column.comment})${column.comment}#end")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}

dao

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
##导入宏定义
$!define

$!prefix

##设置表后缀(宏定义)
#setTableSuffix("Dao")

##保存文件(宏定义)
#save("/dao${prefixPathPipe}", "Dao.java")

##包路径(宏定义)
#setPackageSuffix("dao${prefixPathDot}")

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import $!{tableInfo.savePackageName}.entity${prefixPathDot}.$!{tableInfo.name}Entity;
import org.mapstruct.Mapper;

##表注释(宏定义)
#tableComment("表数据库访问层")
@Mapper
public interface $!{tableName} extends BaseMapper<$!{tableInfo.name}Entity> {

}

service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
##导入宏定义
$!define

$!prefix

##设置表后缀(宏定义)
#setTableSuffix("Service")

##保存文件(宏定义)
#save("/service${prefixPathPipe}", "Service.java")

##包路径(宏定义)
#setPackageSuffix("service${prefixPathDot}")

import com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.entity${prefixPathDot}.$!{tableInfo.name}Entity;

##表注释(宏定义)
#tableComment("表服务接口")
public interface $!{tableName} extends IService<$!{tableInfo.name}Entity> {

}

serviceImpl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
##导入宏定义
$!define

$!prefix

##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")

##保存文件(宏定义)
#save("/service${prefixPathPipe}/impl", "ServiceImpl.java")

##包路径(宏定义)
#setPackageSuffix("service${prefixPathDot}.impl")

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import $!{tableInfo.savePackageName}.dao${prefixPathDot}.$!{tableInfo.name}Dao;
import $!{tableInfo.savePackageName}.entity${prefixPathDot}.$!{tableInfo.name}Entity;
import $!{tableInfo.savePackageName}.service${prefixPathDot}.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import lombok.AllArgsConstructor;

##表注释(宏定义)
#tableComment("表服务实现类")
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
@AllArgsConstructor
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Dao, $!{tableInfo.name}Entity> implements $!{tableInfo.name}Service {

}

controller

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
$!define

$!prefix

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller${prefixPathPipe}"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller${prefixPathDot};

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import $!{tableInfo.savePackageName}.common.utils.R;
import $!{tableInfo.savePackageName}.common.log.annotation.SysLog;
import $!{tableInfo.savePackageName}.entity${prefixPathDot}.$!{tableInfo.name}Entity;
import $!{tableInfo.savePackageName}.service${prefixPathDot}.$!{tableInfo.name}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

#tableComment("表控制层")
@ApiIgnore
@RestController
@AllArgsConstructor
@RequestMapping("/#if($tableApi)$tableApi#else$!tool.firstLowerCase($tableInfo.name)#end")
@Api(value = "$!tool.firstLowerCase($tableInfo.name)", tags = "#if(${tableInfo.comment})${tableInfo.comment}#end 管理")
public class $!{tableName} {

/**
* 服务对象
*/
private final $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;

/**
* 分页查询
* @param page 分页对象
* @param $!{tool.firstLowerCase($tableInfo.name)}Entity #if(${tableInfo.comment})${tableInfo.comment}#end

* @return R
*/
@ApiOperation(value = "分页查询", notes = "分页查询")
@GetMapping("/page" )
@RequiresPermissions("${tableAuth}:list")
public R get$!{tableInfo.name}Page(Page page, $!{tableInfo.name}Entity $!{tool.firstLowerCase($tableInfo.name)}Entity) {
return R.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.page(page, Wrappers.query($!{tool.firstLowerCase($tableInfo.name)}Entity)));
}


/**
* 通过id查询 #if(${tableInfo.comment})${tableInfo.comment}#end

* @param $pk.name $pk.comment
* @return R
*/
@ApiOperation(value = "通过id查询", notes = "通过id查询")
@GetMapping("/{$pk.name}" )
@RequiresPermissions("${tableAuth}:info")
public R getById(@PathVariable("$pk.name") $!pk.shortType $pk.name) {
return R.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.getById($pk.name));
}

/**
* 新增 #if(${tableInfo.comment})${tableInfo.comment}#end

* @param $!{tool.firstLowerCase($tableInfo.name)}Entity #if(${tableInfo.comment})${tableInfo.comment}#end

* @return R
*/
@ApiOperation(value = "新增#if(${tableInfo.comment})${tableInfo.comment}#end", notes = "新增#if(${tableInfo.comment})${tableInfo.comment}#end")
@SysLog("新增#if(${tableInfo.comment})${tableInfo.comment}#end" )
@PostMapping
@RequiresPermissions("${tableAuth}:save")
public R save(@RequestBody $!{tableInfo.name}Entity $!{tool.firstLowerCase($tableInfo.name)}Entity) {
return R.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.save($!{tool.firstLowerCase($tableInfo.name)}Entity));
}

/**
* 修改#if(${tableInfo.comment})${tableInfo.comment}#end

* @param $!{tool.firstLowerCase($tableInfo.name)}Entity #if(${tableInfo.comment})${tableInfo.comment}#end

* @return R
*/
@RequiresPermissions("${tableAuth}:update")
@ApiOperation(value = "修改#if(${tableInfo.comment})${tableInfo.comment}#end", notes = "修改#if(${tableInfo.comment})${tableInfo.comment}#end")
@SysLog("修改#if(${tableInfo.comment})${tableInfo.comment}#end" )
@PutMapping
public R updateById(@RequestBody $!{tableInfo.name}Entity $!{tool.firstLowerCase($tableInfo.name)}Entity) {
return R.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.updateById($!{tool.firstLowerCase($tableInfo.name)}Entity));
}

/**
* 通过$pk.name 删除#if(${tableInfo.comment})${tableInfo.comment}#end

* @param $pk.name $pk.comment
* @return R
*/
@RequiresPermissions("${tableAuth}:delete")
@ApiOperation(value = "通过$pk.name 删除#if(${tableInfo.comment})${tableInfo.comment}#end", notes = "通过$pk.name 删除#if(${tableInfo.comment})${tableInfo.comment}#end")
@SysLog("通过id删除#if(${tableInfo.comment})${tableInfo.comment}#end" )
@DeleteMapping("/{$pk.name}" )
public R removeById(@PathVariable("$pk.name") $!pk.shortType $pk.name) {
return R.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.removeById($pk.name));
}

}

mapper.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
##引入mybatis支持
$!mybatisSupport

$!prefix

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper${prefixPathPipe}"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end

<?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="$!{tableInfo.savePackageName}.dao${prefixPathDot}.$!{tableInfo.name}Dao">

<resultMap type="$!{tableInfo.savePackageName}.entity${prefixPathDot}.$!{tableInfo.name}Entity" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
<result property="$!column.name" column="$!column.obj.name"/>
#end
</resultMap>

<sql id="baseColumn">
#foreach($column in $tableInfo.fullColumn)
$!column.obj.name#if($velocityCount != $tableInfo.fullColumn.size()),#end

#end
</sql>

</mapper>

menu.sql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
## 根据实际menu表修改
$!prefix
-- 菜单SQL
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
VALUES ('1', '#if($tableInfo.comment)$tableInfo.comment#else待命名菜单#end', 'modules/${pathName}.html', NULL, '1', 'fa fa-file-code-o', '6');

-- 按钮父菜单ID
set @parentId = @@identity;

-- 菜单对应按钮SQL
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
SELECT @parentId, '查看', null, '${tableAuth}:list,${tableAuth}:info', '2', null, '6';
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
SELECT @parentId, '新增', null, '${tableAuth}:save', '2', null, '6';
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
SELECT @parentId, '修改', null, '${tableAuth}:update', '2', null, '6';
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
SELECT @parentId, '删除', null, '${tableAuth}:delete', '2', null, '6';


list.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
$!prefix

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, ".html"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/modules/${prefixPathPipe}"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end

<!DOCTYPE html>
<html>
<head>
<title>${tableInfo.comment}</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../css/font-awesome.min.css">
<link rel="stylesheet" href="../../plugins/jqgrid/ui.jqgrid-bootstrap.css">
<link rel="stylesheet" href="../../css/jqgrid.css">
<link rel="stylesheet" href="../../plugins/ztree/css/metroStyle/metroStyle.css">
<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css">
<link rel="stylesheet" href="../../css/main.css">
<script src="../../libs/jquery.min.js"></script>
<script src="../../plugins/layer/layer.js"></script>
<script src="../../libs/bootstrap.min.js"></script>
<script src="../../libs/vue.min.js"></script>
<script src="../../plugins/jqgrid/grid.locale-cn.js"></script>
<script src="../../plugins/jqgrid/jquery.jqGrid.min.js"></script>
<script src="../../plugins/ztree/jquery.ztree.all.min.js"></script>
<script src="../../plugins/layui/layui.all.js"></script>
<script src="../../uploadUtils/uploadUtils.js"></script>
<script src="../../js/common.js"></script>
</head>
<body>
<div id="rrapp" v-cloak>
<div v-show="showList">
<div class="grid-btn">
<table>
<tr>
<td style="padding: 10px;"><label class="form-label">名称</label></td>
<td style="padding: 10px;"><input type="text" class="form-control" v-model="q.name" @keyup.enter="query"
placeholder="请输入名称"></td>
<td style="padding: 10px;">
<a class="btn btn-default" @click="query">
<li class="fa fa-search"></li>&nbsp;查询
</a>
</td>
<td colspan="6" style="padding: 10px;">
<a v-if="hasPermission('${tableAuth}:save')" class="btn btn-primary" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</a>
</td>
</tr>
</table>
</div>
<table id="jqGrid"></table>
<div id="jqGridPager"></div>
</div>

<div class="layer-panel" style="display: none;" id="addOrUpdateLayer">
<form class="form-horizontal">
#foreach($column in $tableInfo.fullColumn)
#if($column.name != $pk.name)
<div class="form-group">
<div class="col-sm-2 control-label">#if(${column.comment})${column.comment}#end</div>
<div class="col-sm-10">
<input type="text" class="form-control" v-model="$!tool.firstLowerCase($tableInfo.name).${column.name}" placeholder="请输入${column.comment}"/>
</div>
</div>
#end
#end
<!-- <div class="form-group">
<div class="col-sm-2 control-label"></div>
<input type="button" class="btn btn-primary" @click="saveOrUpdate" value="确定"/>
&nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="reload" value="返回"/>
</div> -->
</form>
</div>


</div>

<script src="../../js/modules/${pathName}.js"></script>
</body>
</html>

list.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
$!prefix

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, ".js"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/modules/${prefixPathPipe}"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end

$(function () {
$("#jqGrid").jqGrid({
url: ServerConfig.baseURL + '/#if($tableApi)$tableApi#else$!tool.firstLowerCase($tableInfo.name)#end/page',
datatype: "json",
colModel: [
#foreach($column in $tableInfo.fullColumn)
#if($column.name == $pk.name)
{ label: '${column.name}', name: '${column.name}', index: '${column.obj.name}', width: 50, key: true },
#else
{ label: '${column.comment}', name: '${column.name}', index: '${column.obj.name}', width: 80 }#if($velocityCount != $columns.size()), #end

#end
#end
,{
label: '操作',
width: 50,
sortable: false,
name:"option",
formatter: function(value, options, row) {
// id为主键
var id = row.$pk.name;
var id = row.id
var edithtml = "<span class='optionBtn' onclick='update(" + id +
")' title='编辑'><i class='fa fa-edit i-success' ></i></span>";
var delhtml = "<span class='optionBtn' onclick='del(" + id +
")' title='删除'><i class='fa fa-trash i-del'></i></span>";
if (!hasPermission('${tableAuth}:delete')) {
delhtml = '';
}
if (!hasPermission('${tableAuth}:update')) {
edithtml = '';
}
if (delhtml == '' && edithtml == '') {
jQuery("#jqGrid").setGridParam().hideCol("option").trigger("reloadGrid");
}
return "<div style='text-align: center;'>" + edithtml + delhtml + "</div>";
}
}
],
viewrecords: true,
rownumbers: true,
autowidth:true,
multiselect: false,
pager: "#jqGridPager",
height: tableConf.height,
rowNum: tableConf.rowNum,
rowList: tableConf.rowList,
rownumWidth: tableConf.rownumWidth,
jsonReader: tableConf.jsonReader,
prmNames: tableConf.prmNames,
gridComplete:function(){
//隐藏grid底部滚动条
$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
}
});
});
var picAttrList = [1];
var vm = new Vue({
el:'#cqapp',
data:{
showList: true,
title: null,
$!tool.firstLowerCase($tableInfo.name): {},
q:{
"name":''
},
isClick: true,//重复check
fileList: {},//上传图片
delIds: []//上传图片
},
mounted(){
var _this = this;
//setPicObj(_this, picAttrList);//上传图片
},
methods: {
query: function () {
vm.reload();
},
add: function(){
// vm.showList = false;
vm.$!tool.firstLowerCase($tableInfo.name) = {};
vm.openLayer("#addOrUpdateLayer", "新增")
},
validator: function() {
// if (isBlank(vm.cmEquipment.name)) {
// layer.tips('请填写设备名称!', '#name', {
// tips: [2, '#ff0000'],
// time: 1000
// });
// return true;
// }
return false;
},
saveOrUpdate: function (isLayer,layer,index) {
var url = vm.$!tool.firstLowerCase($tableInfo.name).${pk.name} == null ? "/#if($tableApi)$tableApi#else$!tool.firstLowerCase($tableInfo.name)#end/save" : "/#if($tableApi)$tableApi#else$!tool.firstLowerCase($tableInfo.name)#end/update";
if (vm.validator()) {
vm.isClick = true;
return;
}
trimHandle(vm.$!tool.firstLowerCase($tableInfo.name));
//handleImageData(vm,vm.cmEquipment,picAttrList);//上传图片
$.ajax({
type: "POST",
url: ServerConfig.baseURL + url,
contentType: "application/json",
data: JSON.stringify(vm.$!tool.firstLowerCase($tableInfo.name)),
success: function(r){
if (r.code === 200) {
isLayer = false;
layer.close(index);
showSuccess('操作成功', function() {
vm.reload();
})
} else {
showError(layer,r.msg);
vm.isClick = true;
}
}
});
},
getInfo: function(${pk.name}){
$.get(baseURL + "/#if($tableApi)$tableApi#else$!tool.firstLowerCase($tableInfo.name)#end/info/"+${pk.name}, function(r){
vm.$!tool.firstLowerCase($tableInfo.name) = r.data
});
},
reload: function (event) {
vm.showList = true;
var page = $("#jqGrid").jqGrid('getGridParam','page');
$("#jqGrid").jqGrid('setGridParam',{
page:page
}).trigger("reloadGrid");
},
openLayer: function(ids, title) {
var that = this;
that.isLayer = true;
layer.open({
title: title,
type: 1,
area: layerConf.area,
fix: false, //不固定
maxmin: true,
offset: layerConf.offset,
shade: 0.5,
shadeClose: false,
content: jQuery(ids),
btn: ['确定', '取消'],
btn1: function(index) { //确定事件
if (vm.isClick) {
vm.isClick = false;
vm.saveOrUpdate(that.isLayer, layer, index)
}
},
btn2: function(index) { //取消事件
that.isLayer = false;
layer.close(index);
vm.reload();
},
success: function(layero, index) { //打开事件
},
end: function() { //关闭事件
vm.isClick = true;
}
});
}
}
});

function update($pk.name) {
vm.getInfo(${pk.name})
vm.openLayer("#addOrUpdateLayer", "修改")
}

function del(${pk.name}) {
var ${pk.name}s = [${pk.name}]

var confirmIndex = layer.confirm('确定要删除该记录?', function(){
$.ajax({
type: "POST",
url: ServerConfig.baseURL + "/#if($tableApi)$tableApi#else$!tool.firstLowerCase($tableInfo.name)#end/delete",
contentType: "application/json",
data: JSON.stringify(${pk.name}s),
success: function(r){
if (r.code == 200) {
showSuccess('操作成功', function() {
vm.reload();
})
} else {
showError(layer,r.msg, function() {
layer.close(confirmIndex);
})
}
}
});
});
}

index.vue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
$!prefix

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, ".vue"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/modules/${prefixPathPipe}"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end

<template>
<div class="app-container">
<basic-container>
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-button v-if="hasPermission('${tableAuth}:save')" icon="el-icon-plus" type="primary" @click="addOrUpdateHandle()">新增</el-button>
</el-form-item>
</el-form>

<el-table
:data="dataList"
border
v-loading="dataListLoading">
#foreach($column in $tableInfo.fullColumn)
<el-table-column
prop="${column.name}"
header-align="center"
align="center"
label="${column.comment}">
</el-table-column>
#end
<el-table-column
header-align="center"
align="center"
label="操作">
<template slot-scope="scope">
<el-button v-if="hasPermission('${tableAuth}:update')" type="text" size="small" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row.${pk.name})">修改</el-button>
<el-button v-if="hasPermission('${tableAuth}:delete')" type="text" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.${pk.name})">删除</el-button>
</template>
</el-table-column>
</el-table>

<div class="gather_pagination">
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
:total="totalPage"
background
layout="total, sizes, prev, pager, next, jumper">
</el-pagination>
</div>
<!-- 弹窗, 新增 / 修改 -->
<table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
</basic-container>
</div>
</template>

<script>
import {fetchList, delObj} from '@/api/${pathName}'
import TableForm from './${pathName}-form'
import {mapGetters} from 'vuex'
export default {
data () {
return {
dataForm: {
key: ''
},
dataList: [],
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
addOrUpdateVisible: false
}
},
components: {
TableForm
},
created () {
this.getDataList()
},
computed: {
...mapGetters(['permissions'])
},
methods: {
// 获取数据列表
getDataList () {
this.dataListLoading = true
fetchList(Object.assign({
current: this.pageIndex,
size: this.pageSize
})).then(response => {
this.dataList = response.data.data.records
this.totalPage = response.data.data.total
})
this.dataListLoading = false
},
// 每页数
sizeChangeHandle (val) {
this.pageSize = val
this.pageIndex = 1
this.getDataList()
},
// 当前页
currentChangeHandle (val) {
this.pageIndex = val
this.getDataList()
},
// 新增 / 修改
addOrUpdateHandle (id) {
this.addOrUpdateVisible = true
#[[this.$nextTick(() => {]]#
this.$refs.addOrUpdate.init(id)
})
},
// 删除
deleteHandle (id) {
this.$confirm('是否确认删除ID为' + id, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
return delObj(id)
}).then(data => {
this.$message.success('删除成功')
this.getDataList()
})
}
}
}
</script>

form.vue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
$!prefix

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "-form.vue"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/modules/${prefixPathPipe}"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end

<template>
<el-dialog
:title="!dataForm.id ? '新增' : '修改'"
:close-on-click-modal="false"
:visible.sync="visible">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
#foreach($column in $tableInfo.fullColumn)
#if($column.name != $pk.name)
<el-form-item label="#if(${column.comment})${column.comment}#end" prop="${column.name}">
<el-input v-model="dataForm.${column.name}" placeholder="#if(${column.comment})${column.comment}#end"></el-input>
</el-form-item>
#end
#end
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
</span>
</el-dialog>
</template>

<script>
import {getObj, addObj, putObj} from '@/api/${pathName}'

export default {
data () {
return {
visible: false,
dataForm: {
#foreach($column in $tableInfo.fullColumn)
#if($column.name == $pk.name)
${column.name}: 0,
#else
${column.name}: ''#if($velocityCount != $tableInfo.fullColumn.size()),#end

#end
#end
},
dataRule: {
#foreach($column in $tableInfo.fullColumn)
#if($column.name != $pk.name)
${column.name}: [
{ required: true, message: '#if(${column.comment})${column.comment}#end 不能为空', trigger: 'blur' }
]#if($velocityCount != $tableInfo.fullColumn.size()),#end

#end
#end
}
}
},
methods: {
init (id) {
this.dataForm.${pk.name} = id || 0
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.${pk.name}) {
getObj(this.dataForm.${pk.name}).then(response => {
this.dataForm = response.data.data
})
}
})
},
// 表单提交
dataFormSubmit () {
#[[this.$refs['dataForm'].validate((valid) => {]]#
if (valid) {
if (this.dataForm.${pk.name}) {
putObj(this.dataForm).then(data => {
this.$message.success('修改成功')
this.visible = false
this.$emit('refreshDataList')
});
} else {
addObj(this.dataForm).then(data => {
this.$message.success('添加成功')
this.visible = false
this.$emit('refreshDataList')
})
}
}
})
}
}
}
</script>

Global config
image-20220905132335215

init

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
##初始化区域

##去掉表的t_前缀
$!tableInfo.setName($tool.getClassName($tableInfo.obj.name.replaceFirst("book_","")))

##参考阿里巴巴开发手册,POJO 类中布尔类型的变量,都不要加 is 前缀,否则部分框架解析会引起序列化错误
#foreach($column in $tableInfo.fullColumn)
#if($column.name.startsWith("is") && $column.type.equals("java.lang.Boolean"))
$!column.setName($tool.firstLowerCase($column.name.substring(2)))
#end
#end

##实现动态排除列
#set($temp = $tool.newHashSet("testCreateTime", "otherColumn"))
#foreach($item in $temp)
#set($newList = $tool.newArrayList())
#foreach($column in $tableInfo.fullColumn)
#if($column.name!=$item)
##带有反回值的方法调用时使用$tool.call来消除返回值 ##带有反回值的方法调用时使用$tool.call来消除返回值
$tool.call($newList.add($column))
#end
#end
##重新保存
$tableInfo.setFullColumn($newList)
#end

##对importList进行篡改
#set($temp = $tool.newHashSet())
#foreach($column in $tableInfo.fullColumn)
#if(!$column.type.startsWith("java.lang."))
##带有反回值的方法调用时使用$tool.call来消除返回值
$tool.call($temp.add($column.type))
#end
#end
##覆盖
#set($importList = $temp)

define

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
##(Velocity宏定义)

##定义设置表名后缀的宏定义,调用方式:#setTableSuffix("Test")
#macro(setTableSuffix $suffix)
#set($tableName = $!tool.append($tableInfo.name, $suffix))
#end

##定义设置包名后缀的宏定义,调用方式:#setPackageSuffix("Test")
#macro(setPackageSuffix $suffix)
#if($suffix!="")package #end#if($tableInfo.savePackageName!="")$!{tableInfo.savePackageName}.#{end}$!suffix;
#end

##定义直接保存路径与文件名简化的宏定义,调用方式:#save("/entity", ".java")
#macro(save $path $fileName)
$!callback.setSavePath($tool.append($tableInfo.savePath, $path))
$!callback.setFileName($tool.append($tableInfo.name, $fileName))
#end

##定义表注释的宏定义,调用方式:#tableComment("注释信息")
#macro(tableComment $desc)
/**
* $!{tableInfo.comment}($!{tableInfo.obj.name})$desc
*
* @author $!author
* @since $!time.currTime()
*/
#end

##定义GET,SET方法的宏定义,调用方式:#getSetMethod($column)
#macro(getSetMethod $column)

public $!{tool.getClsNameByFullName($column.type)} get$!{tool.firstUpperCase($column.name)}() {
return $!{column.name};
}

public void set$!{tool.firstUpperCase($column.name)}($!{tool.getClsNameByFullName($column.type)} $!{column.name}) {
this.$!{column.name} = $!{column.name};
}
#end

autoimport

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
##自动导入包(仅导入实体属性需要的包,通常用于实体类)
#foreach($import in $importList)
import $!import;
#end

mybatisSupport
##针对Mybatis 进行支持,主要用于生成xml文件
#foreach($column in $tableInfo.fullColumn)
##储存列类型
$tool.call($column.ext.put("sqlType", $tool.getField($column.obj.dataType, "typeName")))
#if($tool.newHashSet("java.lang.String").contains($column.type))
#set($jdbcType="VARCHAR")
#elseif($tool.newHashSet("java.lang.Boolean", "boolean").contains($column.type))
#set($jdbcType="BOOLEAN")
#elseif($tool.newHashSet("java.lang.Byte", "byte").contains($column.type))
#set($jdbcType="BYTE")
#elseif($tool.newHashSet("java.lang.Integer", "int", "java.lang.Short", "short").contains($column.type))
#set($jdbcType="INTEGER")
#elseif($tool.newHashSet("java.lang.Long", "long").contains($column.type))
#set($jdbcType="INTEGER")
#elseif($tool.newHashSet("java.lang.Float", "float", "java.lang.Double", "double").contains($column.type))
#set($jdbcType="NUMERIC")
#elseif($tool.newHashSet("java.util.Date", "java.sql.Timestamp", "java.time.Instant", "java.time.LocalDateTime", "java.time.OffsetDateTime", " java.time.ZonedDateTime").contains($column.type))
#set($jdbcType="TIMESTAMP")
#elseif($tool.newHashSet("java.sql.Date", "java.time.LocalDate").contains($column.type))
#set($jdbcType="TIMESTAMP")
#else
##其他类型
#set($jdbcType="OTHER")
#end
$tool.call($column.ext.put("jdbcType", $jdbcType))
#end

##定义宏,查询所有列
#macro(allSqlColumn)#foreach($column in $tableInfo.fullColumn)$column.obj.name#if($velocityHasNext), #end#end#end

prefix

1
2
3
4
5
6
7
8
9
10
11
12
## 控制是否根据表名首段分割
#set($isEffect=true)
#set($prefixPathPipe="")
#set($prefixPathDot="")
##获取表名前缀
#if($tableInfo.obj.name.indexOf("_") != -1 && $isEffect)
#set($tablePrefix=$tableInfo.obj.name.split("_").get(0))
#set($tableApi=$tableInfo.obj.name.replace("_", "/"))
#set($prefixPathPipe=$tool.append("/",$tablePrefix))
#set($prefixPathDot=$tool.append(".",$tablePrefix))

#end