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