Freemarker中页面直接可以运用的内置对象

FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据,并用来生成输出文本(HTML网页、电子邮件、配置文件、源代码等)的通用工具。 它不是面向最终用户的,而是一个Java类库,是一款程序员可以嵌入他们所开发产品的组件。

 

freemarker中页面直接可以使用的内置对象有以下几种:

 

1. Request:用于获取Request对象中的attribute对象。

 

用法:${Request["atrributeName"]},${Request.atrributeName}这样是直接在页面输出属性值,相当于request.getAtrribute("atrributeName");如果要对这个值进行判断使用如下格式:<#if Request["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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

E%3Dmc%B2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值