<#macro showErrors separator classOrStyle="">
<#list spring.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>${separator}
</#list>
</#macro>
答案 0 :(得分:1)
您只能使用以下宏显示第一个错误:
<#macro showFirstError classOrStyle="">
<#if (spring.status.errorMessages?has_content)>
<#local error = spring.status.errorMessages[0] />
<#if classOrStyle == "">
<b>${error}</b>
<#else>
<#if classOrStyle?index_of(":") == -1>
<#local attr="class">
<#else>
<#local attr="style">
</#if>
<span ${attr}="${classOrStyle}">${error}</span>
</#if>
</#if>
</#macro>