SpringBoot利用FreeMarker渲染指定模板


 
<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,分布式,微服务。 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM