freemarker入門教程atcrowdfunding課件框架_第1頁
freemarker入門教程atcrowdfunding課件框架_第2頁
freemarker入門教程atcrowdfunding課件框架_第3頁
freemarker入門教程atcrowdfunding課件框架_第4頁
freemarker入門教程atcrowdfunding課件框架_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

FreeMarker前 第一章:FreemarkerFreeMarker前 第一章:Freemarker簡 1、數(shù)據模 2、模 第二章:Freemarker的使 1.創(chuàng)建配置實 創(chuàng)建數(shù)據模 獲取模 合并模板與數(shù)據模 第三章:格式化,strust標簽,JSTL標簽,傳值范 1,日期 2、數(shù) 3、struts標 4、作用 尾聲:參考資料代碼下載地 SEO,所以這個問題擺在了我的面前,在網上一搜,關于這方面的資料不是很多,又很雜,關于這方面的知識,越來或多的程序員將會碰到,原來項目中這部分靜態(tài)化的功能主要由我來做的,struts2.0使用類似于用#tempjava使用類似于用#tempjava程序運行的過程中用實際值代替#temp#,為什么還要用FreeMarkerFreeMarkerFreeMarker第一章:Freemarker設計人員可以用它改變的外觀網而無需更改或重新編譯代碼,因為應用將程序邏輯(Java)設計(FreeMarker)FreeMarkerWebWeb,F(xiàn)reeMarkerHTTPservletsWeb意,F(xiàn)reeMarkerStrutsJSPtaglibs1+-+-+-size= +-price=+-+-size=+-price=+-size=+-price=test="Itisa+-+-(1)=+-(2)=變量存儲一個單一的價值(size,pricename)被稱為。目錄(root,animals)被稱為哈希值。序列例如,在此數(shù)據模型的序列。2、模板HTML(或任何文本文件,F(xiàn)reeMarkerHTML,比如也可以是.txt)FreeMarkerhtml更有活力,那么你應該把部分特殊的HTMLFreeMarker$(...)插值jstl${}FTL@代替#。注釋:HTML<#--FTL<#directivename<#listanimalsas<li>${}for${being.price}<#if<#listanimalsas<li>${}for${being.price}<#ifuser"BigJoe">//判斷標簽(exceptforyou)</#list>"if"<#assignages={"Joe":23,"Fred":25}+{"Joe":30,<#--自定義的標簽greet<#macrogreetHello${person}!YourWebsiteis<#--使用自定義的greet<@greetperson="螢火蟲"<#includeStrings:"Foo"or'Foo'or"It's\"quoted\""orr"C:\raw\string"Numbers:123.45Booleans:true,Sequences:["foo","bar",123.45],1..100Hashes:{"name":"greenmouse","price":150}Top-levelvariables:Retrievingdatafromahash:,Retrievingdatafromasequence:Specialvariable:Interpolation(orconcatenation):"Hello${user}!"(or"Free"+Gettingacharacter:Concatenation:users+Retrievingdatafromasequence:Specialvariable:Interpolation(orconcatenation):"Hello${user}!"(or"Free"+Gettingacharacter:Concatenation:users+Sequenceslice:products[10..19]orHashConcatenation:passwords+算術:(x*1.5+10)/2-y%xyxyxyxyxyxyx<y...etc.邏輯比較:!registered&&(firstVisit||fromEurope)Built-ins(內置):name?upper_case方法的調用:repeat("What",3)Defaultvalue:name!"unknown"or()!"unknown"orname!orMissingvaluetest:name??or第二章:FreemarkerConfigurationcfg=new//Specifythedatasourcewherethetemplatefilescome//HereIsetafiledirectoryforit:cfg.setDirectoryForTemplateLoading(newFile("模板路徑"));//cfg.setServletContextForTemplateLoading(this.getServletContext(),"模板路徑//cfg.setClassForTemplateLoading(this.class,”//Specifyhowtemplateswillseethedata-model.Thisisanadvanced//butjustusecfg.setObjectWrapper(new2創(chuàng)建數(shù)據模型java.langjava.utilJava使用構造函數(shù)java.lang.Numberjava.lang.BooleanBooleanjava.util.Listjava.lang.BooleanBooleanjava.util.ListJavaarraysjava.util.Mapproduct.price+-user="Big+-+-url=+-name="green//CreatetheroothashMaproot=newHashMap();//Putstring``user''intotherootroot.put("user","BigJoe");//CreatethehashforMaplatest=new//put``url''and``name''intolatest.put("url","products/greenmouse.html");latest.put("name","greenmouse");//andputitintotheroot.put("latestProduct",3獲取模板getTemplate()方法。test.ftlTemplatetemp=Templatetest.ftltest.ftlTemplate存儲的是模板中的解析形式,而不是文字。ConfigurationTemplate實例,因此當你再次解析test.ftlTemplate4.合并模板與數(shù)據模型Writerout=newOutputStreamWriter(System.out);cess(root,out);Writerout=newOutputStreamWriter(System.out);cess(root,out);//PrintWriterpnewPrintWriter(newFileOutputStream(newFile("1.html")));//如果為cess(root,p);//importfreemarker.template.*;importjava.util.*;importpublicclassTestpublicstaticvoidmain(String[]args)throwsException/*Youusuallydoitonlyonceinthewholeapplicationlife-cycle:Createandadjusttheconfiguration*/Configurationcfg=newConfiguration();newcfg.setObjectWrapper(new/*Youusuallydotheseformanytimesintheapplicationlife-cycle:Getorcreateatemplate*/Templatetemp=/*Createadata-model*/Maproot=newHashMap();root.put("user","BigJoe");Maplatest=newHashMap();root.put("latestProduct",latest);latest.put("url","products/greenmouse.html");latest.put("name","green/*Mergedata-modelwithtemplateWriterout=newOutputStreamWriter(System.out);cess(root,out);1,日期:string(當和一個日期值一起使用1,日期:string(當和一個日期值一起使用這個內置標簽用指定的格式把日期轉換成字符串,(FreeMarkerate_format,time_formatdatetime_format預定義的格式是:short,medium,longfull。定義了結果字符串的長度。例如,如果localeUS.PACIFIC,12:4512:45:0912:45:09PM12:45:09PMApr20,April20,Friday,April20,4/20/0712:45Apr20,200712:45:09April20,200712:45:09PMFriday,April20,200712:45:09PMFreeMarker${lastUpdated?string.short_long}<#--shortdate,longtime--${lastUpdated?string.medium_short}<#--mediumdate,shorttime--FreeMarker${lastUpdated?string.short_long}<#--shortdate,longtime--${lastUpdated?string.medium_short}<#--mediumdate,shorttime--4/8/039:24:44PMApr8,20039:24注意:?string.short?string.short_short,?string.medium?string.medium_medium不幸的是,由于javaDataModelFreeMarker只存儲日期部分或者時間部分再或者日期和時間。這種情況下當你像${lastUpdated?string.short}或者了防止這樣,你可以使用?date,?time?datetime內置標簽來幫助FreeMarker。舉例:${lastUpdated?datetime?string.short}.用?date,?time?datetime你可以使用?string(格式)java${lastUpdated?string("yyyy-MM-ddHH:mm:ss${lastUpdated?string("EEE,MMMd,${lastUpdated?string("EEEE,MMMMdd,yyyy,hh:mm:ssa2003-04-0821:24:44PacificDaylightTue,Apr8,Tuesday,April08,2003,09:24:44PM不像預定義格式,你不需要在指定的格式上使用?date,?time?datetime,F(xiàn)reeMarKer,F(xiàn)reeMarker,soyoucanshow"noise"ifdisplaypartsthatareactuallynotstoredinthevariable.例如mm-ddhh:mm:ssa")},openingTime1790-01-0109:24:44short,medium……"short_medium"的:someDate?string("short")someDate?string.shortdisplaypartsthatareactuallynotstoredinthevariable.例如mm-ddhh:mm:ssa")},openingTime1790-01-0109:24:44short,medium……"short_medium"的:someDate?string("short")someDate?string.shortdate:time:datetime:openingTime<#assignx=openingTime><#--noproblemcanoccurhere--${openingTime?time}<#--without?timeitwouldfail--<#--Forthesakeofbetterunderstanding,considerthis:--<#assignopeningTime=${openingTime}<#--thiswillworknow--Lastupdated:${lastUpdated}<#--assumethatlastUpdatedisadate-timevalue-->Lastupdateddate:${lastUpdated?date}Lastupdatedtime:Lastupdated:04/25/200308:00:54PMLastupdateddate:04/25/2003Lastupdatedtime:08:00:542javaLocale慣.比如300000300,000.如果我們把這個數(shù)字作為表單的一個域值放進數(shù)據庫或者在中使用時,需要再轉換成適合計算機輸入的格式.這個標簽用來輸出數(shù)字(例如用${x?c}替換${x})string(當跟一個數(shù)字一起使用時3:number,currency,percent.US32"number".#settingnumberformat中使用時,需要再轉換成適合計算機輸入的格式.這個標簽用來輸出數(shù)字(例如用${x?c}替換${x})string(當跟一個數(shù)字一起使用時3:number,currency,percent.US32"number".#settingnumberfo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論