2012-02-28 53 views
0

我試圖Freemarker的HashLiteral傳遞給我的自定義方法如下:Freemarker的方法不能接受對象作爲參數

<a href="${href("Item", {"item": item})}">...</a> 

,其中不包括引號項目在ModelAndView中給出的對象。該{"item": item}正確地轉化爲freemarker.core.HashLiteral$SequenceHash,但我不能在我的方法恢復它我得到例外以下:

Expecting a string, date or number here, 
    Expression {"item": item} is instead a freemarker.core.HashLiteral$SequenceHash 

出現這種情況,即使href方法有空體:

​​

感謝

+0

「href」方法的定義是怎樣的? – ddekany 2012-02-28 15:32:18

+0

我已將href方法添加到問題中。 – 2012-02-29 06:10:04

回答

3

這可能是hrefTemplateMethodModel而不是TemplateMethodModelExTemplateMethodModel.exec(args)中的args參數是的String-s,因此FreeMarker會嘗試將該值轉換爲字符串,但只能使用字符串,日期或數字值執行此操作。所以只需將其更改爲TemplateMethodModelEx,然後args將爲ListTemplateModel -s,因此接受所有類型的值。

+0

謝謝,輝煌! – 2012-03-02 10:02:31

相關問題