struts2 官方如下说:
Once you get familiar with FreeMarker, you will find certain subtletieswith it that may become frustrating. The most common thing you'll likely run in to is the BeansWrapper provided by FreeMarker. If you don't know what this is, don't worry. However, if you do, know this:
The StrutsBeanWrapper extends the default FreeMarker BeansWrapper and provides almost no change in functionality, except for how it handles maps. Normally, FreeMarker has two modes of operation: either support for friendly map built-ins (?keys, ?values, etc) but only support for String keys; OR no special built-in support (ie: ?keys returns the methods on the map instead of the keys) but support for String and non-String keys alike. Struts provides an alternative implementation that gives us the best of both worlds.
It is possible that this special behavior may be confusing or can cause problems. Therefore, you can set the struts.freemarker.wrapper.altMap property in struts.properties to false, allowing the normal BeansWrapper logic to take place instead.
这里大致的意思就是,freemarker关于map的处理方式有两种,都是 使用freemarker内建的map?keys
我以前只是使用map?keys返回 这个map当中所有的key的列表,
struts提供了<constant name="struts.freemarker.wrapper.altMap" value="false"/> 参数供我们设置:
当值为true的时候,map?keys返回 map中key的列表 不(这时候map的key只能是String类型的)。当值设置为fase的时候,map?keys返回的是map这个类的所有方法和内容,例如map?keys?size返回22,因为map有22个方法。也可以使用
此时(map的key可以是string或者不是string类型的)
来源:oschina
链接:https://my.oschina.net/u/180543/blog/206141