java代码:

public String getContent(String name, HashMap<String, Object> paramMap) {

//home 文件路径 + name (模版文件名称)  paramMap包含(页面参过来的参数值)
String content = "";
try {
paramMap.put("name", name);
paramMap.put("templ", this);
paramMap.put("param", paramMap);
this.paramMap = paramMap;

Configuration configuration = new Configuration();
configuration.setDirectoryForTemplateLoading(ZDZServiceManager.getEnv().getHomeFile(home));
configuration.setObjectWrapper(new DefaultObjectWrapper());
configuration.setDefaultEncoding("UTF-8");

Template template = configuration.getTemplate(name);

StringWriter writer = new StringWriter();
template.process(paramMap, writer);//页面参数与模版文件交互
content = writer.toString();
} catch (Exception ex) {
log.error("Cannot get schema content {} !", name, ex);
}
return content;
}

模版文件:(xml文件)

<?xml version="1.0" encoding="UTF-8"?>
<table total="547" pager="50" page="0">
<#assign queryList=json.query>
<#assign queryBtnList=json.queryBtn>
<#assign tableList=json.table>
<#if json.tableBtn??>
<#assign tableBtnList=json.tableBtn>
</#if>
<#if queryList??&&(queryList?size>0)>
<query>
<#list queryList as query>
<field type="${query.type}" id= "eq_${query.value}" title="${query.title}" width="${query.width}" color="${query.color}"/>
</#list>
<#list queryBtnList as queryBtn>
<button color="${queryBtn.color}" href="${queryBtn.href}" title="${queryBtn.title}" />
</#list>
</query>
</#if>
<#list tableList as table>
<field type="${table.type}" id="${table.value}" title="${table.title}" width="${table.width}" color="${table.color}"/>
</#list>
<#if tableBtnList??&&(tableBtnList?size>0)>
<#list tableBtnList as tableBtn>
<#list tableBtn as field>
<#if field_index==0>
<field type="button" id="" title="${field.fieldTitle}" width="" color="${field.fieldColor}">
<#list tableBtn as field>
<#if field_index!=0>
<button color="${field.color}" href="${field.href}" title="${field.title}" />
</#if>
</#list>
</field>
</#if>
</#list>
</#list>
</#if>
</table>

模版文件:table_form(ftl文件)

<?xml version="1.0" encoding="UTF-8"?>
<ypattern>
<#assign tid = templ.getNextId()>
<#assign configName = templ.getConfigName(viewId,tid,".xml")>
<#assign code = templ.writeChildContent(configName,"table/table_config.xml")>
<ytable id="${tid}" config="${configName}" width="86%" style="brown"/>

<#assign yid = templ.getNextId()>
<#assign configName = templ.getConfigName(viewId,yid,".xml")>
<#assign code = templ.writeChildContent(configName,"table/dialog_config.xml")>
<ydialog id="${yid}" config="${configName}" visible="0" size="0">

<#assign fid = templ.getNextId()>
<#assign configName = templ.getConfigName(viewId,fid,".xml")>
<#assign code = templ.writeChildContent(configName,"table/form_config.xml")>
<yform id="${fid}" config="${configName}" />
</ydialog>

