freemarker 的ObjectWrapper Settings

关于 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值