<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
SpringBoot利用FreeMarker渲染指定模板

模板位置

注: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);
SpringBoot利用FreeMarker渲染指定模板

结果:

                                                                        微信公众号

                                               

                                                                             JAVA程序猿成长之路

                          分享资源,记录程序猿成长点滴。专注于Java,Spring,SpringBoot,SpringCloud,分布式,微服务。 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2021-07-17
  • 2021-11-19
  • 2021-12-18
  • 2021-05-19
  • 2021-09-10
猜你喜欢
  • 2021-05-22
  • 2021-11-12
  • 2021-08-15
  • 2022-02-08
  • 2022-12-23
  • 2021-07-01
相关资源
相似解决方案