代码生成器
This commit is contained in:
parent
3e31517297
commit
d03c911ebc
|
|
@ -18,7 +18,9 @@ public class AdminConfig {
|
||||||
public static String[] notLoginUri = new String[]{
|
public static String[] notLoginUri = new String[]{
|
||||||
"system:login", // 登录接口
|
"system:login", // 登录接口
|
||||||
"common:index:config", // 配置接口
|
"common:index:config", // 配置接口
|
||||||
"common:index:config" // 配置接口
|
"common:index:config", // 配置接口
|
||||||
|
"gen:genCode", // 配置接口
|
||||||
|
"gen:downloadCode" // 配置接口
|
||||||
};
|
};
|
||||||
|
|
||||||
// 免权限验证
|
// 免权限验证
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.hxkj.common.validator;
|
||||||
|
|
||||||
|
import com.hxkj.common.validator.annotation.IntArrayEmpty;
|
||||||
|
import javax.validation.ConstraintValidator;
|
||||||
|
import javax.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证整数数组是否为空
|
||||||
|
*/
|
||||||
|
public class IntArrayEmptyValidator implements ConstraintValidator<IntArrayEmpty, int[]> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(IntArrayEmpty constraintAnnotation) {
|
||||||
|
ConstraintValidator.super.initialize(constraintAnnotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(int[] value, ConstraintValidatorContext context) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.hxkj.common.validator.annotation;
|
||||||
|
|
||||||
|
import com.hxkj.common.validator.IntArrayEmptyValidator;
|
||||||
|
import javax.validation.Constraint;
|
||||||
|
import javax.validation.Payload;
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Documented
|
||||||
|
@Constraint(validatedBy = IntArrayEmptyValidator.class)
|
||||||
|
@Target({ ElementType.PARAMETER,ElementType.FIELD })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface IntArrayEmpty {
|
||||||
|
|
||||||
|
String message() default "数组不允许为空";
|
||||||
|
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default { };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,17 +2,14 @@ package com.hxkj.generator.config;
|
||||||
|
|
||||||
public class GenConfig {
|
public class GenConfig {
|
||||||
|
|
||||||
// 作者姓名
|
// 基础包名
|
||||||
public static String authorName = "LikeAdmin";
|
public static String packageName = "com.hxkj";
|
||||||
|
|
||||||
// 生成包名
|
// 后台应用
|
||||||
public static String packageName = "com.hxkj.admin";
|
public static String adminPackage = "like-admin/src/main/java/com/hxkj/admin";
|
||||||
|
|
||||||
// 主要应用
|
|
||||||
public static String mainApp = "like-{}/src/main/java/";
|
|
||||||
|
|
||||||
// 公共应用
|
// 公共应用
|
||||||
public static String commonApp = "like-common/src/main/java/";
|
public static String commonPackage = "like-common/src/main/java/com/hxkj/common";
|
||||||
|
|
||||||
// 表前缀名
|
// 表前缀名
|
||||||
public static String tablePrefix = "ls_";
|
public static String tablePrefix = "ls_";
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,16 @@ public class SqlConstants {
|
||||||
/** 时间日期字段名 */
|
/** 时间日期字段名 */
|
||||||
public static final String[] COLUMN_TIME_NAME = {"create_time", "update_time", "delete_time", "start_time", "end_time"};
|
public static final String[] COLUMN_TIME_NAME = {"create_time", "update_time", "delete_time", "start_time", "end_time"};
|
||||||
|
|
||||||
|
/** 页面不需要插入字段 */
|
||||||
|
public static final String[] COLUMN_NAME_NOT_ADD = {"id", "is_delete", "create_time", "update_time", "delete_time"};
|
||||||
|
|
||||||
/** 页面不需要编辑字段 */
|
/** 页面不需要编辑字段 */
|
||||||
public static final String[] COLUMN_NAME_NOT_EDIT = {"id", "create_time", "update_time", "delete_time"};
|
public static final String[] COLUMN_NAME_NOT_EDIT = {"is_delete", "create_time", "update_time", "delete_time"};
|
||||||
|
|
||||||
/** 页面不需要列表字段 */
|
/** 页面不需要列表字段 */
|
||||||
public static final String[] COLUMN_NAME_NOT_LIST = {"id", "intro", "content", "is_delete", "delete_time"};
|
public static final String[] COLUMN_NAME_NOT_LIST = {"id", "intro", "content", "is_delete", "delete_time"};
|
||||||
|
|
||||||
/** 页面不需要查询字段 */
|
/** 页面不需要查询字段 */
|
||||||
public static final String[] COLUMN_NAME_NOT_QUERY = {"id", "image", "intro", "content", "sort", "is_delete", "create_time", "update_time", "delete_time"};
|
public static final String[] COLUMN_NAME_NOT_QUERY = {"is_delete", "create_time", "update_time", "delete_time"};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ public class GenController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/importTable")
|
@PostMapping("/importTable")
|
||||||
public Object importTable(String tables) {
|
public Object importTable(String tables) {
|
||||||
Assert.notNull(tables, "请选择要导出的表");
|
Assert.notNull(tables, "请选择要导入的表");
|
||||||
String[] tableNames = tables.split(",");
|
String[] tableNames = tables.split(",");
|
||||||
iGenerateService.importTable(tableNames);
|
iGenerateService.importTable(tableNames);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
|
|
@ -162,7 +162,7 @@ public class GenController {
|
||||||
response.reset();
|
response.reset();
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=\"like.zip\"");
|
response.setHeader("Content-Disposition", "attachment; filename=\"likeadmin-curd.zip\"");
|
||||||
response.addHeader("Content-Length", "" + data.length);
|
response.addHeader("Content-Length", "" + data.length);
|
||||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||||
IOUtils.write(data, response.getOutputStream());
|
IOUtils.write(data, response.getOutputStream());
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ public class GenTableColumn implements Serializable {
|
||||||
private Integer tableId;
|
private Integer tableId;
|
||||||
private String columnName;
|
private String columnName;
|
||||||
private String columnComment;
|
private String columnComment;
|
||||||
|
private Integer columnLength;
|
||||||
private String columnType;
|
private String columnType;
|
||||||
private String javaType;
|
private String javaType;
|
||||||
private String javaField;
|
private String javaField;
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
|
|
||||||
QueryWrapper<GenTable> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<GenTable> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.orderByDesc("id");
|
queryWrapper.orderByDesc("id");
|
||||||
queryWrapper.select("id,gen_tpl,entity_name,table_name,table_comment,create_time,update_time");
|
queryWrapper.select("id,table_name,table_comment,create_time,update_time");
|
||||||
|
|
||||||
genTableMapper.setSearch(queryWrapper, params, new String[]{
|
genTableMapper.setSearch(queryWrapper, params, new String[]{
|
||||||
"like:tableName@table_name:str",
|
"like:tableName@table_name:str",
|
||||||
|
|
@ -346,6 +346,8 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> previewCode(Integer id) {
|
public Map<String, String> previewCode(Integer id) {
|
||||||
GenTable table = genTableMapper.selectById(id);
|
GenTable table = genTableMapper.selectById(id);
|
||||||
|
Assert.notNull(table, "记录丢失!");
|
||||||
|
|
||||||
List<GenTableColumn> columns = genTableColumnMapper.selectList(
|
List<GenTableColumn> columns = genTableColumnMapper.selectList(
|
||||||
new QueryWrapper<GenTableColumn>()
|
new QueryWrapper<GenTableColumn>()
|
||||||
.eq("table_id", id)
|
.eq("table_id", id)
|
||||||
|
|
@ -357,7 +359,7 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
|
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
Map<String, String> map = new LinkedHashMap<>();
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl());
|
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl(), columns);
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
||||||
|
|
@ -412,7 +414,7 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
VelocityContext context = VelocityUtil.prepareContext(table, columns);
|
VelocityContext context = VelocityUtil.prepareContext(table, columns);
|
||||||
|
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl());
|
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl(), columns);
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
||||||
|
|
@ -451,7 +453,7 @@ public class GenerateServiceImpl implements IGenerateService {
|
||||||
VelocityContext context = VelocityUtil.prepareContext(table, columns);
|
VelocityContext context = VelocityUtil.prepareContext(table, columns);
|
||||||
|
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl());
|
List<String> templates = VelocityUtil.getTemplateList(table.getGenTpl(), columns);
|
||||||
for (String template : templates) {
|
for (String template : templates) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
Template tpl = Velocity.getTemplate(template, GenConstants.UTF8);
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ public class GenUtil {
|
||||||
String tableDesc = map.get("table_comment");
|
String tableDesc = map.get("table_comment");
|
||||||
table.setTableName(tableName);
|
table.setTableName(tableName);
|
||||||
table.setTableComment(tableDesc);
|
table.setTableComment(tableDesc);
|
||||||
table.setAuthorName(GenConfig.authorName);
|
table.setAuthorName(map.getOrDefault("author_name", ""));
|
||||||
table.setEntityName(GenUtil.toClassName(tableName));
|
table.setEntityName(GenUtil.toClassName(tableName));
|
||||||
table.setModuleName(GenUtil.toModuleName(GenConfig.packageName));
|
table.setModuleName(GenUtil.toBusinessName(tableName));
|
||||||
table.setPackageName(GenConfig.packageName);
|
table.setPackageName(GenConfig.packageName);
|
||||||
table.setBusinessName(GenUtil.toBusinessName(tableName));
|
table.setBusinessName(GenUtil.toBusinessName(tableName));
|
||||||
table.setFunctionName(GenUtil.replaceText(tableDesc));
|
table.setFunctionName(GenUtil.replaceText(tableDesc));
|
||||||
|
|
@ -48,10 +48,10 @@ public class GenUtil {
|
||||||
String columnName = column.getColumnName();
|
String columnName = column.getColumnName();
|
||||||
String columnType = GenUtil.getDbType(column.getColumnType());
|
String columnType = GenUtil.getDbType(column.getColumnType());
|
||||||
column.setTableId(table.getId());
|
column.setTableId(table.getId());
|
||||||
|
column.setColumnLength(GenUtil.getColumnLength(column.getColumnType()));
|
||||||
column.setJavaField(StringUtil.toCamelCase(columnName));
|
column.setJavaField(StringUtil.toCamelCase(columnName));
|
||||||
column.setJavaType(JavaConstants.TYPE_STRING);
|
column.setJavaType(JavaConstants.TYPE_STRING);
|
||||||
column.setQueryType(GenConstants.QUERY_EQ);
|
column.setQueryType(GenConstants.QUERY_EQ);
|
||||||
column.setIsInsert(GenConstants.REQUIRE);
|
|
||||||
column.setUpdateTime(table.getUpdateTime());
|
column.setUpdateTime(table.getUpdateTime());
|
||||||
column.setCreateTime(table.getCreateTime());
|
column.setCreateTime(table.getCreateTime());
|
||||||
|
|
||||||
|
|
@ -90,9 +90,15 @@ public class GenUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 需插入字段
|
||||||
|
if (!GenUtil.isArraysContains(SqlConstants.COLUMN_NAME_NOT_ADD, columnName)) {
|
||||||
|
column.setIsInsert(GenConstants.REQUIRE);
|
||||||
|
}
|
||||||
|
|
||||||
// 需编辑字段
|
// 需编辑字段
|
||||||
if (!GenUtil.isArraysContains(SqlConstants.COLUMN_NAME_NOT_EDIT, columnName) && column.getIsPk() == 0) {
|
if (!GenUtil.isArraysContains(SqlConstants.COLUMN_NAME_NOT_EDIT, columnName)) {
|
||||||
column.setIsEdit(GenConstants.REQUIRE);
|
column.setIsEdit(GenConstants.REQUIRE);
|
||||||
|
column.setIsRequired(GenConstants.REQUIRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 需列表字段
|
// 需列表字段
|
||||||
|
|
|
||||||
|
|
@ -58,16 +58,16 @@ public class VelocityUtil {
|
||||||
velocityContext.put("genTpl", table.getGenTpl());
|
velocityContext.put("genTpl", table.getGenTpl());
|
||||||
velocityContext.put("tableName", table.getTableName());
|
velocityContext.put("tableName", table.getTableName());
|
||||||
velocityContext.put("authorName", table.getAuthorName());
|
velocityContext.put("authorName", table.getAuthorName());
|
||||||
|
velocityContext.put("packageName", GenConfig.packageName);
|
||||||
velocityContext.put("EntityName", table.getEntityName());
|
velocityContext.put("EntityName", table.getEntityName());
|
||||||
velocityContext.put("entityName", StringUtil.uncapitalize(table.getEntityName()));
|
velocityContext.put("entityName", StringUtil.uncapitalize(table.getEntityName()));
|
||||||
velocityContext.put("moduleName", table.getModuleName());
|
velocityContext.put("moduleName", table.getModuleName());
|
||||||
velocityContext.put("packageName", table.getPackageName());
|
|
||||||
velocityContext.put("businessName", StringUtil.capitalize(table.getBusinessName()));
|
|
||||||
velocityContext.put("functionName", StringUtil.isNotEmpty(table.getFunctionName()) ? table.getFunctionName() : "【请填写功能名称】");
|
velocityContext.put("functionName", StringUtil.isNotEmpty(table.getFunctionName()) ? table.getFunctionName() : "【请填写功能名称】");
|
||||||
velocityContext.put("table", table);
|
velocityContext.put("table", table);
|
||||||
velocityContext.put("columns", columns);
|
velocityContext.put("columns", columns);
|
||||||
velocityContext.put("fields", fields);
|
velocityContext.put("fields", fields);
|
||||||
velocityContext.put("isSearch", isSearch);
|
velocityContext.put("isSearch", isSearch);
|
||||||
|
velocityContext.put("isEqually", VelocityUtil.getIsEqually(columns));
|
||||||
|
|
||||||
return velocityContext;
|
return velocityContext;
|
||||||
}
|
}
|
||||||
|
|
@ -87,21 +87,47 @@ public class VelocityUtil {
|
||||||
return genPath + File.separator;
|
return genPath + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断需列表字段和查询字段是否一致
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param columns 字段列表
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
public static Boolean getIsEqually(List<GenTableColumn> columns) {
|
||||||
|
StringBuilder listStr = new StringBuilder();
|
||||||
|
StringBuilder queryStr = new StringBuilder();
|
||||||
|
for (GenTableColumn col : columns) {
|
||||||
|
if (col.getIsList() == 1) {
|
||||||
|
listStr.append(",").append(col.getColumnName());
|
||||||
|
}
|
||||||
|
if (col.getIsQuery() == 1) {
|
||||||
|
queryStr.append(",").append(col.getColumnName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return listStr.toString().equals(queryStr.toString());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取模板列表
|
* 获取模板列表
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @return List<String>
|
* @return List<String>
|
||||||
*/
|
*/
|
||||||
public static List<String> getTemplateList(String genTpl) {
|
public static List<String> getTemplateList(String genTpl, List<GenTableColumn> columns) {
|
||||||
List<String> templates = new LinkedList<>();
|
List<String> templates = new LinkedList<>();
|
||||||
templates.add("java/controller.java.vm");
|
templates.add("java/controller.java.vm");
|
||||||
templates.add("java/entity.java.vm");
|
// templates.add("java/entity.java.vm");
|
||||||
templates.add("java/mapper.java.vm");
|
// templates.add("java/mapper.java.vm");
|
||||||
templates.add("java/service.java.vm");
|
// templates.add("java/service.java.vm");
|
||||||
templates.add("java/serviceImpl.java.vm");
|
// templates.add("java/serviceImpl.java.vm");
|
||||||
templates.add("java/validate.java.vm");
|
// templates.add("java/validate.java.vm");
|
||||||
templates.add("java/vo.java.vm");
|
// if (VelocityUtil.getIsEqually(columns)) {
|
||||||
|
// templates.add("java/vo.java.vm");
|
||||||
|
// } else {
|
||||||
|
// templates.add("java/voList.java.vm");
|
||||||
|
// templates.add("java/voDetail.java.vm");
|
||||||
|
// }
|
||||||
// if (GenConstants.TPL_CRUD.equals(genTpl)) {
|
// if (GenConstants.TPL_CRUD.equals(genTpl)) {
|
||||||
// templates.add("vue/index.vue.vm");
|
// templates.add("vue/index.vue.vm");
|
||||||
// }
|
// }
|
||||||
|
|
@ -117,43 +143,34 @@ public class VelocityUtil {
|
||||||
public static String getFileName(String template, GenTable genTable) {
|
public static String getFileName(String template, GenTable genTable) {
|
||||||
String fileName = "";
|
String fileName = "";
|
||||||
String entityName = genTable.getEntityName();
|
String entityName = genTable.getEntityName();
|
||||||
String packageName = genTable.getPackageName();
|
|
||||||
String moduleName = genTable.getModuleName();
|
String moduleName = genTable.getModuleName();
|
||||||
String[] arrPackage = packageName.split("\\.");
|
|
||||||
|
|
||||||
// 生成路径
|
|
||||||
String javaPath = StringUtil.replace(packageName, ".", "/");
|
|
||||||
String basePackage = arrPackage[0] + "/" + arrPackage[1]+"/";
|
|
||||||
String commonPackage = GenConfig.commonApp + basePackage + "common";
|
|
||||||
String mainPackage = StringUtil.format(GenConfig.mainApp, arrPackage.length>=3?arrPackage[2]:"admin")+javaPath;
|
|
||||||
String subPackage = !moduleName.equals("") ? StringUtil.replace(moduleName, ".", "/") + "/" : "";
|
|
||||||
|
|
||||||
if (template.contains("mapper.java.vm")) {
|
if (template.contains("mapper.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/mapper/{}{}Mapper.java", commonPackage, subPackage, entityName);
|
fileName = StringUtil.format("{}/mapper/{}/{}Mapper.java", GenConfig.commonPackage, moduleName, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("entity.java.vm")) {
|
else if (template.contains("entity.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/entity/{}{}Entity.java", commonPackage, subPackage, entityName);
|
fileName = StringUtil.format("{}/entity/{}/{}Entity.java", GenConfig.commonPackage, moduleName, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("service.java.vm")) {
|
else if (template.contains("service.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/service/I{}Service.java", mainPackage, entityName);
|
fileName = StringUtil.format("{}/service/{}/I{}Service.java", GenConfig.adminPackage, moduleName, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("serviceImpl.java.vm")) {
|
else if (template.contains("serviceImpl.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/service/impl/{}ServiceImpl.java", mainPackage, entityName);
|
fileName = StringUtil.format("{}/service/{}/impl/{}ServiceImpl.java", GenConfig.adminPackage, moduleName, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("controller.java.vm")) {
|
else if (template.contains("controller.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/controller/{}{}Controller.java", mainPackage, subPackage, entityName);
|
fileName = StringUtil.format("{}/controller/{}/{}Controller.java", GenConfig.adminPackage, moduleName, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("validate.java.vm")) {
|
else if (template.contains("validate.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/validate/{}{}Param.java", mainPackage, subPackage, entityName);
|
fileName = StringUtil.format("{}/validate/{}/{}Param.java", GenConfig.adminPackage, moduleName, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (template.contains("vo.java.vm")) {
|
else if (template.contains("vo.java.vm")) {
|
||||||
fileName = StringUtil.format("{}/vo/{}{}Vo.java", mainPackage, subPackage, entityName);
|
fileName = StringUtil.format("{}/vo/{}/{}Vo.java", GenConfig.adminPackage, moduleName, entityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileName;
|
return fileName;
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,10 @@ public class GenColumnVo implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Integer id; // 主键
|
private Integer id; // 字段主键
|
||||||
private String columnName; // 字段名称
|
private String columnName; // 字段名称
|
||||||
private String columnComment; // 字段描述
|
private String columnComment; // 字段描述
|
||||||
|
private Integer columnLength; // 字段长度
|
||||||
private String columnType; // 字段类型
|
private String columnType; // 字段类型
|
||||||
private String javaType; // JAVA类型
|
private String javaType; // JAVA类型
|
||||||
private String javaField; // JAVA字段
|
private String javaField; // JAVA字段
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import lombok.Data;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成表实体
|
* 生成列表Vo
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class GenTableVo implements Serializable {
|
public class GenTableVo implements Serializable {
|
||||||
|
|
@ -13,7 +13,6 @@ public class GenTableVo implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Integer id; // 生成主键
|
private Integer id; // 生成主键
|
||||||
private String genTpl; // 生成模板
|
|
||||||
private String tableName; // 表的名称
|
private String tableName; // 表的名称
|
||||||
private String tableComment; // 表的描述
|
private String tableComment; // 表的描述
|
||||||
private String createTime; // 创建时间
|
private String createTime; // 创建时间
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
package ${packageName}.controller;
|
package ${packageName}.admin.controller.${moduleName};
|
||||||
|
|
||||||
import com.hxkj.admin.LikeAdminThreadLocal;
|
import ${packageName}.admin.config.aop.Log;
|
||||||
import com.hxkj.admin.config.aop.Log;
|
import ${packageName}.admin.service.${moduleName}.I${EntityName}Service;
|
||||||
import com.hxkj.admin.service.I${EntityName}Service;
|
import ${packageName}.admin.validate.PageParam;
|
||||||
import com.hxkj.admin.validate.PageParam;
|
import ${packageName}.admin.validate.${moduleName}.${EntityName}Param;
|
||||||
import com.hxkj.admin.validate.system.${EntityName}Param;
|
#if($isEqually)
|
||||||
import com.hxkj.admin.vo.system.${EntityName}Vo;
|
import ${packageName}.admin.vo.${moduleName}.${EntityName}Vo;
|
||||||
import com.hxkj.common.core.AjaxResult;
|
#else
|
||||||
import com.hxkj.common.core.PageResult;
|
import ${packageName}.admin.vo.${moduleName}.${EntityName}ListVo;
|
||||||
import com.hxkj.common.validator.annotation.IDMust;
|
import ${packageName}.admin.vo.${moduleName}.${EntityName}DetailVo;
|
||||||
|
#end
|
||||||
|
import ${packageName}.common.core.AjaxResult;
|
||||||
|
import ${packageName}.common.core.PageResult;
|
||||||
|
import ${packageName}.common.validator.annotation.IDMust;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
@ -19,8 +23,8 @@ import java.util.Map;
|
||||||
* ${functionName}管理
|
* ${functionName}管理
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("api/${moduleName}/${businessName}")
|
@RequestMapping("api/${moduleName}")
|
||||||
public class ${ClassName}Controller {
|
public class ${EntityName}Controller {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
I${EntityName}Service i${EntityName}AdminService;
|
I${EntityName}Service i${EntityName}AdminService;
|
||||||
|
|
@ -28,61 +32,74 @@ public class ${ClassName}Controller {
|
||||||
/**
|
/**
|
||||||
* ${functionName}列表
|
* ${functionName}列表
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
|
* @param pageParam 分页参数
|
||||||
|
* @param params 搜索参数
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Object list(@Validated PageParam pageParam,
|
public Object list(@Validated PageParam pageParam,
|
||||||
@RequestParam Map<String, String> params) {
|
@RequestParam Map<String, String> params) {
|
||||||
PageResult<${EntityName}Vo> list = i${EntityName}Service.list(pageParam, params);
|
PageResult<${EntityName}ListVo> list = i${EntityName}Service.list(pageParam, params);
|
||||||
return AjaxResult.success(list);
|
return AjaxResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}详情
|
* ${functionName}详情
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
* @param id 主键ID
|
* @param id 主键ID
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@GetMapping("/detail")
|
@GetMapping("/detail")
|
||||||
public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||||
${EntityName}Vo vo = i${EntityName}Service.detail(id);
|
${EntityName}DetailVo detail = i${EntityName}Service.detail(id);
|
||||||
return AjaxResult.success(vo);
|
return AjaxResult.success(detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}新增
|
* ${functionName}新增
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
* @param ${entityName}Param 参数
|
* @param ${entityName}Param 参数
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@Log(title = "${functionName}新增")
|
@Log(title = "${functionName}新增")
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public Object add(@Validated(value = ${EntityName}Param.create.class) @RequestBody ${EntityName}Param ${entityName}Param) {
|
public Object add(@Validated(value = ${EntityName}Param.create.class) @RequestBody ${EntityName}Param ${entityName}Param) {
|
||||||
i${EntityName}Service.add(systemAdminParam);
|
i${EntityName}Service.add(${entityName}Param);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}编辑
|
* ${functionName}编辑
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
* @param ${entityName}Param 参数
|
* @param ${entityName}Param 参数
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@Log(title = "${functionName}编辑")
|
@Log(title = "${functionName}编辑")
|
||||||
@PostMapping("/edit")
|
@PostMapping("/edit")
|
||||||
public Object edit(@Validated(value = ${EntityName}Param.update.class}) @RequestBody ${EntityName}Param} ${entityName}Param}) {
|
public Object edit(@Validated(value = ${EntityName}Param.update.class}) @RequestBody ${EntityName}Param ${entityName}Param}) {
|
||||||
i${EntityName}Service.edit(${entityName}Param});
|
i${EntityName}Service.edit(${entityName}Param);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}删除
|
* ${functionName}删除
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
|
* @param ${entityName}Param 参数
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@Log(title = "${functionName}删除")
|
@Log(title = "${functionName}删除")
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ public class ${entityName} implements Serializable {
|
||||||
#if($column.isPk)
|
#if($column.isPk)
|
||||||
@TableId(value="${column.columnName}", type= IdType.AUTO)
|
@TableId(value="${column.columnName}", type= IdType.AUTO)
|
||||||
#end
|
#end
|
||||||
private ${column.javaType} ${column.javaField};
|
private ${column.javaType} ${column.javaField}; // ${column.columnComment}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package com.hxkj.common.mapper;
|
package com.hxkj.common.mapper;
|
||||||
|
|
||||||
import com.hxkj.common.core.basics.IBaseMapper;
|
import com.hxkj.common.core.basics.IBaseMapper;
|
||||||
import com.hxkj.common.entity.${EntityName};
|
import com.hxkj.common.entity.${entityName}.${EntityName};
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}
|
* ${functionName}Mapper
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ${EntityName}Mapper extends IBaseMapper<${EntityName}> {
|
public interface ${EntityName}Mapper extends IBaseMapper<${EntityName}> {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package com.hxkj.admin.service;
|
package com.hxkj.admin.service;
|
||||||
|
|
||||||
import com.hxkj.admin.validate.PageParam;
|
import com.hxkj.admin.validate.PageParam;
|
||||||
import com.hxkj.admin.validate.${EntityName}Param;
|
import com.hxkj.admin.validate.${entityName}.${EntityName}Param;
|
||||||
#if($table.genTpl=="curd")
|
#if($table.genTpl=="curd")
|
||||||
import com.hxkj.admin.vo.system.${EntityName}Vo;
|
import com.hxkj.admin.vo.${entityName}.${EntityName}Vo;
|
||||||
#end
|
#end
|
||||||
import com.hxkj.common.core.PageResult;
|
import com.hxkj.common.core.PageResult;
|
||||||
import com.hxkj.common.entity.${EntityName};
|
import com.hxkj.common.entity.${EntityName};
|
||||||
|
|
@ -19,18 +19,22 @@ public interface I${EntityName}Service {
|
||||||
/**
|
/**
|
||||||
* ${functionName}列表
|
* ${functionName}列表
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
* @param pageParam 分页参数
|
* @param pageParam 分页参数
|
||||||
* @param params 搜索参数
|
* @param params 搜索参数
|
||||||
* @return PageResult<${EntityName}Vo}>
|
* @return PageResult<${EntityName}Vo}>
|
||||||
*/
|
*/
|
||||||
PageResult<${EntityName}Vo> list(PageParam pageParam, Map<String, String> params);
|
PageResult<${EntityName}ListVo> list(PageParam pageParam, Map<String, String> params);
|
||||||
#elseif($table.genTpl=="tree")
|
#elseif($table.genTpl=="tree")
|
||||||
/**
|
/**
|
||||||
* ${functionName}列表
|
* ${functionName}列表
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
* @param params 搜索参数
|
#end
|
||||||
|
* @param params 搜索参数
|
||||||
* @return JSONArray
|
* @return JSONArray
|
||||||
*/
|
*/
|
||||||
JSONArray list(Map<String, String> params);
|
JSONArray list(Map<String, String> params);
|
||||||
|
|
@ -39,7 +43,9 @@ public interface I${EntityName}Service {
|
||||||
/**
|
/**
|
||||||
* ${functionName}详情
|
* ${functionName}详情
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
* @param id 主键ID
|
* @param id 主键ID
|
||||||
* @return ${EntityName}
|
* @return ${EntityName}
|
||||||
*/
|
*/
|
||||||
|
|
@ -48,7 +54,9 @@ public interface I${EntityName}Service {
|
||||||
/**
|
/**
|
||||||
* ${functionName}新增
|
* ${functionName}新增
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
* @param ${entityName}Param 参数
|
* @param ${entityName}Param 参数
|
||||||
*/
|
*/
|
||||||
void add(${EntityName}Param ${entityName}Param);
|
void add(${EntityName}Param ${entityName}Param);
|
||||||
|
|
@ -56,7 +64,9 @@ public interface I${EntityName}Service {
|
||||||
/**
|
/**
|
||||||
* ${functionName}编辑
|
* ${functionName}编辑
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
* @param ${entityName}Param 参数
|
* @param ${entityName}Param 参数
|
||||||
*/
|
*/
|
||||||
void edit(${EntityName}Param ${entityName}Param);
|
void edit(${EntityName}Param ${entityName}Param);
|
||||||
|
|
@ -64,7 +74,9 @@ public interface I${EntityName}Service {
|
||||||
/**
|
/**
|
||||||
* ${functionName}删除
|
* ${functionName}删除
|
||||||
*
|
*
|
||||||
|
#if(!$authorName.equals(""))
|
||||||
* @author ${authorName}
|
* @author ${authorName}
|
||||||
|
#end
|
||||||
* @param id 主键ID
|
* @param id 主键ID
|
||||||
*/
|
*/
|
||||||
void del(Integer id);
|
void del(Integer id);
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,19 @@ public class ${EntityName}Param implements Serializable {
|
||||||
@IDMust(message = "${column.javaField}参数必传且需大于0", groups = {update.class, delete.class})
|
@IDMust(message = "${column.javaField}参数必传且需大于0", groups = {update.class, delete.class})
|
||||||
#end
|
#end
|
||||||
#if(!$column.isPk && $column.isRequired)
|
#if(!$column.isPk && $column.isRequired)
|
||||||
@NotNull(message = "${column.javaField}参数缺失", groups = {create.class, update.class})
|
@NotNull(message = "${column.javaField}参数缺失", groups = {#if($column.isInsert)create.class#end#if($column.isInsert&&$column.isEdit), #end#if($column.isEdit)update.class#end})
|
||||||
|
#end
|
||||||
|
#if(!$column.isPk && $column.javaType.equals("String"))
|
||||||
|
@Length(max = ${column.columnLength}, message = "${column.javaField}参数不能超出${column.columnLength}个字符", groups = {#if($column.isInsert)create.class#end#if($column.isInsert&&$column.isEdit), #end#if($column.isEdit)update.class#end})
|
||||||
|
#end
|
||||||
|
#if(!$column.isPk && $column.javaField.substring(0,2)!="is" && ($column.javaType.equals("Integer") || $column.javaType.equals("Long")))
|
||||||
|
@DecimalMin(value = 0, message = "${column.javaField}参数值不能少于0", groups = {#if($column.isInsert)create.class#end#if($column.isInsert&&$column.isEdit), #end#if($column.isEdit)update.class#end})
|
||||||
|
#end
|
||||||
|
#if(!$column.isPk && $column.javaField.substring(0,2)=="is" && $column.javaType.equals("Integer"))
|
||||||
|
@IntegerContains(values = {0, 1}, message = "${column.javaField}参数值不在符合范围", groups = {#if($column.isInsert)create.class#end#if($column.isInsert&&$column.isEdit), #end#if($column.isEdit)update.class#end})
|
||||||
#end
|
#end
|
||||||
private ${column.javaType} ${column.javaField};
|
private ${column.javaType} ${column.javaField};
|
||||||
#end
|
|
||||||
|
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ public class ${EntityName}Vo implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.isList==1)
|
#if($column.isList==1 || $column.isQuery==1)
|
||||||
#if($column.javaField.equals("createTime") || $column.javaField.equals("updateTime") || $column.javaField.equals("deleteTime"))
|
#if($column.javaField.equals("createTime") || $column.javaField.equals("updateTime") || $column.javaField.equals("deleteTime"))
|
||||||
private String ${column.javaField};
|
private String ${column.javaField};
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.hxkj.admin.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${EntityName}Vo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ${EntityName}DetailVo implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.isQuery==1)
|
||||||
|
#if($column.javaField.equals("createTime") || $column.javaField.equals("updateTime") || $column.javaField.equals("deleteTime"))
|
||||||
|
private String ${column.javaField};
|
||||||
|
#else
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.hxkj.admin.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${EntityName}Vo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ${EntityName}ListVo implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.isList==1)
|
||||||
|
#if($column.javaField.equals("createTime") || $column.javaField.equals("updateTime") || $column.javaField.equals("deleteTime"))
|
||||||
|
private String ${column.javaField};
|
||||||
|
#else
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue