@Mike:看來你有麻煩理解宏的本質。他們已經寫了freemarker腳本,讓你的生活更輕鬆。您始終可以使用write a customed one。
有些人認爲這很明顯,但是我自己發現知道如何查看無彈標誌宏源代碼並不容易。您可以導航到Eclipse的「參考庫」中的包org/springframework/spring-webmvc-3.0.5.jar/org/springframework/web/servlet/view/freemarker/spring.ftl
。
這裏的宏「showErrors」,從「spring.ftl」得到:
<#macro showErrors separator classOrStyle="">
<#list status.errorMessages as error>
<#if classOrStyle == "">
<b>${error}</b>
<#else>
<#if classOrStyle?index_of(":") == -1><#assign attr="class"><#else><#assign attr="style"></#if>
<span ${attr}="${classOrStyle}">${error}</span>
</#if>
<#if error_has_next>${separator}</#if>
</#list>
</#macro>
爲了實現自己的目標,這是非常簡單:只需編寫自定義宏是完全一樣,上面的代碼,通過更換span
div