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. 小伙 zwfw-new.hunan.gov.cn.iname.damddos.com [222.240.80.52]

    由于这个应用出问题非常影响用户体验:于是立马让运维保留现场 dump 线程和内存同时重启应用,还好重启之后恢复正常.于是开始着手排查问题.

  2. Kylin引入Spark引擎

    1 引入Spark引擎 Kylin v2开始引入了Spark引擎,可以在构建Cube步骤中替换MapReduce. 关于配置spark引擎的文档,下面给出官方链接以便查阅:http://kylin.a ...

  3. 上传文件代码报错,java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory

    2018-09-11 11:11:08.235 ERROR 14352 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : ...

  4. MySQL查询操作——2

    -----------查询操作--------------------------- 查询表中的所有字段SELECT * FROM employees; 查询常量值SELECT 100;SELECT ...

  5. LibreOffice字体问题解决;从window复制到Ubuntu

    拷贝或下载windows系统的Fonts字体集到对应的linux系统下;以ubuntu16.04系统为例. 1.进入windows系统,到C:WindowsFonts目录,复制拷贝自己需要的字体(也可 ...

  6. Oracle深入学习

    一.甲骨文公司介绍 甲骨文公司,是全球最大的企业级软件公司,总部位于美国加利福尼亚州的红木滩.1989年正式进入中国市场. 2013年,甲骨文已超越 IBM ,成为继 Microsoft 后全球第二大 ...

  7. linux中一些常用的目录简要说明

    1.目录结构 /bin:binary的缩写,一些常用的命令如:ls.qwd.cp.cd等命令保存在这个文件内. /boot:启动linux时需要使用到的一些核心文件,以及一些镜像等,删除后系统将无法开 ...

  8. C++——智能指针unique_ptr的实现

    起初,我最直观的设计想法,直接设计一个类:包含全部要素(对象,指针计数).然后提供出去. class CPoint { public: CPoint(, ) : x(xVal), y(yVal) {} ...

  9. 现在企业开发时,Java所用到的主流框架有哪些?

    虽然Java一直被唱衰,但是直到现在Java软件开发也坚持霸主地位不动摇.毫无疑问,Java是目前最热门的编程语言之一.随着Java面向对象语言的流行以及多层架构应用的出现,使得应用程序的可复用性得到 ...

  10. 创建一个dynamics 365 CRM online plugin (十一) - Handling Configuration data

    Config data 可以在registering step 的时候来配置 配置好的config data 可以使用 constructor 来获取 Secure Config 和 UnSecure ...