标签:string rect style obj try locale -- ati temp
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.ftl</include>
</includes>
<!-- activate spring profile -->
<filtering>true</filtering>
</resource>
import freemarker.template.Configuration; import freemarker.template.DefaultObjectWrapper; import freemarker.template.Template; import freemarker.template.TemplateException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; import java.util.Locale; import java.util.Map; public class FreeMarkerUtil { private final static Logger logger = LoggerFactory.getLogger(FreeMarkerUtil.class); private static Configuration conf = null; static { conf = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); conf.setClassForTemplateLoading(FreeMarkerUtil.class, "/com/yung/view"); conf.setObjectWrapper(new DefaultObjectWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS)); conf.setLocale(Locale.CHINA); conf.setDefaultEncoding("utf-8"); conf.setClassicCompatible(true); } public static String getString(Map<String,Object> root,String tplName) { Writer out = new StringWriter(2048); try { Template temp = conf.getTemplate(tplName); temp.process(root, out); } catch (IOException e) { logger.error(e.getMessage(),e); } catch (TemplateException e) { logger.error(e.getMessage(),e); } return out.toString(); } }
标签:string rect style obj try locale -- ati temp
原文地址:https://www.cnblogs.com/zfzf1/p/11277268.html