当前使用版本(必填,否则不予处理)
版本3.5.3.1
`package com.baomidou.mybatisplus.generator.config.rules;
import java.util.Map;
/
* 自定义保存路径
*/
public interface CustomPath {
public String getCustomPath(Map然后CustomFile类中新增一个属性和方法/然后Builder静态类里面加一句 /
* 扩展方法
* @param customPath
* @return
/
public Builder customPath(CustomPath customPath){
this.customFile.customPath = customPath;
return this;
}`
最后就是AbstractTemplateEngine类中
/**
* 输出自定义模板文件
*
* @param customFiles 自定义模板文件列表
* @param tableInfo 表信息
* @param objectMap 渲染数据
* @since 3.5.3
*/
protected void outputCustomFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
String entityName = tableInfo.getEntityName();
String parentPath = getPathInfo(OutputFile.parent);
customFiles.forEach(file -> {
String filePath = StringUtils.isNotBlank(file.getFilePath()) ? file.getFilePath() : parentPath;
if (StringUtils.isNotBlank(file.getPackageName())) {
filePath = filePath + File.separator + file.getPackageName().replaceAll("\\.", StringPool.BACK_SLASH + File.separator);
}
// String fileName = filePath + File.separator + entityName + file.getFileName();
//修改源码新增getCustomPath方法实现自定义路径保存
String fileName = filePath + File.separator + ((file.getCustomPath() != null) ? file.getCustomPath().getCustomPath(objectMap) : entityName )+ file.getFileName();
outputFile(new File(fileName), objectMap, file.getTemplatePath(), file.isFileOverride());
});
}
目前用这个方法解决了表单生成的问题,感谢官方~
Comment From: nieqiurong
太乱了,重新排版描述一下.
Comment From: qmdx
描述不是很清楚,具体自定义文件路径新版是支持配置的,可以参考文档 https://baomidou.com/pages/981406 如果与你需求不服可以打开该问题重新反馈。
/**
* 代码生成器支持自定义[DTO\VO等]模版
*/
public final class EnhanceFreemarkerTemplateEngine extends FreemarkerTemplateEngine {
@Override
protected void outputCustomFile(@NotNull Map<String, String> customFile, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
String entityName = tableInfo.getEntityName();
String otherPath = this.getPathInfo(OutputFile.other);
customFile.forEach((key, value) -> {
String fileName = String.format(otherPath + File.separator + entityName + "%s", key);
this.outputFile(new File(fileName), objectMap, value);
});
}
}
.injectionConfig(consumer -> {
Map<String, String> customFile = new HashMap<>();
// DTO
customFile.put("DTO.java", "/templates/entityDTO.java.ftl");
consumer.customFile(customFile);
});
Comment From: freshgeek
链接已经失效了