Freemarker中页面直接可以运用的内置对象
2016-05-20 15:37
344 查看
FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据,并用来生成输出文本(HTML网页、电子邮件、配置文件、源代码等)的通用工具。 它不是面向最终用户的,而是一个Java类库,是一款程序员可以嵌入他们所开发产品的组件。
freemarker中页面直接可以使用的内置对象有以下几种:
Request["atrributeName"]="edit">
对于list等复杂的属性值,也可以${Request["atrributeName"]}、${Request.atrributeName}两种方式联合使用,例如:
前端页面显示:
但是经测试,程序直接抛错!!!不知是没有这个内置对象还是什么原因???
The problematic instruction:
----------
==> ${Parameters["method"]} [on line 134, column 61 in report/cashierSumList.html]
----------
Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression Parameters is undefined on line 134, column 63 in report/cashierSumList.html.
freemarker中页面直接可以使用的内置对象有以下几种:
1. Request:用于获取Request对象中的attribute对象。
用法:${Request["atrributeName"]},${Request.atrributeName}这样是直接在页面输出属性值,相当于request.getAtrribute("atrributeName");如果要对这个值进行判断使用如下格式:<#ifRequest["atrributeName"]="edit">
对于list等复杂的属性值,也可以${Request["atrributeName"]}、${Request.atrributeName}两种方式联合使用,例如:
@RequestMapping("cashierSum") public ModelAndView cashierSum(HttpServletRequest request,HttpSession session) { ModelAndView mv = new ModelAndView("/report/cashierSumList"); String substoreid = String.valueOf(session.getAttribute("substoreid")); String startDate = request.getParameter("start_date"); String endDate = request.getParameter("end_date"); Map<String, Object> params = new HashMap<String, Object>(); params.put("startDate", startDate); params.put("endDate", endDate); params.put("substoreid", substoreid); List<Map<String, Object>> payClasses=this.reportService.getAllPayClass(substoreid); mv.addObject("payClasses", payClasses); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); if (request.getParameter("searchFlag") != null) { list = this.reportService.getCashierSumList(params);// 收银报表列表 mv.addObject("list", list); } return mv; }
前端页面显示:
<#if list ??> <#list list as tmp> <tr> <td>${tmp_index+1}</td> <td>${(tmp.the_date?string("yyyy-MM-dd"))!}</td> <td>${tmp.am_name}</td> <td>${tmp.the_man}</td> <td>${tmp.user_name!}</td> <#if payClasses ??> <#list payClasses as tmp2> <#assign name="payName${tmp2_index}"/> <td><span style="color:#ff0000;">${Request.list[tmp_index][name]}</span></td> </#list> </#if> </tr> </#list> </#if>
2. Session:用于获取Session对象中的attribute对象。
用法:用法参照Request的用法。3. Application:用于获取Application(ServletContext)对象中的attribute对象。
用法:用法参照Request的用法。4. RequestParameters:用于获取Request对象的parameter参数(浏览器端发送的请求数据)。
用法:${RequestParameters["atrributeName"]}等同于request.getParameter("atrributeName");5. Parameters:属性获取,依次从RequestParameters、Request、Session、Application对象中获取对应属性参数,一旦获取,则不再向下查找。
用法:${Parameters["method"]}但是经测试,程序直接抛错!!!不知是没有这个内置对象还是什么原因???
The problematic instruction:
----------
==> ${Parameters["method"]} [on line 134, column 61 in report/cashierSumList.html]
----------
Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression Parameters is undefined on line 134, column 63 in report/cashierSumList.html.
相关文章推荐
- MySQL存储过程调试工具
- 在GridView控件内文本框实现TextChanged事件,勾选复选框时 :textbox文本框可编辑,编辑文本框的数字后 总金额会重新计算并统计
- 课堂作业:评估手机输入法——讯飞
- headroom.js –在不需要页头时将其隐藏
- java验证码生成代码
- php7在centos上源码安装
- 字 典 加 密
- NYOJ Substring--308
- JavaScript基础教程――入门必看篇
- 复杂链表的复制
- Apache Shiro 标签模式授权
- 基于虚拟主机构建个人网站
- c++学习之运算符重载
- 视频文件截图
- Unity移动游戏优化解决方案--前篇
- window下安装redis以及配置phpredis
- 常见链表面试题之判断链表是否相交,并求交点
- 数据驱动来控制界面
- 【随笔】Linux文件的三个时间属性
- nagios安装和配置