Mybatis   发布时间:2019-10-08  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 &&
 (.connection.versionMeetsMinimum(5,2) && .connection.getUsecursorFetch() && isBinaryEncoded && callingStatement != 
                 && callingStatement.getFetchSize() != 0 && callingStatement.getResultSetType() ==ResultSet.TYPE_FORWARD_ONLY) {
             ServerPreparedStatement prepStmt =m.mysql.jdbc.ServerPreparedStatement) callingStatement;
 
             Boolean usingcursor =  
             
             cursor and set this flag if they can,otherwise they punt and go BACk to mysql_store_results()
                           
              (.connection.versionMeetsMinimum(5,5{
                 usingcursor = (.serverStatus & SERVER_STATUS_cursOR_EXISTS) != 0  
             cursor) {
                 RowData rows =  RowDatacursor();
 
                 ResultSetImpl rs =);
 
                 cursor) {
 s.setFetchSize(callingStatement.getFetchSize());
  
                           }

2.Mybatis开启Mapper级别的缓存时,注意Bean需要继承serializer接口

大佬总结

以上是大佬教程为你收集整理的Mybatis常见疑问全部内容,希望文章能够帮你解决Mybatis常见疑问所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: