freemarker使用map替换ftl中相关值
ftl文件demo01.ftl
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<h1>Welcome ${user}!</h1>
<p>Our latest product:
<a href="${url}">${name}</a>!
</body>
</html>
java类 Demo01.java
package demo01;
import java.io.File;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
public class Demo01 {
public static void main(String[] args) throws Exception {
Configuration cfg = new Configuration();
File file = new File(Demo01.class.getResource("/").getPath().substring(1)+"template");
System.out.println(file.getPath());
//设置模板文件所在目录
cfg.setDirectoryForTemplateLoading(file);
//构造填充数据的Map
Map map = new HashMap();
map.put("user", "lavasoft");
map.put("url", "http://www.baidu.com/");
map.put("name", "crd");
//设置模板文件名
Template tmp = cfg.getTemplate("demo01.ftl");
tmp.process(map, new OutputStreamWriter(System.out));
}
}
目录结构

执行后台打印:

所需jar包

freemarker使用map替换ftl中相关值的更多相关文章
- freemarker使用map替换字符串中的值demo2
package demo01; import java.io.IOException;import java.io.OutputStreamWriter;import java.io.StringWr ...
- freemarker使用map替换字符串中的值
package demo01; import java.io.IOException;import java.io.OutputStreamWriter;import java.io.StringRe ...
- EL表达式获取Map和List中的值
EL表达式获取Map和List中的值 EL表达式取Map中的值: 当Map中是String,String时 后台servlet中: Map<String, String> map1 = ...
- Freemarker在replace替换是对NULL值的处理
freemarker的对象调用内建函数时,比如userInfo对象的birthDay函数,页面${userInfo.birthDay}调用,当我想将birthDay值中的“-”替换为“/”时,${us ...
- STL源码中map和set中key值不能修改的实现
前言 最近正好刚刚看完,<stl源码剖析>这本书的map和set的源码部分.但是看完之后又突然发现,之前怎么没有注意到map和set容器中key不能修改是怎么实现的.故,特此整理如下. s ...
- Java 程序动态替换 docx 模板中定制值的实现例子
项目系统中打印功能,导出 word 文档功能是挺常用的,本文介绍自定文档模板,程序实现模板内容中值替代的功能. 模板文件 template.docx 执行 main public static v ...
- myeclipse2014中如何安装freeMarker插件(支持ftl语法高亮)
MyEcplise2014安装Freemarker插件(支持.ftl文件) 1.下载插件:http://sourceforge.net/projects/freemarker-ide/?source= ...
- spring中PropertyPlaceholderHelper替换占位符的值
1.Properties中的值替换¥{}或者#{}占位符 String text = "foo=${foo},bar=${bar}"; Properties props = new ...
- Map接口中的常用方法和Map集合遍历键找值方式
Map接口中定义了很多方法,常用的如下: public V put(K key,V value) 将指定的值与此映射中的指定键相关联(可选操作) V remove(Object key); 如果此映射 ...
随机推荐
- BZOJ 1055 区间DP
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1144 Solved: 668[Submit][Statu ...
- JOIN a table with a subquery
统计数据产品消耗量与产量 注意join 方向 join中子查询 How to use subquery in JOIN operation in MySQL http://www.geeksengin ...
- 获取发布的头条的url,避免点击打开新的页面
https://www.toutiao.com/ document.getElementsByClassName("ugc-mode-content")[0].getElement ...
- css3 3d特效汇总
本篇全是实战,没有基础,如果不明白3d特效的原理,可能会看不懂,不过没关系,给你推荐一下 张鑫旭css3 3d转换,或者看我的另一篇博客 css3 2d转换3d转换以及动画的知识点汇总,看完这些3d ...
- shell脚本自动更新git
gitpull.sh #!/bin/bash cd /home/wwwroot/default/mouse && git pull cd /home/wwwroot/default/s ...
- linux 基础 —— 网络管理
Linux 最强大的功能是什么?网络功能. 修改 dns 服务器(解析域名到 ip 地址): $ sudo vim /etc/resolvconf/resolv.conf.d/base # 添加如下内 ...
- bzoj4195 [Noi2015]程序自动分析——并查集
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4195 突然在这道大水题上WA了半天... 思路很简单,离线处理询问,先把 = 的都加到并查集 ...
- bzoj2763 [JLOI2011]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 构建分层图. 代码如下: 写法1(空间略大)(时间很慢): #include<i ...
- bzoj 3498: PA2009 Cakes【瞎搞】
参考:https://www.cnblogs.com/spfa/p/7495438.html 为什么邻接表会TTTTTTTLE啊...只能用vector? 把点按照点权从大到小排序,把无向边变成排名靠 ...
- sshd服务器搭建管理和防止暴力破解
1.1 Linux服务前期环境准备,搭建一个RHEL7环境 1.2 sshd服务安装-ssh命令使用方法 1.3 sshd服务配置和管理 1.4 防止SSHD服务暴力破解的几种方式 1.1 Linux ...