does freemarker support show all variable in data-model?

前端 未结 2 942
陌清茗
陌清茗 2020-12-17 19:40

I want to see all variables in freemarker data-model, just like struts2 debug tag to show value stack.

Is there a way for freemarker to do this ?

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 20:17

    An even more detailed way would be this macro:

    <#macro dump_object object debug=false>
        <#compress>
            <#if object??>
                <#attempt>
                    <#if object?is_node>
                        <#if object?node_type == "text">${object?html}
                        <#else><${object?node_name}<#if object?node_type=="element" && object.@@?has_content><#list object.@@ as attr>
                            ${attr?node_name}="${attr?html}">
                            <#if object?children?has_content><#list object?children as item>
                                <@dump_object object=item/><#else>${object} </${object?node_name}>
                    <#elseif object?is_method>
                        #method
                    <#elseif object?is_sequence>
                            [<#list object as item><@dump_object object=item/><#if !item?is_last>, ]
                    <#elseif object?is_hash_ex>
                            {<#list object as key, item>${key?html}=<@dump_object object=item/><#if !item?is_last>, }
                    <#else>
                        "${object?string?html}"
                    
                <#recover>
                    <#if !debug>
                
            <#else>
                null
            
        
    
    
    <@dump_object object=.data_model/>
    

    This gives you a full dump of your data model.

提交回复
热议问题