Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxueli committed Sep 30, 2024
1 parent 7dbd80e commit e427da7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 45 deletions.
5 changes: 5 additions & 0 deletions doc/XXL-TOOL官方文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ logger.info(text);
- 3、新增Pipeline模块,高扩展性流程编排引擎;
- 4、新增Freemarker模块,模板引擎工具,支持根据模板文件生成文本、生成文件…等。

### 3.6 v1.3.1 Release Notes[迭代中]
- 1、现有工具完善,包括:StringTool、GsonTool等;
- 2、新增工具,包括:FreemarkerTool、CookieTool、PageModel、CacheTool等;
- 3、完善单测;

### TODO LIST
- excel模块
- 1、单个Excel多Sheet导出导出;
Expand Down
38 changes: 34 additions & 4 deletions src/main/java/com/xxl/tool/freemarker/FreemarkerTool.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.xxl.tool.freemarker;

import com.xxl.tool.exception.BizException;
import freemarker.core.TemplateClassResolver;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.beans.BeansWrapperBuilder;
import freemarker.template.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -112,4 +112,34 @@ public static String processString(Configuration freemarkerConfig, String templa
return htmlText;
}

// ---------------------- process string data by template ----------------------
/**
* 静态包装器
* //BeansWrapper.getDefaultInstance();
*/
private static BeansWrapper wrapper = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build();

/**
* 生成 freemarker 自定义方法
*
* <pre>
* // 自定义方法包装;
* TemplateHashModel model = FreemarkerTool.generateStaticModel(I18nUtil.class.getName())
* // 注入SpringMVC响应对象,逻辑运营在 “AsyncHandlerInterceptor.postHandle” 中;
* modelAndView.addObject("I18nUtil", model);
* </pre>
*
* @param packageName
* @return
*/
public static TemplateHashModel generateStaticModel(String packageName) {
try {
TemplateHashModel staticModels = wrapper.getStaticModels();
TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
return fileStatics;
} catch (Exception e) {
throw new BizException(e);
}
}

}
41 changes: 0 additions & 41 deletions src/main/java/com/xxl/tool/ftl/FtlTool.java

This file was deleted.

0 comments on commit e427da7

Please sign in to comment.