在Config(MybatisConfig或者MybatisPlusConfig)中添加,例如添加Mysql和DM
@Beanpublic DatabaseIdProvider databaseIdProvider(){VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();Properties properties = new Properties();properties.put("MySQL","mysql");properties.put("DM DBMS","dm");databaseIdProvider.setProperties(properties);return databaseIdProvider;}
或者在mybatis-config.xml中添加
<databaseIdProvider type="DB_VENDOR"><property name="MySQL" value="mysql"/> <property name="DM DBMS" value="dm" />
</databaseIdProvider>
然后Mybatis的xml中就可以使用
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.elements.user.dao.dbMapper" ><select id="SelectTime" resultType="String" databaseId="mysql">SELECT NOW() FROM dual </select><select id="SelectTime" resultType="String" databaseId="dm">SELECT 'oralce'||to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') FROM dual </select>
</mapper>
或者
<select xxxx>
<if test="_databaseId == 'mysql'">create_time between date_add(now(), interval - 10 minute) and now()</if><if test="_databaseId == 'dm'">create_time between sysdate() - 10/24/60 and sysdate()</if>
</select>
用来判断数据库类型