我有一個s:iterator像s:if下面的
<s:iterator var="connections" value="serviceItems">
<s:if test='disableCheckBox == "Y"'>
disableCheckBox works
</s:if>
<s:if test='#{troubleSupported.equals("true")}'>
troubleWorks
</s:if>
</s:iterator>
上面的代碼有效,但是如果我像下面這樣更改第二個,它就不起作用。
<s:if test="troubleSupported=='true'">
<s:if test="troubleSupported.equals('true')">
有人可以解釋造成這種差異的原因。我在這里做錯了嗎?
我能看到的唯一區別是,action 變數被宣告為boolean用于 troubleSupported 和StringdisableCheckBox (注意:不是直接,而是通過一些間歇性向量)。這會像我所看到的那樣影響結果嗎?
PS:為了更復雜一點,如果我將單引號和雙引號換成作業場景,
<s:if test="disableCheckBox == 'Y'">不作業,
但
<s:if test="#{troubleSupported.equals('true')}">繼續作業。
目前,我不看這個。我對我原來的問題感到很困惑。:)
uj5u.com熱心網友回復:
<s:if test="troubleSupported=='true'">不是在 java 和許多其他語言中檢查相等性的正確方法。正確的方法是:<s:if test="troubleSupported===true">。更好的是:<s:if test="troubleSupported">因為你想測驗你的布林值是否為真,所以保持簡單。
您也可以使用類似 thymeleaf 的運算式檢查布林值,但它更冗長 : <s:if test="#{troubleSupported.equals('true')}">。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/431388.html
