简体   繁体   English

删除org.apache.commons.lang模板中的$ {var}以获取空白值

[英]Remove ${var} in org.apache.commons.lang templates for blank values

I am a new user of org.apache.commons library. 我是org.apache.commons库的新用户。 I am using this for few templates in my project. 我在项目中的一些模板中使用了它。 For one of the requirment , we are getting inputs from HTML form and rendering as per commons template. 对于其中一项要求,我们从HTML表单获取输入,并按照commons模板进行呈现。 I have created a sample template like this - 我已经创建了一个这样的示例模板-

Hello ${user} how are you doing. Here is your order ${order}

Its working fine when I input both the values from form (user and order). 当我输入表单(用户和订单)中的两个值时,它的工作正常。 It gives me following output Hello Jhon, here is your order - Two New Books. 它给了我以下输出Hello Jhon,这是您的订单-两本新书。

But, if I enter only one value, it shows the template variable. 但是,如果我仅输入一个值,它将显示模板变量。 like 喜欢

Hello Jhon, here is your order ${order}

I need to avoid this variable. 我需要避免这个变量。 Any suggestion ? 有什么建议吗?

Note: I can not control form inputs at HTML end, that is a third party form. 注意:我无法控制HTML端的表单输入,即第三方表单。

Thanks !! 谢谢 !!

I figures this out.I should set a default value for unresolved variables. 我想通了,我应该为未解析的变量设置一个默认值。 I did like 我喜欢

Hello ${user:-} Here is your order ${order:-} 

You can also give default values to unresolved variables like 您还可以将默认值提供给未解析的变量,例如

Hello ${user:-Guest} Here is your order ${order:-air}

Thanks ! 谢谢 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 包org.apache.commons.lang不存在[Netbeans] - package org.apache.commons.lang does not exist [Netbeans] Java:无法解析导入org.apache.commons.lang [Eclipse] - Java: The import org.apache.commons.lang cannot be resolved [Eclipse] 如何在Java中使用org.apache.commons.lang命名空间? - How to use org.apache.commons.lang namespace in Java? 无法在JSP页面上导入org.apache.commons.lang - Trouble importing org.apache.commons.lang on JSP page NoClassDefFoundError: org/apache/commons/lang3/StringUtils - NoClassDefFoundError: org/apache/commons/lang3/StringUtils python中的org.apache.commons.lang.StringEscapeUtils - org.apache.commons.lang.StringEscapeUtils in python NoClassDefFoundError:org / apache / commons / lang / StringUtils - NoClassDefFoundError: org/apache/commons/lang/StringUtils java.lang.NoClassDefFoundError:org / apache / commons / lang / text / StrLookup - java.lang.NoClassDefFoundError: org/apache/commons/lang/text/StrLookup java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder - java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder org.apache.commons.lang.SerializationException:java.lang.ClassNotFoundException - org.apache.commons.lang.SerializationException: java.lang.ClassNotFoundException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM