Mybatis__doFlushStatements

相信看过Mybatis的执行器Executor以及5个子类源码的朋友应该对FlushStatements和doFlushSatements知道吧,这里我们说说它的作用,顾名思义的话了就是刷新Statement,我们知道在执行器就是执行Statement的,在进行提交,回滚等事务操作以及DML操作时,需要刷新Statement,在不同的Executor执行器中因为缓存执行器需要缓存,SimpleStatement执行完就关闭Statement,ReuseExecutor执行完不关闭而是返回Map集合中,等,所以在各执行器中的doFlushSatements也是不同的。

BaseExecutor
我们知道BaseExecutor是Executor顶层接口的子类,也是执行器类的基类,它基本实现了Update和quart还有commit,rollback等功能,还有定义了抽象方法doUpdate(),doQuery(), doFlushStatement()给其子类去实现符合各自的方法,它也简单的实现了flushStatement的功能,也定义了doFlushStatement抽象方法给子类去实现。

@Override
  public List<BatchResult> flushStatements() throws SQLException {
	
    return flushStatements(false);
  }

  public List<BatchResult> flushStatements(boolean isRollBack) throws SQLException {
    if (closed) {
      throw new ExecutorException("Executor was closed.");
    }
    return doFlushStatements(isRollBack);
  }


/**
   * 事务提交
   */
  @Override
  public void commit(boolean required) throws SQLException {
    if (closed) {
      throw new ExecutorException("Cannot commit, transaction is already closed");
    }
    //清除缓存
    clearLocalCache();
    //flushStatements里,不
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
MyBatis PageHelper是一个用于实现分页查询的插件,它可以帮助我们快速实现分页功能,并且与Mapper.xml完全解耦,避免了直接编写分页SQL的麻烦。在使用MyBatis PageHelper时,可以根据不同的情况进行配置。 如果你使用的是Spring Boot,可以直接配置几个属性来启用MyBatis PageHelper。在application.properties或application.yml文件中,添加以下配置项: ``` mybatis.configuration-properties.helperDialect=mysql mybatis.configuration-properties.offsetAsPageNum=true mybatis.configuration-properties.rowBoundsWithCount=true mybatis.configuration-properties.reasonable=true mybatis.configuration-properties.mapper-locations=mybatis/mapper/*.xml ``` 其中,helperDialect指定了数据库的方言,offsetAsPageNum设置为true表示使用RowBounds分页方式,rowBoundsWithCount设置为true表示查询总数时会同时执行count查询,reasonable设置为true表示当pageNum<=0或pageNum>pages时会自动修正为合理的值,mapper-locations指定了Mapper.xml文件的位置。 另外,如果你使用的是Spring Boot,还可以直接引入pagehelper-spring-boot-starter依赖,它会自动配置PageHelper,省去了许多不必要的配置。 ```xml <!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.12</version> </dependency> ``` 通过以上配置,你就可以在MyBatis中使用PageHelper来实现分页查询了。 #### 引用[.reference_title] - *1* [【Mybatis】使用PageHelper进行分页查询](https://blog.csdn.net/Flying_Ape/article/details/128098911)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Mybatis分页插件——PageHelper快速入门](https://blog.csdn.net/weixin_52850476/article/details/124802877)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

偷偷学习被我发现

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值