freemarker自定义标签

1、错误描述

 六月 05, 2014 11:31:35 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
 严重: Template processing error: "Error executing macro: write\nrequired parameter: nums is not specified."

 Error executing macro: write
 required parameter: nums is not specified.
 The problematic instruction:
 ----------
 ==> macro write [on line 11, column 10 in myself.ftl]
  in user-directive write [on line 18, column 10 in myself.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.template.TemplateException: Error executing macro: write
 required parameter: nums is not specified.
     at freemarker.core.Macro$Context.sanityCheck(Macro.java:211)
     at freemarker.core.Macro$Context.runMacro(Macro.java:169)
     at freemarker.core.Environment.visit(Environment.java:614)
     at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:217)
     at com.you.test.freemarker.FreemarkerTest.testMyself(FreemarkerTest.java:204)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 <html>
   <head>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     <title>freemarker自定义标签</title>

   </head>

   <body>

 Error executing macro: write
 required parameter: nums is not specified.
 The problematic instruction:
 ----------
 ==> macro write [on line 11, column 10 in myself.ftl]
  in user-directive write [on line 18, column 10 in myself.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.template.TemplateException: Error executing macro: write
 required parameter: nums is not specified.
     at freemarker.core.Macro$Context.sanityCheck(Macro.java:211)
     at freemarker.core.Macro$Context.runMacro(Macro.java:169)
     at freemarker.core.Environment.visit(Environment.java:614)
     at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:217)
     at com.you.test.freemarker.FreemarkerTest.testMyself(FreemarkerTest.java:204)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 Error executing macro: write
 required parameter: nums is not specified.
 The problematic instruction:
 ----------
 ==> macro write [on line 11, column 10 in myself.ftl]
  in user-directive write [on line 18, column 10 in myself.ftl]
 ----------

 Java backtrace for programmers:
 ----------
 freemarker.template.TemplateException: Error executing macro: write
 required parameter: nums is not specified.
     at freemarker.core.Macro$Context.sanityCheck(Macro.java:211)
     at freemarker.core.Macro$Context.runMacro(Macro.java:169)
     at freemarker.core.Environment.visit(Environment.java:614)
     at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.MixedContent.accept(MixedContent.java:92)
     at freemarker.core.Environment.visit(Environment.java:221)
     at freemarker.core.Environment.process(Environment.java:199)
     at freemarker.template.Template.process(Template.java:259)
     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:217)
     at com.you.test.freemarker.FreemarkerTest.testMyself(FreemarkerTest.java:204)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

2、错误原因

 <#--freemarker自定义标签-->
      <#--对于write自定义标签有两个参数,nums是次数,name是名称-->
      <#macro write nums name>
          <#list 1..nums as num>
                        姓名:张三丰
                        性别:男
          </#list>
      </#macro>

      <@write/>

由于write自定义标签有两个参数,在调用它的时候需要给两个参数指定值,否则报错

3、解决办法

 <@write nums=4 name="你好!"/>

给两个参数赋值

 <html>
   <head>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     <title>freemarker自定义标签</title>

   </head>

   <body>
      <#--freemarker自定义标签-->
      <#--对于write自定义标签有两个参数,nums是次数,name是名称-->
      <#macro write nums name>
          <#list 1..nums as num>
                        姓名:张三丰
                        性别:男
          </#list>
      </#macro>

      <@write nums=4 name="你好!"/>
   </body>
 </html>

运行结果:

 <html>
   <head>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     <title>freemarker自定义标签</title>

   </head>

   <body>

                        姓名:张三丰
                        性别:男
                        姓名:张三丰
                        性别:男
                        姓名:张三丰
                        性别:男
                        姓名:张三丰
                        性别:男
   </body>
 </html>

