Files
hutool/hutool-extra/src/test/java/cn/hutool/extra/template/VelocityTest.java

22 lines
741 B
Java
Raw Normal View History

2021-01-20 17:10:45 +08:00
package cn.hutool.extra.template;
2022-04-28 03:31:23 +08:00
import cn.hutool.core.map.Dict;
2021-01-20 17:10:45 +08:00
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.extra.template.engine.velocity.VelocityEngine;
import org.junit.Assert;
import org.junit.Test;
public class VelocityTest {
@Test
public void charsetTest(){
final TemplateConfig config = new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH);
config.setCustomEngine(VelocityEngine.class);
config.setCharset(CharsetUtil.CHARSET_GBK);
final TemplateEngine engine = TemplateUtil.createEngine(config);
Template template = engine.getTemplate("velocity_test_gbk.vtl");
String result = template.render(Dict.create().set("name", "hutool"));
Assert.assertEquals("你好,hutool", result);
}
}