<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
模板位置
注:springboot中freemarker默认读取位置
核心代码:
Template t = configuration.getTemplate("activeUserTemplate.ftl", "UTF-8"); Map<String, Object> map = new HashMap<>(); map.put("loginName","张三"); map.put("activeUserUrl","https://www.jianshu.com/p/4e8c6cb1ddad"); map.put("dateTime","2019-04-12"); String string = FreeMarkerTemplateUtils.processTemplateIntoString(t, map); File file = new File("D:\welocme.html"); FileUtils.writeStringToFile(file,string);
结果:
微信公众号
JAVA程序猿成长之路
分享资源,记录程序猿成长点滴。专注于Java,Spring,SpringBoot,SpringCloud,分布式,微服务。