调整部分包路径

This commit is contained in:
RuoYi
2019-03-08 14:44:38 +08:00
parent 1b193bcc65
commit 9531875401
78 changed files with 809 additions and 701 deletions

View File

@ -0,0 +1,73 @@
package com.ruoyi.generator.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
/**
* 读取代码生成相关配置
*
* @author ruoyi
*/
@Component
@ConfigurationProperties(prefix = "gen")
@PropertySource(value = { "generator.yml" })
public class GenConfig
{
/** 作者 */
public static String author;
/** 生成包路径 */
public static String packageName;
/** 自动去除表前缀默认是true */
public static String autoRemovePre;
/** 表前缀(类名不会包含表前缀) */
public static String tablePrefix;
public static String getAuthor()
{
return author;
}
@Value("${author}")
public void setAuthor(String author)
{
GenConfig.author = author;
}
public static String getPackageName()
{
return packageName;
}
@Value("${packageName}")
public void setPackageName(String packageName)
{
GenConfig.packageName = packageName;
}
public static String getAutoRemovePre()
{
return autoRemovePre;
}
@Value("${autoRemovePre}")
public void setAutoRemovePre(String autoRemovePre)
{
GenConfig.autoRemovePre = autoRemovePre;
}
public static String getTablePrefix()
{
return tablePrefix;
}
@Value("${tablePrefix}")
public void setTablePrefix(String tablePrefix)
{
GenConfig.tablePrefix = tablePrefix;
}
}

View File

@ -0,0 +1,89 @@
package com.ruoyi.generator.controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.support.Convert;
import com.ruoyi.generator.domain.TableInfo;
import com.ruoyi.generator.service.IGenService;
/**
* 代码生成 操作处理
*
* @author ruoyi
*/
@Controller
@RequestMapping("/tool/gen")
public class GenController extends BaseController
{
private String prefix = "tool/gen";
@Autowired
private IGenService genService;
@RequiresPermissions("tool:gen:view")
@GetMapping()
public String gen()
{
return prefix + "/gen";
}
@RequiresPermissions("tool:gen:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(TableInfo tableInfo)
{
startPage();
List<TableInfo> list = genService.selectTableList(tableInfo);
return getDataTable(list);
}
/**
* 生成代码
*/
@RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/genCode/{tableName}")
public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
{
byte[] data = genService.generatorCode(tableName);
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
}
/**
* 批量生成代码
*/
@RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/batchGenCode")
@ResponseBody
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
{
String[] tableNames = Convert.toStrArray(tables);
byte[] data = genService.generatorCode(tableNames);
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
}
}

View File

@ -1,7 +1,7 @@
package com.ruoyi.generator.domain;
import java.util.List;
import com.ruoyi.common.base.BaseEntity;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.StringUtils;
/**

View File

@ -14,9 +14,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.generator.config.GenConfig;
import com.ruoyi.generator.domain.ColumnInfo;
import com.ruoyi.generator.domain.TableInfo;
import com.ruoyi.generator.mapper.GenMapper;
@ -110,7 +110,7 @@ public class GenServiceImpl implements IGenService
VelocityInitializer.initVelocity();
String packageName = Global.getPackageName();
String packageName = GenConfig.getPackageName();
String moduleName = GenUtils.getModuleName(packageName);
VelocityContext context = GenUtils.getVelocityContext(table);

View File

@ -5,10 +5,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.velocity.VelocityContext;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.generator.config.GenConfig;
import com.ruoyi.generator.domain.ColumnInfo;
import com.ruoyi.generator.domain.TableInfo;
@ -64,7 +64,7 @@ public class GenUtils
{
// java对象数据传递到模板文件vm
VelocityContext velocityContext = new VelocityContext();
String packageName = Global.getPackageName();
String packageName = GenConfig.getPackageName();
velocityContext.put("tableName", table.getTableName());
velocityContext.put("tableComment", replaceKeyword(table.getTableComment()));
velocityContext.put("primaryKey", table.getPrimaryKey());
@ -74,7 +74,7 @@ public class GenUtils
velocityContext.put("columns", table.getColumns());
velocityContext.put("basePackage", getBasePackage(packageName));
velocityContext.put("package", packageName);
velocityContext.put("author", Global.getAuthor());
velocityContext.put("author", GenConfig.getAuthor());
velocityContext.put("datetime", DateUtils.getDate());
return velocityContext;
}
@ -105,8 +105,8 @@ public class GenUtils
*/
public static String tableToJava(String tableName)
{
String autoRemovePre = Global.getAutoRemovePre();
String tablePrefix = Global.getTablePrefix();
String autoRemovePre = GenConfig.getAutoRemovePre();
String tablePrefix = GenConfig.getTablePrefix();
if (Constants.AUTO_REOMVE_PRE.equals(autoRemovePre) && StringUtils.isNotEmpty(tablePrefix))
{
tableName = tableName.replaceFirst(tablePrefix, "");
@ -199,7 +199,7 @@ public class GenUtils
public static String getProjectPath()
{
String packageName = Global.getPackageName();
String packageName = GenConfig.getPackageName();
StringBuffer projectPath = new StringBuffer();
projectPath.append("main/java/");
projectPath.append(packageName.replace(".", "/"));

View File

@ -0,0 +1,11 @@
# 代码生成
gen:
# 作者
author: ruoyi
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
packageName: com.ruoyi.system
# 自动去除表前缀默认是true
autoRemovePre: true
# 表前缀(类名不会包含表前缀)
tablePrefix: sys_

View File

@ -0,0 +1,123 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="gen-form">
<div class="select-list">
<ul>
<li>
表名称:<input type="text" name="tableName"/>
</li>
<li>
表描述:<input type="text" name="tableComment"/>
</li>
<li class="select-time">
<label>表时间: </label>
<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
<span>-</span>
<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="javascript:batchGenCode()" shiro:hasPermission="tool:gen:code">
<i class="fa fa-download"></i> 批量生成
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table" data-mobile-responsive="true"></table>
</div>
</div>
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript">
var prefix = ctx + "tool/gen";
$(function() {
var options = {
url: prefix + "/list",
sortName: "createTime",
sortOrder: "desc",
showExport: true,
columns: [{
checkbox: true
},
{
title: "序号",
formatter: function (value, row, index) {
return $.table.serialNumber(index);
}
},
{
field: 'tableName',
title: '表名称',
width: '20%',
sortable: true
},
{
field: 'tableComment',
title: '表描述',
width: '20%',
sortable: true
},
{
field: 'createTime',
title: '创建时间',
width: '20%',
sortable: true
},
{
field: 'updateTime',
title: '更新时间',
width: '20%',
sortable: true
},
{
title: '操作',
width: '20%',
align: 'center',
formatter: function(value, row, index) {
var msg = '<a class="btn btn-primary btn-xs" href="#" onclick="genCode(\'' + row.tableName + '\')"><i class="fa fa-bug"></i>生成代码</a> ';
return msg;
}
}]
};
$.table.init(options);
});
// 生成代码
function genCode(tableName) {
$.modal.confirm("确定要生成" + tableName + "表代码吗?", function() {
location.href = prefix + "/genCode/" + tableName;
layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
})
}
//批量生成代码
function batchGenCode() {
var rows = $.table.selectColumns("tableName");
if (rows.length == 0) {
$.modal.alertWarning("请选择要生成的数据");
return;
}
$.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
location.href = prefix + "/batchGenCode?tables=" + rows;
layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
});
}
</script>
</body>
</html>