- Notifications
You must be signed in to change notification settings - Fork12
The simple mybatis.(手写简易版 mybatis)
License
NotificationsYou must be signed in to change notification settings
houbb/mybatis
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
mybatis 是一款简化版的 mybatis 实现。
学习 mybatis 的原理
便于拓展自己的数据库工具
jdk 1.7+
maven 3.x+
<dependency> <groupId>com.github.houbb</groupId> <artifactId>mybatis</artifactId> <version>0.1.0</version></dependency>
- sql 建表
在 test 数据库执行下面的建表语句。
-- auto-generated definitionuse test;createtableuser( idint auto_incrementprimary key comment'唯一主键', namevarchar(100)not null comment'姓名', passwordvarchar(100)not null comment'密码', create_timechar(17) comment'创建时间') CHARACTERSET utf8 COLLATE utf8_general_ci;-- initinsert into user (name, password) value ('luna','123456');
- 配置文件
<?xml version="1.0" encoding="UTF-8"?><configuration> <dataSource> <propertyname="driver"value="com.mysql.jdbc.Driver"/> <propertyname="url"value="jdbc:mysql://localhost:3306/test"/> <propertyname="username"value="root"/> <propertyname="password"value="123456"/> </dataSource> <mappers> <mapperresource="mapper/UserMapper.xml"/> </mappers> <plugins> <plugininterceptor="com.github.houbb.mybatis.plugin.SimpleLogInterceptor"/> </plugins> <typeHandlers> <typeHandlerjavaType="java.util.Date"handler="com.github.houbb.mybatis.typehandler.DateTypeHandler"/> </typeHandlers></configuration>
备注:默认使用的是 mysql 5.7,如果为 8.0+,需要自行引入 jar。
publicstaticvoidmain(String[]args) {Configconfig =newXmlConfig("mybatis-config-5-7.xml");SqlSessionsqlSession =newDefaultSessionFactory(config).openSession();UserMapperuserMapper =sqlSession.getMapper(UserMapper.class);Useruser =userMapper.selectById(1L);System.out.println(user);}
- 输出
User{id=1, name='ryo', password='123456', createTime=Wed Jul 01 22:03:01 CST 2020}
手写 mybatis 系列(二)mybatis interceptor 插件机制详解
从零开始手写 mybatis (三)jdbc pool 从零实现数据库连接池
日志组合
连接池管理
TX 管理
- [ ] 数据库厂商标识(databaseIdProvider)
api 方法配置全接口,便于直接配置使用。
添加 MBG
添加 spring 整合实现
添加 spring-boot 整合实现
自增强-类似 mybatis-plus 模块。让组件使用起来更加方便
保持核心功能的简单,保证使用的强大便捷。