Mybatis常见疑问
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常见疑问的更多相关文章
- Mybatis常见配置错误总结
Mybatis常见配置错误总结 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionF ...
- 【面经】MyBatis常见面试问题
1.什么是 MyBatis? 答:MyBatis 是一个可以自定义 SQL.存储过程和高级映射的持久层框架. 2.讲下 MyBatis 的缓存 答:MyBatis 的缓存分为一级缓存和二级缓存,一级缓 ...
- mybatis常见易出错
在学习mybatis的过程中,发现了很多错误,这里记录一下,以供后来使用 1,config.xml文件中配置项的顺序: org.apache.ibatis.exceptions.Persistence ...
- spring + myBatis 常见错误:注解事务不回滚
最近项目在用springMVC+spring+myBatis框架,在配置事务的时候发现一个事务不能回滚的问题. 刚开始配置如下:springMVC.xml配置内容: spring.xml配置内容 从上 ...
- spring + myBatis 常见错误:@Autowired注解失败
今天配置spring+myBatis的时候,使用注解@Autowired把持久层dao注入service层的时候总是报错. 查了好久才发现,居然是配置文件路径写错了.basepackge的路径一定要正 ...
- mybatis常见错误总结
1. 现象:mybatis xml文件中查询的返回类型写成list或java.util.List时,执行sql时报 java.lang.UnsupportedOperationException错误. ...
- springboot mybatis常见异常及处理方法
1.in导致的异常 Data truncation: Truncated incorrect DOUBLE value: 异常过程: mapper接口如下: public int updateBatc ...
- RESTful设计中的常见疑问
最近写了几个有关RESTful的API相关内容,也谈谈对常见问题的自己的理解. 什么是RESTful 详情可以看http://www.ruanyifeng.com/blog/2011/09/restf ...
- mybaits(十)mybatis常见面试
面试题总结 1.MyBatis 解决了什么问题? 或:为什么要用 MyBatis? 或:MyBatis 的核心特性? 1)资源管理(底层对象封装和支持数据源) 2)结果集自动映射 3)SQL 与代 ...
随机推荐
- vue-cli的使用(模板自定义、本地配置,eslint的配置)
vue-cli(脚手架工具:帮助开发者完成基本的代码编写). 功能: 目录结构 本地调试 代码部署 热加载 单元测试 使用模板: vue init <template-name> < ...
- win10下安装mongodb
环境 :win10 mongodb-win32-x86_64-v3.4-latest.zip 1.下载地址:https://www.mongodb.com/download-center/commu ...
- 【Linux】awk指令
介绍: awk是一种可以处理数据,产生格式化报表的语言.其工作方式是读取数据文件,将每一行数据视为一条记录,没笔记录按分隔符(默认空格)分割成若干字段,输出各字段的值. 实例: [jboss@vm-k ...
- 代码中设置color的selector
//应该用getColorStateList这种方式 xml中设置时直接color引用就可以了 textView.setTextColor(getResources().getColorStateLi ...
- cocos2dx翻牌效果示例
实现类似翻扑克牌的效果 代码如下: OrbitCamera* rotate1; OrbitCamera* rotate2; if(towardRight){//向右翻转 rotate1=OrbitCa ...
- latex中使用定理、证明、缩进
1.定理和证明 \documentclass[a4paper,UTF8]{article} \usepackage{ctex} \usepackage{amsthm,amsmath,amsfonts, ...
- 2018.11.25 AMC-ICPC 亚洲区域赛(焦作站)吊银
11月23日 大清早,跟着wyb的脚步,早起跑过去听方伟的编译原理,然鹅一点都没听进去,在焦作胡辣汤群里疯狂灌水... 听说焦作那边冷得不行,前一天看天气预报说那边已经是2℃了,都快零下了,然鹅学校里 ...
- Mybatis集成Oracle
首先需要导入Oracle的驱动,这部分会有一个天坑 Maven无法直接将我们所需的Oracle驱动加入项目中,手动加入依赖也是无效(原因还在分析),而且驱动无效如果不注意的话是看不出来的,他不会在编译 ...
- Map的嵌套 练习
Map的嵌套 练习 利用迭代和增强for循环的两种方式实现如下效果 package cn.ccc; import java.util.HashMap;import java.util.Iterat ...
- getRealPath()和getContextPath()的区别
转载自:http://sucre.iteye.com/blog/319178 在程序中常常要获取文件的路径,有的时候需要用到相对路径而有的时候就要用到绝对路径,一提到绝对路径大家一定想到了getRea ...