<#assign gid = templ.getNextId()>
<#assign configName = templ.getConfigName(viewId,gid,".xml")>
<#assign code = templ.writeChildContent(configName,"table/dialog_config.xml")>
<ydialog id="${gid}" config="${configName}" visible="0" size="0"></ydialog>
<yscript><![CDATA[
$(document).ready(function(){
query(${tid}Table);
});
function query(${tid}) {
var url = "${json.url.query}";
var filter = ${tid}.getFilter();
filter.start = ${tid}.page;
filter.max = ${tid}.pageMax;
$z.showSpin();
$z.post(url,filter,function(data) {
if(data.code >= 0) {
${tid}.removeAll();
${tid}.add(data.result);
${tid}.showPager(url,filter,data.count,data.page,data.pageMax);
${tid}.refresh();
} else {
showErrorDialog("查询","查询失败!");
}
}, function() {
showErrorDialog("查询","查询失败,未知的网络错误!");
});
}
function showAddDialog(${tid}) {
${fid}Form.clearData();
${yid}Dialog.setTitle("添加");
${yid}Dialog.setBtnTitle(0,"添加");
${yid}Dialog.clickBtn(0,addDialog);
$(document).keydown(function(event){
${yid}Dialog.keyBtn(event,addDialog);
});
function addDialog(){
if(${fid}Form.validate()) {
var formData = ${fid}Form.getData();
$z.showSpin();
$z.post("${json.url.add}",formData,function(data) {
if(data.code >= 0) {
${yid}Dialog.hide();
if(data.result == -1) {
showErrorDialog("添加","添加失败,名称已经存在!");
} else {
showErrorDialog("添加","添加成功!");
query(${tid});
}
} else {
showErrorDialog("添加","添加失败!");
}
}, function() {
showErrorDialog("添加","添加失败,未知的网络错误!");
})
}
};
${yid}Dialog.clickBtn(1,function(){
${yid}Dialog.hide();
});
${yid}Dialog.show();
};
function showEditDialog(${tid},index) {
var rec = ${tid}.data[index];
${fid}Form.setData(rec);
${yid}Dialog.setTitle("编辑");
${yid}Dialog.setBtnTitle(0,"保存");
${yid}Dialog.clickBtn(0,editDialog);
$(document).keydown(function(event){
${yid}Dialog.keyBtn(event,editDialog);
});
function editDialog(){
if(${fid}Form.validate()) {
var formData = ${fid}Form.getData(rec);
formData.eq_id = rec.id;
$z.showSpin();
$z.post("${json.url.edit}",formData,function(data) {
if(data.code >= 0) {
if(data.result) {
${yid}Dialog.hide();
showErrorDialog("编辑","编辑成功!");
${tid}.data[index] = formData;
${tid}.refresh();
} else {
showErrorDialog("编辑","编辑失败,名称已经存在!");
}
} else {
showErrorDialog("编辑","编辑失败!");
}
}, function() {
showErrorDialog("编辑","编辑失败,未知的网络错误!");
})
}
};
${yid}Dialog.clickBtn(1,function(){
${yid}Dialog.hide();
});
${yid}Dialog.show();
}
function showRemoveDialog(${tid},index) {
${gid}Dialog.setTitle("删除");
${gid}Dialog.setContent("<br/><br/>确认要删除吗?");
${gid}Dialog.setBtnTitle(0,"删除");
${gid}Dialog.showBtn(1);
$(document).keydown(function(event){
${gid}Dialog.keyBtn(event,removeDialog);
});
${gid}Dialog.clickBtn(0,removeDialog);
function removeDialog() {
${gid}Dialog.hide();
var formData = {};
formData.eq_id = ${tid}.data[index].id;
$z.showSpin();
$z.post("${json.url.del}",formData,function(data) {
if(data.code >= 0) {
${yid}Dialog.hide();
showErrorDialog("删除","删除成功!");
${tid}.remove(index);
query(${tid});
} else {
showErrorDialog("删除","删除失败!");
}
}, function() {
showErrorDialog("删除","删除失败,未知的网络错误!");
});
}
${gid}Dialog.clickBtn(1,function(){
${gid}Dialog.hide();
});
${gid}Dialog.show();
}
function showErrorDialog(title, message) {
${gid}Dialog.setTitle(title);
${gid}Dialog.setContent("<br/><br/>" + message);
${gid}Dialog.setBtnTitle(0,"关闭");
${gid}Dialog.hideBtn(1);
${gid}Dialog.clickBtn(0,function(){
${gid}Dialog.hide();
});
$(document).keydown(function(event){
${gid}Dialog.closeBtn(event);
});
${gid}Dialog.show();
}
]]></yscript>

