简体   繁体   中英

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

I am a new user of org.apache.commons library. 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. 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.

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.

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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM