springBoot 代码生成基础配置生成返回预览 /codeGenerate/runFileContent
This commit is contained in:
parent
820f17dd6b
commit
c7e0309a4e
@ -157,4 +157,24 @@ public class CodeGenerateController {
|
||||
}
|
||||
this.codeGenerateService.runDown(codeGenerateParam, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码生成基础配置生成返回预览
|
||||
*
|
||||
* @author Sam
|
||||
* @date 2022-02-11 01:55:48
|
||||
*/
|
||||
@Permission
|
||||
@GetMapping("/codeGenerate/runFileContent")
|
||||
@BusinessLog(title = "代码生成_返回预览", opType = LogAnnotionOpTypeEnum.QUERY)
|
||||
public ResponseData runFileContent(@Validated(CodeGenerateParam.detail.class) CodeGenerateParam codeGenerateParam) {
|
||||
|
||||
// 演示环境开启,则不允许操作
|
||||
if (ConstantContextHolder.getDemoEnvFlag()) {
|
||||
throw new DemoException();
|
||||
}
|
||||
|
||||
return ResponseData.success(this.codeGenerateService.runFileContent(codeGenerateParam));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright [2020] [https://www.xiaonuo.vip]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
|
||||
1.请不要删除和修改根目录下的LICENSE文件。
|
||||
2.请不要删除和修改Snowy源码头部的版权声明。
|
||||
3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
|
||||
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
|
||||
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
package vip.xiaonuo.generate.modular.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 文件内容返回对象
|
||||
*
|
||||
* @author Sam
|
||||
* @datetime 2022年02月07日20:01:56
|
||||
*/
|
||||
@Data
|
||||
public class FileContentResult {
|
||||
|
||||
/**
|
||||
* 文件名称(字母形式的)
|
||||
*/
|
||||
public String fileName;
|
||||
|
||||
/**
|
||||
* 文件内容
|
||||
*/
|
||||
public String fileContent;
|
||||
|
||||
public FileContentResult() {
|
||||
|
||||
}
|
||||
|
||||
public FileContentResult(String name, String content) {
|
||||
fileName = name;
|
||||
fileContent = content;
|
||||
}
|
||||
|
||||
}
|
@ -28,6 +28,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import vip.xiaonuo.core.pojo.page.PageResult;
|
||||
import vip.xiaonuo.generate.modular.entity.CodeGenerate;
|
||||
import vip.xiaonuo.generate.modular.param.CodeGenerateParam;
|
||||
import vip.xiaonuo.generate.modular.result.FileContentResult;
|
||||
import vip.xiaonuo.generate.modular.result.InformationResult;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -104,4 +105,12 @@ public interface CodeGenerateService extends IService<CodeGenerate> {
|
||||
* @date 2020年12月16日21:03:15
|
||||
*/
|
||||
void runDown(CodeGenerateParam codeGenerateParam, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 获取文件内容
|
||||
*
|
||||
* @author Sam
|
||||
* @datetime 2022年02月07日20:01:56
|
||||
*/
|
||||
List<FileContentResult> runFileContent(CodeGenerateParam codeGenerateParam);
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ import vip.xiaonuo.generate.modular.enums.CodeGenerateExceptionEnum;
|
||||
import vip.xiaonuo.generate.modular.mapper.CodeGenerateMapper;
|
||||
import vip.xiaonuo.generate.modular.param.CodeGenerateParam;
|
||||
import vip.xiaonuo.generate.modular.param.SysCodeGenerateConfigParam;
|
||||
import vip.xiaonuo.generate.modular.result.FileContentResult;
|
||||
import vip.xiaonuo.generate.modular.result.InforMationColumnsResult;
|
||||
import vip.xiaonuo.generate.modular.result.InformationResult;
|
||||
import vip.xiaonuo.generate.modular.service.CodeGenerateService;
|
||||
@ -57,6 +58,7 @@ import vip.xiaonuo.generate.modular.service.SysCodeGenerateConfigService;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@ -180,6 +182,12 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
|
||||
downloadCode(xnCodeGenParam, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileContentResult> runFileContent(CodeGenerateParam codeGenerateParam) {
|
||||
XnCodeGenParam xnCodeGenParam = copyParams(codeGenerateParam);
|
||||
return fileContentCode(xnCodeGenParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验表中是否包含主键
|
||||
*
|
||||
@ -216,6 +224,36 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件内容化代码基础
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2020年12月23日 00点32分
|
||||
*/
|
||||
private List<FileContentResult> fileContentCode(XnCodeGenParam xnCodeGenParam) {
|
||||
Util.initVelocity();
|
||||
XnVelocityContext context = new XnVelocityContext();
|
||||
|
||||
List<FileContentResult> reList = new ArrayList<>();
|
||||
String[] filePath = GenConstant.xnCodeGenFilePath(xnCodeGenParam.getBusName(), xnCodeGenParam.getPackageName());
|
||||
for (int a = 0; a < filePath.length; a++) {
|
||||
String templateName = GenConstant.xnCodeGenTempFile[a];
|
||||
String fileBaseName = ResetFileBaseName(xnCodeGenParam.getClassName(),
|
||||
templateName.substring(templateName.indexOf(GenConstant.FILE_SEP) + 1, templateName.lastIndexOf(TEMP_SUFFIX)));
|
||||
|
||||
VelocityContext velContext = context.createVelContext(xnCodeGenParam);
|
||||
String tempName = GenConstant.templatePath + templateName;
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(tempName, ENCODED);
|
||||
tpl.merge(velContext, sw);
|
||||
|
||||
FileContentResult fcResult = new FileContentResult(fileBaseName, sw.toString());
|
||||
reList.add(fcResult);
|
||||
}
|
||||
|
||||
return reList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表中所有字段集合
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user