freemarker加载模板文件的的更多相关文章

  1. MarkDown富文本编辑器怎么加载模板文件

    我们只需要一段加载代码就可以搞定MarkDown加载模板文件. $("#md-demo").bind('click', function () { $.get("/Lib ...

  2. velocity中加载模板文件的方式

    velocity有多中种方式供我们去加载我们自定义的模板文件,下面详细的介绍使用的方法. 1.1.1. 加载classpath目录下的模板文件 使用classpath方式加载,是我们经常用到的一种方式 ...

  3. 我是如何使用freemarker生成Word文件的?

    推荐:亲身体验,数次踩坑,遂撰写此文,以备各位不时之需. 背景 一天,产品经理递给我了一份word报告,我定睛一看 这个文档有大大小小的标题层级,还有排版好的段落.各种一目了然的饼图.走势图,当然还少 ...

  4. Freemarker提供了3种加载模板目录的方法

    Freemarker提供了3种加载模板目录的方法 原创 2016年08月24日 14:50:13 标签: freemarker / Configuration 8197 Freemarker提供了3种 ...

  5. Angular通过XHR加载模板而限制使用file://(解决方案)

    编写angular项目时,遇到此困难: angular.js:12011 XMLHttpRequest cannot load file:///E:/angular/imooc/chapter2/bo ...

  6. FreeMarker的模板文件语法

    FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1,文本:直接输出的部分 2,注释:<#-- ... -->格式部分,不会输 ...

  7. Lodop 动态加载模板,动态加载数据

    最近需要使用Lodop打印控件,所以就研究了一下,期间从网上找了诸多的东西,基本全是对HTML进行打印的,没有找到我想要的,就只好自己动手丰衣足食. 这篇文章主要讲述的是Lodop与数据的结合使用,官 ...

  8. java类加载器加载文件

    例子:采用配置文件加反射的方式创建ArrayList和HashSet的实例对象. //第一种方式:类加载器加载文件 InputStream ips = ReflectTest2.class.getCl ...

  9. NOPI导出加载模板

    ListExcel导出(加载模板) /// <summary> /// List根据模板导出ExcelMemoryStream /// </summary> /// <p ...

随机推荐

  1. EntityFramework 二

    特性 用来具体的设置数据库属性   [Table("表名")]//设置表名 public class User { [Key] //设置主键 [Column("列名&qu ...

  2. selenim

    一.安装selenium Pip install selenium==2.53.1    (稳定版) 下载火狐浏览器35.0.1  http://dl.pconline.com.cn/download ...

  3. node——模块分类,require执行顺序,require注意事项,原理

    node.js模块 在node.js开发中一个文件就可以认为是一个模块. 一.node.js模块分类 核心模块Code Module.内置模块.原生模块 fs http path url ... 所有 ...

  4. 7、A Design of Group Recommendation Mechanism Considering Opportunity Cost and Personal Activity Using Spark Framework---使用Spark框架的基于机会成本以及个人活动群组推荐机制

    来源EDB2018---EDB 一.摘要: 组推荐是将一种项目(例如产品.服务)推荐给由多个成员组成的组的方法. 最小痛苦法(least Misery)是一种具有代表性的群体推荐方法,其能够推荐考虑群 ...

  5. 02 C#高级

    第九天 面向过程--à面向对象 面向过程:面向的是完成这件事儿的过程,强调的是完成这件事儿的动作. 把大象塞进冰箱 1. 打开冰箱门 2. 把大象塞进去,亲下大象的屁股 3. 关闭冰箱门 孙全 瘦小 ...

  6. 在Action中获取servlet API

    Struts2的Action组件是不依赖servlet API 的.那么当你在action中的业务需要处理HttpServletRequest和HttpServletResponse的时候(比如要对响 ...

  7. nginx 查看每秒有多少访问量

    nginx访问量统计 1.根据访问IP统计UV awk '{print $1}' access.log|sort | uniq -c |wc -l 2.统计访问URL统计PV awk '{print ...

  8. Servlet里面一调用Dao里的某个方法

    背景: 这几天,由于项目集成的需要,我要在doFilter里调用dao层里的某些方法,可是总之报空指针,只要调用那个dao方法,就报错误.很是纳闷,网上查找了各种原因,终于让我给突破了,看来还是Jav ...

  9. ZOJ 3556

    终于做出来了,激动.... 这道题隐藏得深啊,但若推导下来,就变简单了. 首先,一个集合的子集的个数为2^n=s.注意了,题目求的是有序集合组,并且每个集合是可以重复使用的,怎么办呢?这就要想到多重集 ...

  10. 轻松学习JavaScript十七:JavaScript的BOM学习(二)

    JavaScript计时事件 通过使用JavaScript中的BOM对象中的window对象的两个方法就是setTimeout()方法和claerTimeout()方法,我们 有能力作到在一个设定的时 ...