mirror of https://gitee.com/maxjhandsome/pig
end: 优化代码生成
This commit is contained in:
parent
9a8300e731
commit
32521a1607
|
@ -2,11 +2,13 @@ package com.github.pig.admin.controller;
|
|||
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.github.pig.admin.entity.SysDict;
|
||||
import com.github.pig.admin.service.SysDictService;
|
||||
import com.github.pig.common.constant.CommonConstant;
|
||||
import com.github.pig.common.web.BaseController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -28,9 +30,31 @@ public class DictController extends BaseController {
|
|||
@Autowired
|
||||
private SysDictService sysDictService;
|
||||
|
||||
/**
|
||||
* 通过ID查询字典信息
|
||||
*
|
||||
* @param id ID
|
||||
* @return 字典信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public void dict(@PathVariable Integer id) {
|
||||
public SysDict dict(@PathVariable Integer id) {
|
||||
return sysDictService.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询字典信息
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param limit 每页限制
|
||||
* @return 分页对象
|
||||
*/
|
||||
@RequestMapping("/dictPage")
|
||||
public Page dictPage(Integer page, Integer limit) {
|
||||
SysDict condition = new SysDict();
|
||||
condition.setDelFlag(CommonConstant.STATUS_NORMAL);
|
||||
EntityWrapper wrapper = new EntityWrapper(condition);
|
||||
wrapper.orderBy("createTime", false);
|
||||
return sysDictService.selectPage(new Page<>(page, limit), wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,6 +64,7 @@ public class DictController extends BaseController {
|
|||
* @return 同类型字典
|
||||
*/
|
||||
@GetMapping("/type/{type}")
|
||||
@Cacheable(value = "dict_details", key = "#type")
|
||||
public List<SysDict> findDictByType(@PathVariable String type) {
|
||||
SysDict condition = new SysDict();
|
||||
condition.setDelFlag(CommonConstant.STATUS_NORMAL);
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.github.pig.admin.util;
|
|||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DbType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
|
@ -55,7 +54,7 @@ public class MybatisPlusGenerator {
|
|||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
// strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意
|
||||
strategy.setTablePrefix(new String[]{"sys_"});// 此处可以修改为您的表前缀
|
||||
strategy.setSuperControllerClass("com.github.pig.common.web.BaseController");
|
||||
// 表名生成策略
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
mpg.setStrategy(strategy);
|
||||
|
@ -77,10 +76,16 @@ public class MybatisPlusGenerator {
|
|||
viewDir.mkdirs();
|
||||
}
|
||||
List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
|
||||
focList.add(new FileOutConfig("/template/listvue.vue.vm") {
|
||||
focList.add(new FileOutConfig("/templates/listvue.vue.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return getGeneratorViewPath(viewOutputDir, tableInfo, "List.vue");
|
||||
return getGeneratorViewPath(viewOutputDir, tableInfo, ".vue");
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig("/templates/controller.java.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return getGeneratorViewPath(viewOutputDir, tableInfo, ".java");
|
||||
}
|
||||
});
|
||||
cfg.setFileOutConfigList(focList);
|
||||
|
|
|
@ -1,179 +0,0 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||
<%@ include file="/commons/global.jsp" %>
|
||||
<script type="text/javascript">
|
||||
var ${table.entityPath}DataGrid;
|
||||
$(function() {
|
||||
${table.entityPath}DataGrid = $('#${table.entityPath}DataGrid').datagrid({
|
||||
url : '${path}/${table.entityPath}/dataGrid',
|
||||
striped : true,
|
||||
rownumbers : true,
|
||||
pagination : true,
|
||||
singleSelect : true,
|
||||
idField : 'id',
|
||||
sortName : 'id',
|
||||
sortOrder : 'asc',
|
||||
pageSize : 20,
|
||||
pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
|
||||
frozenColumns : [ [ {
|
||||
width : '60',
|
||||
title : '编号',
|
||||
field : 'id',
|
||||
sortable : true
|
||||
}, {
|
||||
width : '60',
|
||||
title : '状态',
|
||||
field : 'status',
|
||||
sortable : true,
|
||||
formatter : function(value, row, index) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return '正常';
|
||||
case 1:
|
||||
return '停用';
|
||||
}
|
||||
}
|
||||
}, {
|
||||
width : '140',
|
||||
title : '创建时间',
|
||||
field : 'createTime',
|
||||
sortable : true
|
||||
}, {
|
||||
field : 'action',
|
||||
title : '操作',
|
||||
width : 200,
|
||||
formatter : function(value, row, index) {
|
||||
var str = '';
|
||||
<shiro:hasPermission name="/${table.entityPath}/edit">
|
||||
str += $.formatString('<a href="javascript:void(0)" class="${table.entityPath}-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="${table.entityPath}EditFun(\'{0}\');" >编辑</a>', row.id);
|
||||
</shiro:hasPermission>
|
||||
<shiro:hasPermission name="/${table.entityPath}/delete">
|
||||
str += ' | ';
|
||||
str += $.formatString('<a href="javascript:void(0)" class="${table.entityPath}-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="${table.entityPath}DeleteFun(\'{0}\');" >删除</a>', row.id);
|
||||
</shiro:hasPermission>
|
||||
return str;
|
||||
}
|
||||
} ] ],
|
||||
onLoadSuccess:function(data){
|
||||
$('.${table.entityPath}-easyui-linkbutton-edit').linkbutton({text:'编辑'});
|
||||
$('.${table.entityPath}-easyui-linkbutton-del').linkbutton({text:'删除'});
|
||||
},
|
||||
toolbar : '#${table.entityPath}Toolbar'
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 添加框
|
||||
* @param url
|
||||
*/
|
||||
function ${table.entityPath}AddFun() {
|
||||
parent.$.modalDialog({
|
||||
title : '添加',
|
||||
width : 700,
|
||||
height : 600,
|
||||
href : '${path}/${table.entityPath}/addPage',
|
||||
buttons : [ {
|
||||
text : '确定',
|
||||
handler : function() {
|
||||
parent.$.modalDialog.openner_dataGrid = ${table.entityPath}DataGrid;//因为添加成功之后,需要刷新这个treeGrid,所以先预定义好
|
||||
var f = parent.$.modalDialog.handler.find('#${table.entityPath}AddForm');
|
||||
f.submit();
|
||||
}
|
||||
} ]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
function ${table.entityPath}EditFun(id) {
|
||||
if (id == undefined) {
|
||||
var rows = ${table.entityPath}DataGrid.datagrid('getSelections');
|
||||
id = rows[0].id;
|
||||
} else {
|
||||
${table.entityPath}DataGrid.datagrid('unselectAll').datagrid('uncheckAll');
|
||||
}
|
||||
parent.$.modalDialog({
|
||||
title : '编辑',
|
||||
width : 700,
|
||||
height : 600,
|
||||
href : '${path}/${table.entityPath}/editPage?id=' + id,
|
||||
buttons : [ {
|
||||
text : '确定',
|
||||
handler : function() {
|
||||
parent.$.modalDialog.openner_dataGrid = ${table.entityPath}DataGrid;//因为添加成功之后,需要刷新这个dataGrid,所以先预定义好
|
||||
var f = parent.$.modalDialog.handler.find('#${table.entityPath}EditForm');
|
||||
f.submit();
|
||||
}
|
||||
} ]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
function ${table.entityPath}DeleteFun(id) {
|
||||
if (id == undefined) {//点击右键菜单才会触发这个
|
||||
var rows = ${table.entityPath}DataGrid.datagrid('getSelections');
|
||||
id = rows[0].id;
|
||||
} else {//点击操作里面的删除图标会触发这个
|
||||
${table.entityPath}DataGrid.datagrid('unselectAll').datagrid('uncheckAll');
|
||||
}
|
||||
parent.$.messager.confirm('询问', '您是否要删除当前角色?', function(b) {
|
||||
if (b) {
|
||||
progressLoad();
|
||||
$.post('${path}/${table.entityPath}/delete', {
|
||||
id : id
|
||||
}, function(result) {
|
||||
if (result.success) {
|
||||
parent.$.messager.alert('提示', result.msg, 'info');
|
||||
${table.entityPath}DataGrid.datagrid('reload');
|
||||
}
|
||||
progressClose();
|
||||
}, 'JSON');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清除
|
||||
*/
|
||||
function ${table.entityPath}CleanFun() {
|
||||
$('#${table.entityPath}SearchForm input').val('');
|
||||
${table.entityPath}DataGrid.datagrid('load', {});
|
||||
}
|
||||
/**
|
||||
* 搜索
|
||||
*/
|
||||
function ${table.entityPath}SearchFun() {
|
||||
${table.entityPath}DataGrid.datagrid('load', $.serializeObject($('#${table.entityPath}SearchForm')));
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="easyui-layout" data-options="fit:true,border:false">
|
||||
<div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
|
||||
<form id="${table.entityPath}SearchForm">
|
||||
<table>
|
||||
<tr>
|
||||
<th>名称:</th>
|
||||
<td><input name="name" placeholder="搜索条件"/></td>
|
||||
<td>
|
||||
<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="${table.entityPath}SearchFun();">查询</a>
|
||||
<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="${table.entityPath}CleanFun();">清空</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div data-options="region:'center',border:false">
|
||||
<table id="${table.entityPath}DataGrid" data-options="fit:true,border:false"></table>
|
||||
</div>
|
||||
</div>
|
||||
<div id="${table.entityPath}Toolbar" style="display: none;">
|
||||
<shiro:hasPermission name="/${table.entityPath}/add">
|
||||
<a onclick="${table.entityPath}AddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
|
||||
</shiro:hasPermission>
|
||||
</div>
|
|
@ -1,124 +0,0 @@
|
|||
<template>
|
||||
<div class="app-container calendar-list-container">
|
||||
<div class="filter-container">
|
||||
</div>
|
||||
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit
|
||||
highlight-current-row style="width: 100%">
|
||||
|
||||
<el-table-column align="center" label="序号">
|
||||
<template scope="scope">
|
||||
<span>{{scope.row.id}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="URI" show-overflow-tooltip>
|
||||
<template scope="scope">
|
||||
<span>{{ scope.row.requestUri}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column align="center" label="IP">
|
||||
<template scope="scope">
|
||||
<span>{{scope.row.remoteAddr}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column align="center" label="METHOD">
|
||||
<template scope="scope">
|
||||
<span>{{scope.row.method}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column align="center" label="PARAMS" show-overflow-tooltip>
|
||||
<template scope="scope">
|
||||
<span>{{scope.row.params}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column align="center" label="EXCEPTION">
|
||||
<template scope="scope">
|
||||
<span>{{scope.row.time}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column align="center" label="创建时间">
|
||||
<template scope="scope">
|
||||
<span>{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="操作">
|
||||
<template scope="scope">
|
||||
<el-button size="mini" type="danger"
|
||||
@click="handleDelete(scope.row)">删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div v-show="!listLoading" class="pagination-container">
|
||||
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
|
||||
:current-page.sync="listQuery.page"
|
||||
:page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
|
||||
layout="total, sizes, prev, pager, next, jumper" :total="total">
|
||||
</el-pagination>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { fetchList, delObj } from '@/api/log'
|
||||
import waves from '@/directive/waves/index.js' // 水波纹指令
|
||||
|
||||
export default {
|
||||
name: 'table_log',
|
||||
directives: {
|
||||
waves
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
list: null,
|
||||
total: null,
|
||||
listLoading: true,
|
||||
listQuery: {
|
||||
page: 1,
|
||||
limit: 20
|
||||
},
|
||||
tableKey: 0
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
},
|
||||
methods: {
|
||||
getList() {
|
||||
this.listLoading = true
|
||||
fetchList(this.listQuery).then(response => {
|
||||
this.list = response.data.records
|
||||
this.total = response.data.total
|
||||
this.listLoading = false
|
||||
})
|
||||
},
|
||||
handleSizeChange(val) {
|
||||
this.listQuery.limit = val
|
||||
this.getList()
|
||||
},
|
||||
handleCurrentChange(val) {
|
||||
this.listQuery.page = val
|
||||
this.getList()
|
||||
},
|
||||
handleDelete(row) {
|
||||
delObj(row.id)
|
||||
.then(response => {
|
||||
this.dialogFormVisible = false
|
||||
this.getList()
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,121 @@
|
|||
package ${package.Controller};
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.wangzhixuan.commons.result.PageInfo;
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
#if(${superControllerClassPackage})
|
||||
import ${superControllerClassPackage};
|
||||
#end
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${table.entityPath}")
|
||||
public class ${table.controllerName} extends ${superControllerClass} {
|
||||
@Autowired private ${table.serviceName} ${table.entityPath}Service;
|
||||
|
||||
@PostMapping("/dataGrid")
|
||||
public PageInfo dataGrid(${entity} ${table.entityPath}, Integer page, Integer rows, String sort,String order) {
|
||||
PageInfo pageInfo = new PageInfo(page, rows, sort, order);
|
||||
EntityWrapper<${entity}> ew = new EntityWrapper<${entity}>(${table.entityPath});
|
||||
Page<${entity}> pages = getPage(pageInfo);
|
||||
pages = ${table.entityPath}Service.selectPage(pages, ew);
|
||||
pageInfo.setRows(pages.getRecords());
|
||||
pageInfo.setTotal(pages.getTotal());
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加页面
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/addPage")
|
||||
public String addPage() {
|
||||
return "admin/${table.entityPath}/${table.entityPath}Add";
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@ResponseBody
|
||||
public Object add(@Valid ${entity} ${table.entityPath}) {
|
||||
${table.entityPath}.setCreateTime(new Date());
|
||||
${table.entityPath}.setUpdateTime(new Date());
|
||||
${table.entityPath}.setDeleteFlag(0);
|
||||
boolean b = ${table.entityPath}Service.insert(${table.entityPath});
|
||||
if (b) {
|
||||
return renderSuccess("添加成功!");
|
||||
} else {
|
||||
return renderError("添加失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@ResponseBody
|
||||
public Object delete(Long id) {
|
||||
${entity} ${table.entityPath} = new ${entity}();
|
||||
${table.entityPath}.setId(id);
|
||||
${table.entityPath}.setUpdateTime(new Date());
|
||||
${table.entityPath}.setDeleteFlag(1);
|
||||
boolean b = ${table.entityPath}Service.updateById(${table.entityPath});
|
||||
if (b) {
|
||||
return renderSuccess("删除成功!");
|
||||
} else {
|
||||
return renderError("删除失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param model
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/editPage")
|
||||
public String editPage(Model model, Long id) {
|
||||
${entity} ${table.entityPath} = ${table.entityPath}Service.selectById(id);
|
||||
model.addAttribute("${table.entityPath}", ${table.entityPath});
|
||||
return "admin/${table.entityPath}/${table.entityPath}Edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
@ResponseBody
|
||||
public Object edit(@Valid ${entity} ${table.entityPath}) {
|
||||
${table.entityPath}.setUpdateTime(new Date());
|
||||
boolean b = ${table.entityPath}Service.updateById(${table.entityPath});
|
||||
if (b) {
|
||||
return renderSuccess("编辑成功!");
|
||||
} else {
|
||||
return renderError("编辑失败!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
-- 菜单SQL
|
||||
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');
|
||||
|
||||
-- 按钮父菜单ID
|
||||
set @parentId = @@identity;
|
||||
|
||||
-- 菜单对应按钮SQL
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
SELECT @parentId, '查看', null, '${pathName}:list,${pathName}:info', '2', null, '6';
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
SELECT @parentId, '新增', null, '${pathName}:save', '2', null, '6';
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
SELECT @parentId, '修改', null, '${pathName}:update', '2', null, '6';
|
||||
INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`)
|
||||
SELECT @parentId, '删除', null, '${pathName}:delete', '2', null, '6';
|
Loading…
Reference in New Issue