? ?? ??
?????: springmvc+freemarker
?? ??: springsource-tool-suite-2.9.0
JDK ??: 1.6.0_29
tomcat ??: apache-tomcat-7.0 . 26
step1. ???? ??? ?????.
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.ftl ??? ?????.
<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>
3??. ?? ? ???
Tomcat? ????? ???? ????, ????? http://localhost:8080/??? ???? ??/helloWorld.htm
??? Freemarker ?? ??? ?????. ??? ??? ??? ?? ?? PHP ??? ????? ??????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)