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. centos7下部署node应用程序

    一.安装node 二.安装nginx 三.使用express写一个简单的demo,并且使用pm2部署 四.错误 invalid PID number "" in "/ru ...

  2. linux下用命令安装node&pm2

    我的安装环境是腾讯云centos7操作系统,并且将安装包下载到了/usr/local/src目录下 一.下载node安装包 1.wget https://npm.taobao.org/mirrors/ ...

  3. D1——初读《Head First Java》

    今天随便看了点<Head First Java>,发觉这本书的风格真是有趣.打算先把这本书踏踏实实的看了.学习切忌好高骛远.心浮气躁,尤其入门基础阶段更应该踏踏实实地学习知识.下面随便谈谈 ...

  4. s21day14 python笔记

    s21day14 python笔记 一.内容回顾及补充 参数补充 对于函数的默认值是可变类型 # 如果要想给value设置默认是空列表 # 不推荐(坑) def func(data,value=[]) ...

  5. Golang安装与环境的配置

    (一) 不需FQ的情况 打开https://studygolang.com/ 下载相应的系统安装包. (二) 安装与环境配置 linux: 解压到指定目录: sudo tar zxvf [安装包的下载 ...

  6. Vue基础之数据绑定

    我们学习一门新语言或者框架时,第一件事是什么呢,那必然是向世界say Hello. 创建一个Vue应用 话不多说,先上代码,让我们感受一下Vue的核心功能 <!DOCTYPE html> ...

  7. 渗透测试学习 四、 HTML基础

    HTML是一种解释型语言,解释给浏览器解析执行显示给用户浏览,是一种静态,无交互的 超文本标记语言(Hyper Text Markup Language),标准通用标记语言下的一个应用.HTML 不是 ...

  8. 如何让input框显示在一行?

    案例: <input type="float:left" value="aaaa"> <input type="float:left ...

  9. SpringCloud基于消息总线的配置中心

    @https://www.cnblogs.com/ityouknow/p/6931958.html Spring Cloud Bus Spring cloud bus通过轻量消息代理连接各个分布的节点 ...

  10. 自己用的vim插件

    一.Plugin 'VundleVim/Vundle.vim'. 二.Plugin 'Valloric/YouCompleteMe' let g:ycm_server_python_interpret ...