Mybatis mapper.xml下引用静态方法、静态常量或者枚举类型

一、引用静态方法

(1)在ONGL中引用

<select id="selectTest">
<if test="@com.test.DateUtils@isLeapYear(year)==true">
  select * from tableA
</if>
<if test="@com.test.DateUtils@isLeapYear(year)==false">
  select * from tableB
</if>
</select>

(2)在SQL中引用

<select id="selectTest">
  select * from tableA where year=${@com.test.DateUtils@getYear()}
</select>

二、引用静态常量

(1)在ONGL中引用

<select id='selectTest'>
<if test="year==@com.test.Consants@CURRENT_YEAR">
  select * from tableA
</if>
</select>

(2)在SQL中引用

<select id="selectTest">
  select * from tableA where year=${@com.test.Constants@CURRENT_YEAR}
</select>

三、引用枚举类型

(1)在ONGL中引用

<select id='selectTest'>
<if test="year==@com.test.Enums@YEAR.getValue()">
  select * from tableA
</if>
</select>

(2)在SQL中引用

<select id="selectTest">
  select * from tableA where year=${@com.test.Enums@YEAR.getValue()}
</select>
posted @ 2022-04-24 16:17  寒爵  阅读(1551)  评论(0编辑  收藏  举报