Springboot + Mybatis 同时支持多类数据库SQL的解决方案

pg、Oracle、MySQL 的字符串转日志函数不同,可通过 _databaseId 来判断该执行哪段SQL

多余的代码就不写上了,直接根据下列代码就能理解。

			<choose>
                <when test="_databaseId == @[email protected]">
                    WHERE t1.CH_TIME >= TO_DATE(#{beginDate, jdbcType=VARCHAR}, 'YYYY-MM-DD')
                    AND t1.CH_TIME < TO_DATE(#{endDate, jdbcType=VARCHAR}, 'YYYY-MM-DD')
                    AND (t1.EX_STATUS = '1' or t1.EX_STATUS = '3')
                when>
                <when test="_databaseId == @[email protected]">
                    WHERE t1.CH_TIME >= STR_TO_DATE(#{beginDate, jdbcType=VARCHAR},'%Y-%m-%d')
                    AND t1.CH_TIME < STR_TO_DATE(#{endDate, jdbcType=VARCHAR},'%Y-%m-%d')
                    AND (t1.EX_STATUS = '1' or t1.EX_STATUS = '3')
                when>
                <when test="_databaseId == @com.yinhai.ta404.module.mybatis.support.DriverType@POSTGRESQL.type">
                    WHERE t1.CH_TIME >= TO_DATE(#{beginDate, jdbcType=VARCHAR}, 'YYYY-MM-DD')
                    AND t1.CH_TIME < TO_DATE(#{endDate, jdbcType=VARCHAR}, 'YYYY-MM-DD')
                    AND (t1.EX_STATUS = '1' or t1.EX_STATUS = '3')
                when>
            choose>

你可能感兴趣的:(Spring,Boot,数据库,spring,boot,mybatis)