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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • InnoDB数据库隔离级别

    InnoDB数据库隔离级别事务隔离级别分为四种(级别递减):1、Serializable(串行化):最严格的级别,事务串行执行,资源消耗最大;2、REPEATABLEREAD(重复读):保证了一个事务不会修改已经由另一个事务读取但未提交(回滚)的数据。避免了“脏读取”和“不可重复读取”的情况,但不能避免“幻读”,但是带来了更多的性能损失。3、READCOMMITTED(提交读):大多数主流数据库的默认事…

    2022年5月18日
    34
  • C语言整型转字符串_c++整形转字符串

    C语言整型转字符串_c++整形转字符串本文主要介绍在C++编程语言中,将整型转换为字符串类型的具体方法。1使用to_string函数在C++11标准中,可以使用to_string函数,将整型转换为字符串类型。1.1to_string函数介绍to_string函数的用法如下:stringto_string(intval);stringto_string(longval);stringto_string(longlongval);stringto_string(unsigned

    2022年10月18日
    10
  • FileStream Close「建议收藏」

    FileStream Close「建议收藏」           FileStreamf=newFileStream(“hou.txt”,FileMode.Create,FileAccess.ReadWrite);           StreamWriterwf=newStreamWriter(f);           wf.Write(“Helloworld!”);           wf.Close();

    2022年7月21日
    10
  • whl文件下载「建议收藏」

    whl文件下载「建议收藏」到哪找.whl文件?http://www.lfd.uci.edu/~gohlke/pythonlibs/转载于:https://www.cnblogs.com/lhuser/p/8084734.html

    2022年5月7日
    96
  • pycharm和Anaconda环境下安装pygame「建议收藏」

    pycharm和Anaconda环境下安装pygame「建议收藏」pycharm和Anaconda环境下安装pygamewindows系统下安装windows系统下安装1.点击windows键打开Anacondaprompt2.打开之后输入condalist可以找到pip3.然后继续输入condainstallpip等安装完成4.pip安装完成之后输入pipinstallpygame如图所示安装成功。…

    2022年8月29日
    5
  • tableau新手教程_什么是tableau

    tableau新手教程_什么是tableautableau教程快速入门先基础了解你的数据先选数据源了解你的数据源字段含义、字段类型数据更新频率、数据量、波动频率范围决定了你的时间颗粒度例子:页面转化率(约小时级别+日级别)财

    2022年8月1日
    6

发表回复

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

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