在寫mybatis的xml文件時總會有<if></if>標(biāo)簽出現(xiàn),里面的條件可能隨手就寫成了固定數(shù)值,這樣會造成日后代碼難以維護(hù)。
MybBatis是支持這樣的需求在ongl中:
select * from user where 1=1
<if test="idNumber != null and @com.mr.cn.Contants@userLevel == sumNumber">
and id_number = ${@com.mr.cn.Contants@userLevel }
</if>
以上的調(diào)用均為java類的公共常量,靜態(tài)方法也可以調(diào)用。例如@com.mr.cn.Contants@getLevel 即可直接調(diào)用方法