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. 查询MySQL数据库中表结构的几种方法

    什么是表结构?表结构就是定义数据表文件名,确定数据表包含哪些字段,各字段的字段名.字段类型.及宽度,并将这些数据输入到计算机当中. 查询方法:以表‘employees’为例子 1.describe(d ...

  2. C# Winform 国际化

    1.在Form的language属性选择中文,来制作中文界面 保存后,设置界面标题会变成如下所示,并且会出现一个zh-CN的资源文件,打开resx文件可看到相应内容 2.将Form的language属 ...

  3. ansible 下lineinfile详细使用

    ansible 下lineinfile详细使用 时间 2016-12-13 18:02:31  51CTO推荐博文 原文  http://zouqingyun.blog.51cto.com/78224 ...

  4. leftBarButtonItem 的颜色

    修改系统:leftBarButtonItem, rightBarButtonItem 的颜色 在你需要修改的页面,ViewDidload()方法里面贴上下面代码 self.navigationCont ...

  5. 使用spark访问hive错误记录

    在spark集群中执行./spark-shell时报以下错误: 18/07/23 10:02:39 WARN DataNucleus.Connection: BoneCP specified but ...

  6. QT | 一些学习心得

    1. 如何使控件随着窗口大小变化而自动填充? 选中控件中最外层的那个控件,如centralWidget(不要去选中内部的小控件,这样能够保证内部的相对位置) 然后对centralWidget选择布局方 ...

  7. oracle中left join,right join,inner join的坑

    本文主要是记录一下实际使用oracle中join查询遇到的坑 1.用到两张表,学生表和学年分数表,先建立 2.普通连接查询 INNER JOIN,查询每个学年有成绩的学生以及分数情况 LFET JOI ...

  8. EOS wallet API 报HTTP 400错误

    服务器:192.168.8.144 按照官方的docker方式运行的,因为keosd(钱包)开出来的API只容许本地访问,即: url --request POST --header 'Host: 0 ...

  9. Sql Server 2005/2008数据库被标记为“可疑”/“质疑”的问题

    日常对Sql Server 2005关系数据库进行操作时,有时对数据库(如:Sharepoint网站配置数据库名Sharepoint_Config)进行些不正常操作如数据库在读写时而无故停止数据库,从 ...

  10. AOP统一处理Web请求日志

    <!--aop--> <dependency> <groupId>org.springframework.boot</groupId> <arti ...