sql如果不想將邏輯寫在sql或代碼中分離出來的話可以使用mybatis標籤
mybatis 做簡單條件判斷的時候可以選用<choose/> <when/>標籤
當傳入的封裝對象中有枚舉類型的時候是無法將枚舉類型直接和字符串繼續比較的,如下圖
<choose>
<when test="queryType == 'DAY'">
to_char(createTime,'YYYY-MM-dd')
</when>
<when test="queryType == 'HOUR'">
to_char(createTime,'YYYY-MM-dd hh24')
</when>
<otherwise>
to_char(createTime,'YYYY-MM')
</otherwise>
</choose>
想要可以進行比較的花可以
<choose>
<when test="queryType.toString == 'DAY'">
to_char(createTime,'YYYY-MM-dd')
</when>
<when test="queryType.toString == 'HOUR'">
to_char(createTime,'YYYY-MM-dd hh24')
</when>
<otherwise>
to_char(createTime,'YYYY-MM')
</otherwise>
</choose>