mybatis及hibernate下的MySQL和oracle数据库分页详解

mybatis下的分页

- MySQL

  • 因为MySQL自带 limit 关键字分页
/**
 起始索引start,结束索引end
 int pageIndex=1;//当前页数
 int countPage=3;//每页显示条目数
 int start=(pageIndex-1)×countPage;//每页的起始索引
 int end=countPage;//表示要显示的个数
 因为索引从0开始
 所以[start,end)=[0,3)
**/
@Select("select * from user_tab limit #{start},#{end}")
List<User>pageQuery(@Param("start")intstart,@Param("end")int end);

- Oracle

  • oracle没有limit分页所以通过子查询完成
1.排序起别名u (select * from user_tab order by id ) u
2.查询所有及伪列 (select u.*,rownum r from (select * from user_tab 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要将 MyBatis-Plus 从 MySQL 切换到 Oracle 数据库,需要进行以下步骤: 1. 修改数据库驱动和连接信息 在 pom.xml 文件中将 MySQL数据库驱动和连接信息替换为 Oracle 的,例如: ``` <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc8</artifactId> <version>19.3.0.0</version> </dependency> ``` 同时,在 application.yml 或 application.properties 文件中修改数据库连接信息,例如: ``` spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl spring.datasource.username=your_username spring.datasource.password=your_password ``` 2. 修改 MyBatis-Plus 的配置 在 MyBatis-Plus 的配置文件中,需要将 MySQL 的方言替换为 Oracle 的,例如: ``` mybatis-plus: mapper-locations: classpath*:mapper/**/*.xml global-config: db-config: id-type: ID_WORKER table-prefix: mp_ field-strategy: not_empty logic-delete-value: 1 logic-not-delete-value: 0 sql-injector: com.baomidou.mybatisplus.core.injector.LogicSqlInjector configuration: map-underscore-to-camel-case: true log-impl: org.apache.ibatis.logging.stdout.StdOutImpl dialect-type: oracle ``` 3. 修改 SQL 语句 在 XML 映射文件中,需要将 MySQL 的 SQL 语句替换为 Oracle 的,例如: ``` <select id="getUserById" resultType="User"> SELECT * FROM user WHERE id = #{id} </select> ``` 修改为: ``` <select id="getUserById" resultType="User"> SELECT * FROM user WHERE id = #{id} </select> ``` 需要注意的是,Oracle 数据库中的 SQL 语法与 MySQL 有所不同,需要进行相应的修改。 完成以上步骤后,即可将 MyBatis-Plus 从 MySQL 切换到 Oracle 数据库

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值