1.在连接数据库时候,mysql是否支持fetchsize分页获取?
满足以下几个条件,可以使用fetchsize,根据游标获得记录
①MySQL 从5.0.2开始支持分页获得.
②同时需要在jdbc连接参数上配置 jdbc:mysql://localhost:3306/test?useCursorFetch=true
③设置FetchSize,在mybatis的 具体查询语句中配置 。 ④isBinaryEncoded 如果是使用PreparedStatement则这个值为true ⑤如果使用PreparedStatement,则会生成JDBC42ServerPreparedStatement对象,在访问数据库时,会自动设置resultsetType=ResultSet.TYPE_FORWARD_ONLY 疑问:mybatis什么情况下会将statement的类型初始化为PreParedStatement? 在sql配置文件中有一个参数,statementType 可以自己设置。要不即使参数使用${}。也还是会使用PreparedStatement。默认是PreparedStatement 在MySQL的JDBC源码中:MysqlIO中 //版本>=5.0.2 && 连接上配置useCurSorFetch=true &&isBinaryEncoded =true && (.connection.versionMeetsMinimum(5,2) && .connection.getUseCursorFetch() && isBinaryEncoded && callingStatement != && callingStatement.getFetchSize() != 0 && callingStatement.getResultSetType() == ServerPreparedStatement prepStmt = usingCursor = (.connection.versionMeetsMinimum(5,5 usingCursor = (.serverStatus & SERVER_STATUS_CURSOR_EXISTS) != 0 RowData rows = RowDataCursor( ResultSetImpl rs = } 2.Mybatis开启Mapper级别的缓存时,注意Bean需要继承Serializer接口
④isBinaryEncoded 如果是使用PreparedStatement则这个值为true
⑤如果使用PreparedStatement,则会生成JDBC42ServerPreparedStatement对象,在访问数据库时,会自动设置resultsetType=ResultSet.TYPE_FORWARD_ONLY
疑问:mybatis什么情况下会将statement的类型初始化为PreParedStatement?
在sql配置文件中有一个参数,statementType 可以自己设置。要不即使参数使用${}。也还是会使用PreparedStatement。默认是PreparedStatement
在MySQL的JDBC源码中:MysqlIO中 //版本>=5.0.2 && 连接上配置useCurSorFetch=true &&isBinaryEncoded =true && (.connection.versionMeetsMinimum(5,2) && .connection.getUseCursorFetch() && isBinaryEncoded && callingStatement != && callingStatement.getFetchSize() != 0 && callingStatement.getResultSetType() == ServerPreparedStatement prepStmt = usingCursor = (.connection.versionMeetsMinimum(5,5 usingCursor = (.serverStatus & SERVER_STATUS_CURSOR_EXISTS) != 0 RowData rows = RowDataCursor( ResultSetImpl rs = } 2.Mybatis开启Mapper级别的缓存时,注意Bean需要继承Serializer接口
在MySQL的JDBC源码中:MysqlIO中
(.connection.versionMeetsMinimum(5,2) && .connection.getUseCursorFetch() && isBinaryEncoded && callingStatement != && callingStatement.getFetchSize() != 0 && callingStatement.getResultSetType() == ServerPreparedStatement prepStmt = usingCursor = (.connection.versionMeetsMinimum(5,5 usingCursor = (.serverStatus & SERVER_STATUS_CURSOR_EXISTS) != 0 RowData rows = RowDataCursor( ResultSetImpl rs = }
2.Mybatis开启Mapper级别的缓存时,注意Bean需要继承Serializer接口