- 1、本文档共9页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
freemarker对null的处理
freemarker对null的处理 1 提供默认值 #if mouse? Mouse found #else 也可以直接${mouse?if_exists} #if user.age?? //TO DO /#if 2.忽略null值 假设前提:userName为null ${userName} error ${userName!} 空白 ${userName!tivon} tivon 假设前提:user.name为null ${user.name},异常 ${(user.name)!},显示空白 ${user.name!vakin},若user.name不为空则显示本身的值,否则显示vakin ${user.name?default(vakin)},同上 ${user.name???string(user.name,vakin)},同上 3 list #list userList as user … /#list List指令还隐含了两个循环变量: user_index:当前迭代项在所有迭代项中的位置,是数字值。 user_has_next:用于判断当前迭代项是否是所有迭代项中的最后一项。 这2个值也可以控制 null 或者0的出现。 4#escape x as x!/#escape可以对所有的变量进行空值处理,这里是全部替换为空字符串。当然也可以替换为其它字符串。 如果其中某些变量不需要这种替换,可以加入#noescape/#noescape标签。 5 这种为全局配置方法 配置classic_compatible=true可以满足一般需要。默认情况变量为null则替换为空字符串,如果需要自定义,写上${empty!EmptyValue of fbysss}的形式即可 a.通过Configuration设置。Configuration cfg = new Configuration(); cfg.setClassicCompatible(true);//设置属性 b.通过Eviroment设置。 Environment env = template.createProcessingEnvironment(root, out); env.setClassicCompatible(true); c.通过ftl设置:在ftl前加入!--#setting classic_compatible=true--; d.通过Spring配置文件设置 bean id=freemarkerConfig class=org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer property name=freemarkerSettings props prop key=classic_compatibletrue/prop /props /property /bean e.class目录下添加freemarker.properties文件:加入classic_compatible=true (需要struts2或spring) 举一反三,其他属性也可以用类似方法进行设置。 补充知识点: Freemarker中对List进行排序 通常我们的排序操作都是通过DAO层来实现的,如果我们想随时更改我们的排序,那么就必须修改我们的DAO层代码,确实不方便。但Freemarker为我们提供了这样的排序方法,解决了这个问题。 1. sort升序排序函数 sort对序列(sequence)进行排序,要求序列中的变量必须是:字符串(按首字母排序),数字,日期值。 #list list?sort as l…/#list 2. sort_by函数 sort_by有一个参数,该参数用于指定想要排序的子变量,排序是按照变量对应的值进行排序,如: #list userList?sort_by(age) as user…/#list age是User对象的属性,排序是按age的值进行的。 3. reverse降序排序函数 #list list? reverse as l…/#list reverse使用同sort相同。reverse还可以同sort_by一起使用 如:想让用户按年龄降序排序,那么可以这个样写 #list userList?sort_by(“age”)?reverse as user…/#list * * * *
您可能关注的文档
- Evaluation of Drug Interaction in Binding to Protein by High Performance Liquid Chromatogra.pdf
- Evaluation of fatigue damage.pdf
- Evaluation of hadronic vacuum polarization contribution to muonium hyperfine splitting.pdf
- Evaluation of Machine Translation Output for an Unknown Source Language Report of an ISLEB.pdf
- Evaluation of nutritional quality of moringa (Moringa oleifera Lam.) leaves as an alternative protei.pdf
- Evaluation of ObjectOriented Reflective Models.pdf
- Evaluation of ontologies.pdf
- Evaluation of Piecewise Affine Control via Binary Search Tree.pdf
- Evaluation of Pressure Tensor in ConstantVolume Simulations of Hard and Soft Convex Bodies.pdf
- Evaluation of Performance of Cooperative Web Caching with Web.pdf
- 人教版英语5年级下册全册教学课件.pptx
- 部编人教版2年级上册语文全册教学课件含单元及专项复习.pptx
- 人教版8年级上册英语全册教学课件(2021年8月修订).pptx
- 教科版(2017版)6年级上册科学全册课件+课时练.pptx
- 人教版PEP版6年级英语下册全册教学课件(2022年12月修订).pptx
- 部编人教版2年级下册语文全册课件(2021年春修订).pptx
- 人教版数学6年级下册全册教学课件(2023年教材).pptx
- 湘少版5年级下册英语全册教学课件(2021年春修订).pptx
- 人教PEP4年级下册英语全册教学课件 [2}.pptx
- 人教版6年级上册英语全册教学课件.pptx
文档评论(0)