调整部分包路径
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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(".", "/"));
|
||||
|
Reference in New Issue
Block a user