0
我有包含對象的列表,我想對其進行更改。如何更新Freemarker中的列表索引對象值
<#list Users as usr>
/*It is not reflect into the list */
<#assign usr.Name="Jhone">
</#list>
我有包含對象的列表,我想對其進行更改。如何更新Freemarker中的列表索引對象值
<#list Users as usr>
/*It is not reflect into the list */
<#assign usr.Name="Jhone">
</#list>
首先,模板不應修改數據模型。所以如果你真的想這樣做,請三思。
如果您仍然想這樣做,FreeMarker的沒有明確的支持,但如果usr
在Java中的公共setName(String)
方法,你可以調用:${usr.setName("Jhone")}
。
不知道/*It is not reflect into the list*/
是什麼意思。由於用戶對象來自列表,因此更改用戶對象也會更改列表中的用戶對象。