org.springframework.boot
spring-boot-starter-freemarker
1.5.9.RELEASE
org.springframework
spring-webmvc
org.springframework
spring-context-support
String templatevalue = "hello,我是${name}";//模板
String htmlStr = "";//输出模板内容
Map dataModel = new HashMap<>();
dataModel.put("name", "张三");//封装参数
String templateName = "test-template";//名字随便起一个
Configuration configuration = configuration();
Template template = new Template(templateName, templatevalue, configuration);//参数填充模板
htmlStr = FreeMarkerTemplateUtils.processTemplateIntoString(template, dataModel);
private Configuration configuration() {
Configuration configuration = new Configuration(Configuration.VERSION_2_3_27);
StringTemplateLoader templateLoader = new StringTemplateLoader();
configuration.setTemplateLoader(templateLoader);
configuration.setDefaultEncoding("UTF-8");
return configuration;
}