# mybatis **Repository Path**: jinxianyang/mybatis ## Basic Information - **Project Name**: mybatis - **Description**: MyBatis 的前身就是 iBatis - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: learn - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 143 - **Created**: 2025-08-17 - **Last Updated**: 2025-08-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README MyBatis SQL Mapper Framework for Java ===================================== [![build](https://github.com/mybatis/mybatis-3/actions/workflows/ci.yaml/badge.svg)](https://github.com/mybatis/mybatis-3/actions?query=workflow%3A%22Java+CI%22) [![Coverage Status](https://coveralls.io/repos/mybatis/mybatis-3/badge.svg?branch=master&service=github)](https://coveralls.io/github/mybatis/mybatis-3?branch=master) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mybatis_mybatis-3&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=mybatis_mybatis-3) [![Maven central](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.mybatis/mybatis.svg)](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis/) [![License](https://img.shields.io/:license-apache-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [![Stack Overflow](https://img.shields.io/:stack%20overflow-mybatis-brightgreen.svg)](https://stackoverflow.com/questions/tagged/mybatis) [![Project Stats](https://www.openhub.net/p/mybatis/widgets/project_thin_badge.gif)](https://www.openhub.net/p/mybatis) ![mybatis](https://mybatis.org/images/mybatis-logo.png) The MyBatis SQL mapper framework makes it easier to use a relational database with object-oriented applications. MyBatis couples objects with stored procedures or SQL statements using an XML descriptor or annotations. Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping tools. Essentials ---------- * [See the docs](https://mybatis.org/mybatis-3) * [Download Latest](https://github.com/mybatis/mybatis-3/releases) * [Download Snapshot](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis/) Contributions ------------- See [here](CONTRIBUTING.md) Tests ----- Mybatis-3 code runs more expressive testing depending on jdk usage and platform. By default, we set ```TestcontainersTests,RequireIllegalAccess``` which will exclude a subset of tests with @Tag('TestcontainersTests') and @Tag('RequireIllegalAccess'). When we run on ci platform, we further make adjustments as needed. See [here](.github/workflows/ci.yaml) for details. As of 12/28/2024, using combined system + jdk will result in given number of tests ran. This will change as tests are added or removed over time. without adjusting settings (ie use as is, platform does not matter) - any OS + jdk 17 = 1899 tests - any OS + jdk 21 = 1899 tests - any OS + jdk 23 = 1899 tests - any OS + jdk 24 = 1899 tests - any OS + jdk 25 = 1899 tests our adjustments for GH actions where platform does matter - windows + jdk 17 = 1899 tests - windows + jdk 21 = 1899 tests - windows + jdk 23 = 1899 tests - windows + jdk 24 = 1899 tests - windows + jdk 25 = 1899 tests - linux + jdk 17 = 1934 tests - linux + jdk 21 = 1934 tests - linux + jdk 23 = 1934 tests - linux + jdk 24 = 1934 tests - linux + jdk 25 = 1934 tests - mac + jdk 17 = 1899 tests - mac + jdk 21 = 1899 tests - mac + jdk 23 = 1899 tests - mac + jdk 24 = 1899 tests - mac + jdk 25 = 1899 tests 二级缓存需要提交后在存入缓存,且二级缓存的可以多线程访问 根据sqlSessionFactory对象创建sqlSession sqlSessionFactory.openSession() 获取mapper接口对象 sqlSession.getMapper(UserMapper.class) 根据statement查找到对应的根据configuration获取对应的mappedStatement 根据mappedStatement调用对应的执行器进行查询操作 首先执行cachingExecutor进行二级缓存相关操作 然后调用对应的executor进行查询操作 doQuery方法 1. SimpleExecutor 简单执行器,每次查询都会预编译操作 2. BathExecutor 批量执行器,对查询或更新操作进行批量执行 3. ReuseExecutor 重用执行器,对查询或更新操作进行重用,避免多次预编译操作 获取对应的handler进行执行对应的jdbc操作 1. SimpleStatementHandler 针对静态sql语句进行操作 2. CallableStatementHandler 针对存储过程进行操作 3. PreStatementHandler 针对动态sql语句进行操作(默认) 4. RoutingStatementHandler 根据mappedStatement类型进行选择对应的StatementHandler sqlSession.selectList("com.example.mapper.UserMapper.selectAll") sqlSession.commit() sqlSession.close()