• <cite id="zzcp9"><source id="zzcp9"></source></cite>
      <output id="zzcp9"></output>
      \r\n示例一輸出結(jié)果:\r\n

      \r\n<#-- if指令的用法-->\r\n<#-- 在指令標(biāo)籤內(nèi)直接使用變量名得到文本值-->\r\n<#if flag == 1>\r\n    flag = 1\r\n<#elseif flag ==2>\r\n    flag = 2\r\n<#else>\r\n    <#-- 在指令標(biāo)籤外使用   ${變量名}   的格式來得到文本值-->\r\n    flag!=1 && flag!=2 flag的值為:${flag}\r\n<\/#if>\r\n<\/p>\r\n

      ----------------------------------------------------------<\/p>\r\n示例二輸出結(jié)果:\r\n

      \r\n<#-- 判斷變量是否存在-->\r\n<#if noExistList??>\r\n    List存在\r\n<#else>\r\n    List不存在\r\n<\/#if>\r\n<\/p>\r\n

      ----------------------------------------------------------<\/p>\r\n示例三輸出結(jié)果:\r\n

      \r\n<#-- list指令的用法,as可設(shè)置別名-->\r\n<#list strList as sl>\r\n    <#-- 在變量名后加   _index   得到變量在容器中的序號,從0開始-->\r\n    <#if sl_index == 0>\r\n        我的博客地址是:${sl}\r\n    <#else>\r\n        ${sl}\r\n    <\/#if>\r\n<\/#list>\r\n<\/p>\r\n

      <\/p>\r\n直接使用下標(biāo)訪問List:${strList[0]}${strList[1]}${strList[2]}\r\n<\/p>\r\n

      ----------------------------------------------------------<\/p>\r\n示例四輸出結(jié)果:\r\n

      \r\n<#-- 使用    ${變量名.變量名}   獲取容器對象的子對象-->\r\n${strMap.mapKey0}${strMap.mapKey1}${strMap.mapKey2}\r\n<\/p>\r\n

      ----------------------------------------------------------<\/p>\r\n示例五輸出結(jié)果:\r\n

      \r\n<#-- 當(dāng)變量是日期對象時,可使用函數(shù)使其按格式輸出-->\r\n${nowTime?string(\"yyyy-MM-dd\")}\r\n<\/p>\r\n<\/body>\r\n<\/html><\/pre>

      step3. Run and debug

      Deploy the project to tomcat and run it, enter in the browser: http:\/\/localhost:8080\/the project name you set\/helloWorld.htm
      For more Freemarker common instruction usage examples and related articles, please pay attention to the PHP Chinese website! <\/p>"}

      亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

      Home php教程 PHP開發(fā) Freemarker common instruction usage examples

      Freemarker common instruction usage examples

      Jan 05, 2017 pm 01:53 PM
      freemarker

      My development environment
      Framework: springmvc+freemarker
      Development tool: springsource-tool-suite-2.9.0
      JDK version: 1.6.0_29
      tomcat version: apache-tomcat-7.0 .26

      step1. Write the controller file, the code is as follows:

      package www.asuan.com.controller;
      import java.util.ArrayList;
      import java.util.Date;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.web.bind.annotation.RequestMapping;
      @Controller
      public class HelloWorldController {
          @RequestMapping("/helloWorld")
          public String helloWorld(Model model) {
              // 示例一
              int flag = 0;
              model.addAttribute("flag", flag);
              // 示例二
              List<String> noExistList = new ArrayList<String>();
              noExistList = null;
              model.addAttribute("noExistList", noExistList);
              // 示例三
              List<String> strList = new ArrayList<String>();
              strList.add("www.");
              strList.add("cnblogs.");
              strList.add("com/sunang");
              model.addAttribute("strList", strList);
              // 示例四
              Map<String, String> strMap = new HashMap<String, String>();
              strMap.put("mapKey0", "www.");
              strMap.put("mapKey1", "cnblogs.");
              strMap.put("mapKey2", "com/sunang");
              model.addAttribute("strMap", strMap);
              // 示例五
              Date nowTime = new Date();
              model.addAttribute("nowTime", nowTime);//傳輸時間對象
              return "helloWorld.ftl";
          }
      }

      step2. Write the ftl file, the code is as follows:

      <html>
      <body>
      示例一輸出結(jié)果:
      <p>
      <#-- if指令的用法-->
      <#-- 在指令標(biāo)籤內(nèi)直接使用變量名得到文本值-->
      <#if flag == 1>
          flag = 1
      <#elseif flag ==2>
          flag = 2
      <#else>
          <#-- 在指令標(biāo)籤外使用   ${變量名}   的格式來得到文本值-->
          flag!=1 && flag!=2 flag的值為:${flag}
      </#if>
      </p>
      <p>----------------------------------------------------------</p>
      示例二輸出結(jié)果:
      <p>
      <#-- 判斷變量是否存在-->
      <#if noExistList??>
          List存在
      <#else>
          List不存在
      </#if>
      </p>
      <p>----------------------------------------------------------</p>
      示例三輸出結(jié)果:
      <p>
      <#-- list指令的用法,as可設(shè)置別名-->
      <#list strList as sl>
          <#-- 在變量名后加   _index   得到變量在容器中的序號,從0開始-->
          <#if sl_index == 0>
              我的博客地址是:${sl}
          <#else>
              ${sl}
          </#if>
      </#list>
      </p>
      <p><p></p>
      直接使用下標(biāo)訪問List:${strList[0]}${strList[1]}${strList[2]}
      </p>
      <p>----------------------------------------------------------</p>
      示例四輸出結(jié)果:
      <p>
      <#-- 使用    ${變量名.變量名}   獲取容器對象的子對象-->
      ${strMap.mapKey0}${strMap.mapKey1}${strMap.mapKey2}
      </p>
      <p>----------------------------------------------------------</p>
      示例五輸出結(jié)果:
      <p>
      <#-- 當(dāng)變量是日期對象時,可使用函數(shù)使其按格式輸出-->
      ${nowTime?string("yyyy-MM-dd")}
      </p>
      </body>
      </html>

      step3. Run and debug

      Deploy the project to tomcat and run it, enter in the browser: http://localhost:8080/the project name you set/helloWorld.htm
      For more Freemarker common instruction usage examples and related articles, please pay attention to the PHP Chinese website!

      Statement of this Website
      The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

      Hot AI Tools

      Undress AI Tool

      Undress AI Tool

      Undress images for free

      Undresser.AI Undress

      Undresser.AI Undress

      AI-powered app for creating realistic nude photos

      AI Clothes Remover

      AI Clothes Remover

      Online AI tool for removing clothes from photos.

      Clothoff.io

      Clothoff.io

      AI clothes remover

      Video Face Swap

      Video Face Swap

      Swap faces in any video effortlessly with our completely free AI face swap tool!

      Hot Tools

      Notepad++7.3.1

      Notepad++7.3.1

      Easy-to-use and free code editor

      SublimeText3 Chinese version

      SublimeText3 Chinese version

      Chinese version, very easy to use

      Zend Studio 13.0.1

      Zend Studio 13.0.1

      Powerful PHP integrated development environment

      Dreamweaver CS6

      Dreamweaver CS6

      Visual web development tools

      SublimeText3 Mac version

      SublimeText3 Mac version

      God-level code editing software (SublimeText3)