2010-02-09 12 views
2

nVelocity(或Velocity)中的if或if語句不是真或假的語法是什麼?nVelocity中if錯誤的語法是什麼?

更重要的是,這是在nVelocity文檔中的位置?我一直在谷歌搜索一段時間無濟於事。

我試過幾個不同的組合,如:

#if (!$artist.IsFestival) 

$artist.FestivalName 

#end 

#if ($artist.IsFestival == false) 

$artist.FestivalName 

#end 

這麼折騰!

在此先感謝!

-ev

+0

nvelocity docs:http://www.castleproject.org/others/nvelocity/index.html – 2010-02-09 11:10:14

+0

IsFestival是一個公共財產? – 2010-02-09 11:10:58

+0

@MauricioScheffer您的nvelocity文檔鏈接不再工作...因爲速度語法錯誤!大聲笑 – BritishDeveloper 2012-09-24 11:45:38

回答

1

這些都應該有工作,所以我想你可能訪問「isFestival」的問題。您應該嘗試bean語法$artist.festival或方法語法$artist.isFestival()(您現在正在使用兩者的混合)。 該方法返回一個布爾值,對嗎?

爲了調試嘗試剛剛打印出來的結果,看看它的工作原理:

$artist   ## see if the artist is defined 
$artist.IsFestival ## maybe an error 
$artist.festival ## should be true or false 
$artist.isFestival() ## should be true or false 

更新:剛讀你問nVelocity。我的答案可能只適用於Java版本。無論如何,試試吧。

+1

真的NVelocity – 2010-02-09 06:18:11

+0

啊非常感謝。 但我真的需要知道如果否定測試,所以如果某事是不正確的。我該怎麼說:if(not $ artist.IsFestival)? – 2010-02-11 23:39:26

+0

您顯示的兩種模式都應該有效('!$ x'和'$ x == false')。 – Thilo 2010-02-12 01:35:19