freemarker依赖
Posted zfzf1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了freemarker依赖相关的知识,希望对你有一定的参考价值。
<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();
以上是关于freemarker依赖的主要内容,如果未能解决你的问题,请参考以下文章