在页面中遍历一个list,现有个需求想在第五条的时候加个line
但是怎样判断遍历到第五个?谁知道告诉我,谢谢!

解决方案 »

  1.   

    FTL
    <#assign seq = ["test1", "test2", "test3", "test4", "test5","test6"]>
    <#list seq as x>
      ${x_index + 1}. ${x}<#if x_index+1==5>----line</#if>
    </#list>  JAVAimport java.io.IOException;
    import java.io.PrintWriter;
    import java.io.Writer;import freeer.template.Configuration;
    import freeer.template.DefaultObjectWrapper;
    import freeer.template.Template;
    import freeer.template.TemplateException;public class Test
    {
        
        /** <一句话功能简述>
         * <功能详细描述>
         * @param args [参数说明]
         * 
         * @return void [返回类型说明]
         * @exception throws [违例类型] [违例说明]
         * @see [类、类#方法、类#成员]
         */
        public static void main(String[] args)
        {
            Configuration cfg = new Configuration();
            // Specify the data source where the template files come from.
            // Here I set a file directory for it:
            cfg.setClassForTemplateLoading(Test.class, "");
            // Specify how templates will see the data-model. This is an advanced topic...
            // but just use this:
            cfg.setObjectWrapper(new DefaultObjectWrapper());
            try
            {
                Template temp = cfg.getTemplate("test.ftl");
                temp.process(null, new PrintWriter(System.out));
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (TemplateException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    运行结果:
      1. test1
      2. test2
      3. test3
      4. test4
      5. test5----line
      6. test6