zoukankan      html  css  js  c++  java
  • 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,分布式,微服务。 

  • 相关阅读:
    客户(项目)经理应具备那些基本心理素质
    js 添加数组 删除数组
    c# ifram 刷新父页面
    [转].Net ajax检测用户名是否重复
    js 自动执行方法
    js 层 分页显示选择用户名
    c# Cookie的操作
    c# 取IE地址值
    js 弹出层无刷新分页
    iframe 无边框
  • 原文地址:https://www.cnblogs.com/niugang0920/p/12186440.html
Copyright © 2011-2022 走看看