MyBatis 判斷條件爲等於的時候,常量需要加 .toString()

當MyBatis 判斷條件爲等於的時候,常量需要加 .toString() 來轉換,這種方法是穩定的,推薦使用,比如:

<!-- 正確的,穩定,推薦使用 -->  
<if test="newsImage != null and newsImage == '0'.toString()">  
    <![CDATA[ and len(newsImage) > 0 ]]>  
</if> 
<if test="pd.T_STA_TIME != null and pd.T_STA_TIME != '' and '2'.toString() eq pd.sType"><!-- 關鍵詞檢索 -->
   	AND W.T_STA_TIME &lt;= TO_DATE(#{pd.T_STA_TIME}, 'yyyy-mm-dd hh24:mi:ss') 
   	AND W.T_END_TIME &gt;= TO_DATE(#{pd.T_STA_TIME}, 'yyyy-mm-dd hh24:mi:ss')
</if>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章