关于 struts2 和freemarker合作来处理 map 类型的情况:
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类型的)
转载于:https://my.oschina.net/mam/blog/206141
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/109897.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...