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. javascript中手风琴特效

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. BroadcastReceiver广播接受者简单使用

    1.注册BrocadcastReceiver <receiver android:name=".FirstReceiver" > <!-- 指定能够接收的广播类型 ...

  3. oracle数据库 sqlplus

  4. Projective Texture Mapping - 投影纹理

    昨天导师让写一个投影纹理,将一个相机渲染的图片的一部分投影到另外一个相机里面,目的是无缝的拼接. 投影纹理就和shadow map一样,都是将片元转换到另外一个相机/光源坐标系下,投影后找到对应的纹素 ...

  5. Windows下安装XAMPP,Wordpress

    配置XAMPP:   1.下载:https://www.apachefriends.org/zh_cn/download.html(下载速度日了狗!)  2.安装XAMPP;  3.启动apache, ...

  6. CSS骚操作

    获取当前HTML页面根元素的字体大小 getComputedStyle(document.getElementsByTagName("html")[0],undefined).fo ...

  7. event 下鼠标坐标的获取

    event.clientX.event.clientY 鼠标相对于浏览器窗口可视区域的X,Y坐标(窗口坐标),可视区域不包括工具栏和滚动条.IE事件和标准事件都定义了这2个属性 event.pageX ...

  8. [CTSC1999][网络流24题]家园

    题目:洛谷P2754. 题目大意:有$n$个空间站,$m$个飞船,每个飞船有各自的停靠站点,并且从第一个停靠站点开始,不断循环.每个飞船有不同的容量(-1为月球,0为地球).每个飞船初始停在第一个停靠 ...

  9. 首页 > 所有书 > 操作系统 > Linux >

    http://book.51cto.com/col/1213/list_1213_8.htm linux一些经典教材

  10. 什么叫openapi

    Open API即开放API,也称开放平台. 所谓的开放API(OpenAPI)是服务型网站常见的一种应用,网站的服务商将自己的网站服务封装成一系列API(Application Programmin ...