freemarker 的ObjectWrapper Settings

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109897.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 4月20日

    4月20日

    2021年9月27日
    50
  • CentOS7.0下安装FTP服务的方法

    CentOS7.0下安装FTP服务的方法

    2021年10月19日
    37
  • 除了we tool还有哪些免费安全好用的微信群发软件?这两个软件比we tool好用!

    除了we tool还有哪些免费安全好用的微信群发软件?这两个软件比we tool好用!除了wetool还有哪些安全好用的微信群发软件?群发工具是社群运营使用频率最高的工具,无论是给群内推送消息,还是给个人推送消息。按键精灵:点击左侧链接下载按键精灵是一款模拟鼠标键盘动作的软件。通过制作脚本,可以让按键精灵代替您的双手,自动执行一系列鼠标键盘动作。按键精灵免费版简单易用,不需要任何编程知识就可以作出功能强大的脚本。只要您在电脑前用双手可以完成的动作,按键精灵都可以替您完成。按键精灵用途广泛,具有大量脚本资源。简单百宝箱:点击左侧链接下载简单百宝箱是一个绿色和安全的游戏

    2022年6月4日
    94
  • 图解SM2算法流程——第4章 加密解密[通俗易懂]

    图解SM2算法流程——第4章 加密解密[通俗易懂]A.4第4部分——密钥封装和加解密A.4.1加密(UserA)说明:第3步计算S=[h]PB略,因h=1。A.4.2解密(UserB)说明:第2步计算S=[h]C1略,因h=1。A.4.3原理关键在于说明加密流程第4步计算的[k]PB=(x2,y2)与解密流程第2步计算的[dB]C1=(x2,y2)相等。解密流程第2步计算 …

    2022年10月4日
    3
  • 【SpringBoot】19、SpringBoot中实现启动任务

    【SpringBoot】19、SpringBoot中实现启动任务我们在项目中会用到项目启动任务,即项目在启动的时候需要做的一些事,例如:数据初始化、获取第三方数据等等,那么如何在SpringBoot中实现启动任务,一起来看看吧SpringBoot中提供了两种项目启动方案,CommandLineRunner和ApplicationRunner一、CommandLineRunner使用CommandLineRunner,需要自定义一个类区实现CommandLineRunner接口,例如:importorg.springframework.boot.

    2022年9月26日
    2
  • idea的mybatis插件不联网可以使用吗_idea特效插件

    idea的mybatis插件不联网可以使用吗_idea特效插件IDEA的Mybatis插件idea不支持xml和映射器接口之间的跳转安装插件:FreeMybatisplugin使用指路:https://www.jianshu.com/p/4f1c2600802c

    2022年10月7日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号