Skip to content

Commit

Permalink
revert(generator): 还原静态模型变量设置,修复 Menu.ftl 生成报错
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jan 8, 2025
1 parent d12c68d commit ee46e47
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.TemplateUtil;
import cn.hutool.extra.template.engine.freemarker.FreemarkerEngine;
import cn.hutool.system.SystemUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.DefaultObjectWrapperBuilder;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -289,6 +293,11 @@ private List<GeneratePreviewResp> preview(String tableName) {
Map<String, GeneratorProperties.TemplateConfig> templateConfigMap = generatorProperties.getTemplateConfigs();
TemplateEngine engine = TemplateUtil
.createEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));
// 在模板中允许使用静态方法
if (engine instanceof FreemarkerEngine freemarkerEngine) {
DefaultObjectWrapper wrapper = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_33).build();
freemarkerEngine.getConfiguration().setSharedVariable("statics", wrapper.getStaticModels());
}
for (Map.Entry<String, GeneratorProperties.TemplateConfig> templateConfigEntry : templateConfigMap.entrySet()) {
GeneratorProperties.TemplateConfig templateConfig = templateConfigEntry.getValue();
// 移除需要忽略的字段
Expand Down

0 comments on commit ee46e47

Please sign in to comment.