freeMarker 自定義標籤

2021-08-08 18:22:20 字數 750 閱讀 7553

freemarker 自定義標籤(取後台資料),上乾貨

1、freemarker配置工廠

2、後台**實現

@service

public class contentdirective implements templatedirectivemodel

public void execute(environment env, map params, templatemodel loopvars,

templatedirectivebody body) throws templateexception, ioexception

//list轉換

if (paramvalue instanceof collectionmodel)

}if (paramvalue instanceof ******sequence)

}//將params屬性copy到seachdto

try catch (illegalacces***ception | invocationtargetexception e)

//todo 業務邏輯

liststrings = new arraylist();

body.render(env.getout());

}

3、前台ftl呼叫

freemarker 自定義指令

自定義指令可以使用,marco指令來進行定義 巨集 是有乙個變數名的模板片段,在模板中使用巨集作為自定義指令,這樣就能供其他頁面使用。hello joe macro 指令只是用來建立巨集變數,自身不輸出任何內容,所以就會有乙個名為 greet 的變數。在 macro greet 和 之間的內容 稱為...

Freemarker自定義指令

在做乙個cms 時,要列出 欄目,比如有新聞,科技,體育,財經等欄目。欄目內容存放在資料庫中。沒有迴圈變數 user def dir exp param1 val1 param2 val2 paramn valn 有迴圈變數 user def dir exp param1 val1 param2 v...

FreeMarker自定義指令

摘要 freemarker自定義指令就像struts2的set標籤,為了好理解,也可以認為是定義乙個方法,就像js的function.在freemarker中的這個標籤就是macro。在定義乙個指令的時候,可以指定引數,當然也可以不指定,這裡要注意了,我這裡只貼出模板檔案及輸出結果,freemark...