目录
1,目录
2,介绍
3,快速入门
4,配置XML
5,xml文件映射
6,动态sql
7,java api
8,Statement Builders
9,日志
1,介绍
1.1 介绍
1.1.1 MyBatis是什么
MyBatis 是第一类持久化框架,支持定制sql,存储过程和高等映射。MyBatis几乎淘汰了所有的JDBC编码和手工设置参数以及结果的检索。MyBatis能够使用简单的xml或者注解配置和原始的map,Map接口和java POJOs到数据库记录
1.1.2 你的帮助能使文档变得更好
如果你发现文档有任何的缺少或者有任何缺少,你可也可以自己写文档。
Sources of this manual are available in xdoc format at project's Git . Check them out, update them
and send your patch to the tracker .
You’re the best author of this documentation, people like you have to read it!
1.1.3 翻译
你想阅读你们自己母语版的关于MyBatis的文档吗?可以发行你们母语版的文档。
2,快速入门
2.1 快速入门
每一个MyBatis应用中心都会围绕一个SqlSessionFactory实例。一个SqlSessionFactory实例的获得可通过用SqlSessionFactoryBuilder.SqlSessionFactoryBuilder通过XMl配置文件和自定义编写的实例创建一个SqlSessionFactory。
2.1.1 通过XML创建SqlSessionFactory
通过一个xml文件的配置创建SqlSessionFactory是非常简单的。推荐你使用一个classpath resource去配置,另外你需要使用流,流中包含一个文件路径或者URL。MyBatis包含一个工具类,这个工具类中有一个方法可以含有类路径的资源:
String resource = "org/mybatis/example/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
这个XML配置文件含有对MyBatis系统的核心设置,包含一个获得数据连接实例的数据源,同时也含有一个如何处理和控制的事物管理器。关于XML配置文件的细节我们会在文档后面涉及,这个给出一个简单的示例:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment >
关于每个字段描述,请见官方文档29页
4.1.3 sql
p29/33明天计划40-43
4.1.4 Parameters
4.1.5 Result Maps
4.1.6 Auto-mapping
4.1.7 cache
相关文章: