Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

java - Velocity nulls and empty strings

In velocity I have a variable which its value is null. I don't want to display anything in that case.

Currently the template engine translates "" to null so I have to do.

#set ( $a = "")
#if ($a) 
   assert("never prints a neither gets here: " + $a)
#end

Is there a way I could do that directly? I'd like to be able to make something like:

This is the variable $a. ## in case that $a is null i don't want 'dollar a' to be displayed
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

$!a does the trick. You can use this form directly without an if check.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...