1.在连接数据库时候,mysql是否支持fetchsize分页获取?

  满足以下几个条件,可以使用fetchsize,根据游标获得记录

  ①MySQL 从5.0.2开始支持分页获得.

  ②同时需要在jdbc连接参数上配置 jdbc:mysql://localhost:3306/test?useCursorFetch=true

  ③设置FetchSize,在mybatis的 具体查询语句中配置 。<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap" fetchSize="5">

  ④isBinaryEncoded 如果是使用PreparedStatement则这个值为true

  ⑤如果使用PreparedStatement,则会生成JDBC42ServerPreparedStatement对象,在访问数据库时,会自动设置resultsetType=ResultSet.TYPE_FORWARD_ONLY

  疑问:mybatis什么情况下会将statement的类型初始化为PreParedStatement?

    在sql配置文件中有一个参数,statementType 可以自己设置。要不即使参数使用${}。也还是会使用PreparedStatement。默认是PreparedStatement

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap" fetchSize="5" statementType="PREPARED">

  

  在MySQL的JDBC源码中:MysqlIO中

            //版本>=5.0.2 && 连接上配置useCurSorFetch=true &&isBinaryEncoded =true && 
          if (this.connection.versionMeetsMinimum(5, 0, 2) && this.connection.getUseCursorFetch() && isBinaryEncoded && callingStatement != null
&& callingStatement.getFetchSize() != 0 && callingStatement.getResultSetType() == ResultSet.TYPE_FORWARD_ONLY) {
ServerPreparedStatement prepStmt = (com.mysql.jdbc.ServerPreparedStatement) callingStatement; boolean usingCursor = true; //
// Server versions 5.0.5 or newer will only open a cursor and set this flag if they can, otherwise they punt and go back to mysql_store_results()
// behavior
// if (this.connection.versionMeetsMinimum(5, 0, 5)) {
usingCursor = (this.serverStatus & SERVER_STATUS_CURSOR_EXISTS) != 0;
} if (usingCursor) {
RowData rows = new RowDataCursor(this, prepStmt, fields); ResultSetImpl rs = buildResultSetWithRows(callingStatement, catalog, fields, rows, resultSetType, resultSetConcurrency, isBinaryEncoded); if (usingCursor) {
rs.setFetchSize(callingStatement.getFetchSize());
} return rs;
}
}

2.Mybatis开启Mapper级别的缓存时,注意Bean需要继承Serializer接口

Mybatis常见疑问的更多相关文章

  1. Mybatis常见配置错误总结

    Mybatis常见配置错误总结 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionF ...

  2. 【面经】MyBatis常见面试问题

    1.什么是 MyBatis? 答:MyBatis 是一个可以自定义 SQL.存储过程和高级映射的持久层框架. 2.讲下 MyBatis 的缓存 答:MyBatis 的缓存分为一级缓存和二级缓存,一级缓 ...

  3. mybatis常见易出错

    在学习mybatis的过程中,发现了很多错误,这里记录一下,以供后来使用 1,config.xml文件中配置项的顺序: org.apache.ibatis.exceptions.Persistence ...

  4. spring + myBatis 常见错误:注解事务不回滚

    最近项目在用springMVC+spring+myBatis框架,在配置事务的时候发现一个事务不能回滚的问题. 刚开始配置如下:springMVC.xml配置内容: spring.xml配置内容 从上 ...

  5. spring + myBatis 常见错误:@Autowired注解失败

    今天配置spring+myBatis的时候,使用注解@Autowired把持久层dao注入service层的时候总是报错. 查了好久才发现,居然是配置文件路径写错了.basepackge的路径一定要正 ...

  6. mybatis常见错误总结

    1. 现象:mybatis xml文件中查询的返回类型写成list或java.util.List时,执行sql时报 java.lang.UnsupportedOperationException错误. ...

  7. springboot mybatis常见异常及处理方法

    1.in导致的异常 Data truncation: Truncated incorrect DOUBLE value: 异常过程: mapper接口如下: public int updateBatc ...

  8. RESTful设计中的常见疑问

    最近写了几个有关RESTful的API相关内容,也谈谈对常见问题的自己的理解. 什么是RESTful 详情可以看http://www.ruanyifeng.com/blog/2011/09/restf ...

  9. mybaits(十)mybatis常见面试

      面试题总结 1.MyBatis 解决了什么问题? 或:为什么要用 MyBatis? 或:MyBatis 的核心特性? 1)资源管理(底层对象封装和支持数据源) 2)结果集自动映射 3)SQL 与代 ...

随机推荐

  1. 使用Axure做验证码之获取验证码(一)

    本次作业,制作验证码,仅完成获取验证码操作,如下: 分析: 左图为矩形,主要展示验证码(本例设置4位验证码),其中验证码为字母和数字组合: 右图为文本输入框,主要设置点击事件,即点击文本文字,矩形框中 ...

  2. Xcode注释转文档appledoc使用

    参考了一些大神的方法总算成功了记录一下少走弯路 1:安装appledoc 使用终端下载: 命令行: git clone git://github.com/tomaz/appledoc.git cd . ...

  3. AC, FVOCI, FVPL

    IFRS9 会计新准则中规定了资产划分依据为合同现金流特征及业务模式. 关键词:资产负债表,利润表,损益,利率风险 AC账户: 为收取合同约定的现金流.持有到期业务. 资产在持有期内不变,使用摊余成本 ...

  4. videojs播放直播源rtmp时画面在左上角解决方案

    问题描述:https://stackoverflow.com/questions/30383135/videojs-live-rtmp-stream-player-and-video-size-iss ...

  5. Java——string类型与date类型之间的转化

    String类型转化为Date类型 方法一 Date date=new Date("2019-01-25"); 方法二 String =(new SimpleDateFormat( ...

  6. 认识Ajax

    1.简介 AJAX 相当于异步 JavaScript 和 XML,是一种用于创建快速动态网页的技术.通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个网 ...

  7. 锋利的jQuery初学(5)

    层级选择器: 层级选择器 符号 解释 使用 空格 后代选择器 $("div p").css("","") + 紧邻选择器 $("d ...

  8. LeetCode 922. Sort Array By Parity II C++ 解题报告

    922. Sort Array By Parity II 题目描述 Given an array A of non-negative integers, half of the integers in ...

  9. 简述iproute家族命令

    ifconfig 是用来查看.配置.启用或禁用网络接口的工具.可以用这个工具来临时配置网卡的IP地址.掩码.广播地址.网关等. 语法 ifconfig [interface] 参数 up 启动指定网络 ...

  10. mint-ui loadmore使用方法和注意事项

    最好按照github里的例子ctrl+c => v 模版.js mint-ui/example/pages/pull-up.vue 注意设置:mt-loadmore组件:auto-fill='a ...