异常-----freemarker.template.TemplateException: Error executing macro: write的更多相关文章

  1. 异常-----freemarker.template.TemplateException:Error executing macro:mainSelect

    1.错误描述 freemarker.template.TemplateException:Error executing macro:mainSelect require parameter:id i ...

  2. freemarker.template.TemplateException:Error executing macro:mainSelect

    1.错误描述 freemarker.template.TemplateException:Error executing macro:mainSelect require parameter:id i ...

  3. freemarker.template.TemplateException:Error parsing including template

    1.错误描述 freemarker.template.TemplateException:Error parsing including template ftl/main.ftl:on line 6 ...

  4. 异常-----freemarker.template.TemplateException: Macro select has no such argument

    1.错误描述 六月 25, 2014 11:32:49 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  5. 异常-----freemarker.template.TemplateException: Expected collection or sequence. datas evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 7, column 18 in inc/select.ftl.

    1.错误描述 六月 26, 2014 11:26:27 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  6. 异常-----freemarker.template.TemplateException: The only legal comparisons are between two numbers, two strings, or two dates

    1.错误描述 六月 26, 2014 10:44:49 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  7. 异常-----freemarker.template.TemplateException

    一,案例一 1.1.错误描述 五月 30, 2014 11:33:57 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Templ ...

  8. freemarker.template.TemplateException:Macro has no such argument:params

    1.错误描述 freemarker.template.TemplateException:Macro mainSelect has no such argument:params 2.错误原因 在宏定 ...

  9. cosbench 异常 FreeMarker template error: The following has evaluated to null or missing

    问题现象: 使用Cosbench 0.4.2.c4 版本测试Ceph RGW read test失败,遇到异常如下: FreeMarker template error: The following ...

随机推荐

  1. CF528D. Fuzzy Search [FFT]

    CF528D. Fuzzy Search 题意:DNA序列,在母串s中匹配模式串t,对于s中每个位置i,只要s[i-k]到s[i+k]中有c就认为匹配了c.求有多少个位置匹配了t 预处理\(f[i][ ...

  2. WPF---Xaml中改变ViewModel的值

    在开发中遇到实现如下需求的情景:一个输入框,旁边一个清空输入的按钮,当输入框中有内容时显示清空按钮,点击该按钮可以清空输入框内容,当输入框中无内容时隐藏按钮 当然这个需求使用wpf的绑定功能很容易实现 ...

  3. java使用*导包的性能

    项目中切换到IDEA工具,使用Git提交代码之后在comments中被吐槽了.事情是这样的原有的导入包被IDEA优化了,譬如java.util.Set, java.util.Map, ... 会被优化 ...

  4. vagrant启动报错The following SSH command responded with a no

    vagrant package打包生成box,以这个box为基础模板,打造vagrant环境,启动vagrant报错 angel:vagrant $ vagrant up Bringing machi ...

  5. 在tableViewCell的点击事件中处理界面跳转问题

    UIViewController *controller; UIView *view = self.view; while (1) { controller = (UIViewController * ...

  6. IDA学习笔记 函数调用约定

    stdcall和cdecl: stdcall和cdecl 压栈方向都是从右到左 区别在于c约定是调用方在函数返回后add esp,n指令清除堆栈中的参数,而stdcall在被调函数内使用ret n来清 ...

  7. Redis入门_上

    Redis是基于内存的Key-Value数据库,包含Set.String.SortedSet.List.Hash等数据结构,可用于缓存.排名.爬虫去重等应用场景. 1.思维导图 2.安装与配置 2.1 ...

  8. Android App 压力测试方法(Monkey)

    一.为什么要开展压力测试 a.提高产品的稳定性:b.提高产品的留存率 二.什么时候开展压力测试 a.首轮功能测试通过后:b.下班后的夜间进行 三.7个基础知识(理论部分) 3.1 手动测试场景与自动测 ...

  9. thinkPHP替换SQL变量

    使用tp里M()->where(pb_id=%d and course=%d and DATE_FORMAT(pub_time, \"%H:%i:%s\") < &qu ...

  10. CSS布局(四) float详解

    一.float设计初衷 因为float被设计出来的初衷是用于--文字环绕效果.即,一个图片一段文字,图片float:left之后,文字会环绕图片. <div style="width: ...