SpringBoot 框架结合Mybatis-Plus 连接不同的数据源实现自定义分页展示数据
由于Mysql和Oracle 分页查询语句不同,导致自定义时采用不同的方法执行查询
MySql
接口:
/**
* @method:
* @description:
* @author: ityemu
* @param: pageNum 第几页
* @param: pageSize 每页展示数量
* @param: queryWrapper 查询条件
* @return:
*/
IPage<SysDictCategory> selectMyPageByOracle(@Param("start")Integer pageNum,
@Param("end")Integer pageSize,
@Param(Constants.WRAPPER)QueryWrapper queryWrapper);
XML
<select id="selectMyPageByMysql" resultMap="BaseResultMap">
select
*
from temp
${ew.customSqlSegment}
</select>
Oracle:
接口:
/**
* @method:
* @description:
* @author: ityemu
* @param: page 分页数据
* @param: queryWrapper 查询条件
* @return:
*/
IPage<SysDictCategory> selectMyPageByMysql(IPage page, @Param(Constants.WRAPPER)QueryWrapper queryWrapper);
XML
<select id="selectMyPageByOracle" resultMap="BaseResultMap">
select * from (select tt.*, ROWNUM num from (
select *
from temp
${ew.customSqlSegment}
<![CDATA[ ) tt where ROWNUM <= #{end} ) q where q.num >= #{start} ]]>
</select>
注:
XML文件中${ew.customSqlSegment} 就是查询条件
可以根据自己的数据源来使用不同接口