diff --git a/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/model/entity/GenConfigDO.java b/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/model/entity/GenConfigDO.java index b171eae64..3b2167049 100644 --- a/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/model/entity/GenConfigDO.java +++ b/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/model/entity/GenConfigDO.java @@ -16,6 +16,7 @@ package top.continew.admin.generator.model.entity; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.annotation.*; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; @@ -25,6 +26,7 @@ import lombok.NoArgsConstructor; import org.hibernate.validator.constraints.Length; import top.continew.admin.common.constant.RegexConstants; +import top.continew.starter.core.constant.StringConstants; import java.io.Serial; import java.io.Serializable; @@ -114,6 +116,15 @@ public class GenConfigDO implements Serializable { private LocalDateTime updateTime; public GenConfigDO(String tableName) { + this.setTableName(tableName); + } + + public void setTableName(String tableName) { this.tableName = tableName; + // 默认表前缀(sys_user -> sys_) + int underLineIndex = StrUtil.indexOf(tableName, StringConstants.C_UNDERLINE); + if (-1 != underLineIndex) { + this.tablePrefix = StrUtil.subPre(tableName, underLineIndex + 1); + } } } diff --git a/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java b/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java index 190c430fc..f2ba467e3 100644 --- a/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java +++ b/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java @@ -125,11 +125,6 @@ public GenConfigDO getGenConfig(String tableName) throws SQLException { if (null != lastGenConfig) { genConfig.setAuthor(lastGenConfig.getAuthor()); } - // 默认表前缀(sys_user -> sys_) - int underLineIndex = StrUtil.indexOf(tableName, StringConstants.C_UNDERLINE); - if (-1 != underLineIndex) { - genConfig.setTablePrefix(StrUtil.subPre(tableName, underLineIndex + 1)); - } } return genConfig; } @@ -245,19 +240,16 @@ public List preview(String tableName) { GeneratePreviewResp generatePreview = new GeneratePreviewResp(); generatePreview.setBackend(isBackend); generatePreviewList.add(generatePreview); - if (isBackend) { - generatePreview.setFileName(className + extension); - generatePreview.setContent(TemplateUtils.render(templateConfig.getTemplatePath(), BeanUtil - .beanToMap(innerGenConfig))); - } else { - generatePreview.setFileName(".vue".equals(extension) && "index".equals(classNameSuffix) + String fileName = className + extension; + if (!isBackend) { + fileName = ".vue".equals(extension) && "index".equals(classNameSuffix) ? "index.vue" - : this.getFrontendFileName(classNamePrefix, className, extension)); - innerGenConfig.setFieldConfigs(fieldConfigList); - generatePreview.setContent(TemplateUtils.render(templateConfig.getTemplatePath(), BeanUtil - .beanToMap(innerGenConfig))); + : this.getFrontendFileName(classNamePrefix, className, extension); } - setPreviewPath(generatePreview, innerGenConfig, templateConfig); + generatePreview.setFileName(fileName); + generatePreview.setContent(TemplateUtils.render(templateConfig.getTemplatePath(), BeanUtil + .beanToMap(innerGenConfig))); + this.setPreviewPath(generatePreview, innerGenConfig, templateConfig); } return generatePreviewList; }