时间:2021-07-01 10:21:17 帮助过:3人阅读
MutiDatasourcePaginationPlugin 类文件为扩展的mybatis-generator 插件,用来在生成代码文件的过程中,完成不同数据库支持下的分页逻辑代码部分;
此例中只需要关心生成的 MutiDatabaseMapper.xml:
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.alexgaoyh.MutiModule.persist.mutiDatabase.MutiDatabaseExample"> <include refid="OracleDialectPrefix" /> select <if test="distinct"> distinct </if> <include refid="Base_Column_List" /> from mutidatabase mutiDatabase <if test="_parameter != null"> <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null"> order by ${orderByClause} </if> <include refid="OracleDialectSuffix" /> <include refid="MysqlDialect" /> </select> <sql id="OracleDialectPrefix"> <if test="page != null and _databaseId == ‘oracle‘"> select * from ( select row_.*, rownum rownum_ from ( </if> </sql> <sql id="OracleDialectSuffix"> <if test="page != null and _databaseId == ‘oracle‘"> <![CDATA[ ) row_ ) where rownum_ > #{page.begin} and rownum_ <= #{page.end} ]]> </if> </sql> <sql id="MysqlDialect"> <if test="page != null and _databaseId == ‘mysql‘"> limit #{page.begin} , #{page.length} </if> </sql>
这样,通过 databaseIdProvider 的不同,就完成不同sql语句的引入操作;
部分链接:
http://stackoverflow.com/questions/29139092/mybatis-multi-datasource-configuration-issue
https://mybatis.github.io/spring/factorybean.html
mybatis-generator 插件扩展,生成支持多种数据库的分页功能
标签: