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 与代 ...
随机推荐
- Day03_Python知识总结
1.元组: 元组其实跟列表差不多,也是存一组数,但它一旦创建便不能修改,所以又叫只读列表. names = ("alex","jack","eric ...
- golang struct
ex1 /* https://golangbot.com/structs/ struct 结构 结构就是一组字段. */ package main import "fmt" // ...
- python初识模块
sys import sys print(sys.argv) #输出 $ python test.py helo world ['test.py', 'helo', 'world'] # ...
- 用Sqoop进行Hive和MySQL之间的数据互导
Hive导数据入MySQL 创建mysql表 use anticheat; create table anticheat_blacklist( userid varchar(30) primary k ...
- 前端axios下载excel(二进制)
需求:通过后端接口下载excel文件,后端没有文件地址,返回二进制流文件 实现:axios(ajax类似) 主要代码: axios:设置返回数据格式为blob或者arraybuffer 如: var ...
- sublime快捷键使用
sublime常用快捷键 自己觉得比较实用的sublime快捷键有: Ctrl+/..................注释 Ctrl+滚动..................字体变大.缩小 Ctrl+ ...
- CSS学习笔记_day7
目录 1.径向渐变 2. 线性渐变 3. 背景图片裁剪 4. 背景图片大小 5. 边框图片 6. 边框圆角 7. 边框阴影 8.位移 9. 倾斜 10. 旋转 11. 缩放 12. 文本换行 13. ...
- BZOJ-3105: 新Nim游戏 (nim博弈&线性基)
pro: 传统的Nim游戏是这样的:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量可以不同).两个游戏者轮流操作,每次可以选一个火柴堆拿走若干根火柴.可以只拿一根,也可以拿走整堆火柴,但不能同时从 ...
- Django-api认证
验证过程:每一个中控机有一个key,然后获取到当前时间戳.把key和当前时间戳这两个值进行一次加密,加密之后得到加密的戳,把加密的戳和当前获取的时间戳用管道符分割开生成一个大的字符串(加密戳|时间戳) ...
- linux中一些常用的目录简要说明
1.目录结构 /bin:binary的缩写,一些常用的命令如:ls.qwd.cp.cd等命令保存在这个文件内. /boot:启动linux时需要使用到的一些核心文件,以及一些镜像等,删除后系统将无法开 ...