mybatis总结及理解分享

mybatis的流程:

String resource = "org/mybatis/example/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

mybatis提供了resources(工具类)方法,可以获取*.xml配置文件的内容( classpath 或其他位置加载资源文件)。
sqlsessionfactorybuilder 创建sqlsessionfactory链接。

SqlSession session = sqlSessionFactory.openSession();
try {
  Blog blog = (Blog) session.selectOne("org.mybatis.example.BlogMapper.selectBlog", 101);
} finally {
  session.close();
}

获取数据库链接seesion,通过sqlSessionFactory来打开。sqlSessionFactory在加载配置时,已经加载了XML 配置文件中配置的 MyBatis 系统的核心功能(获取数据库连接实例的数据源(DataSource)和决定事务作用域和控制方式的事务管理器(TransactionManager))。
mybatis配置包括:
configuration:
1、属性(properties)
2、设置(settings)
3、类型别名(typealiases)
4、类型处理器(typehandlers)
5、插件(plugins)
6、环境配置(enviroments)
7、数据库厂商标识(databaseidprovider)
8、映射器(mappers)

mapperstatement->sqlsource->boundSql
mappers的基本操作符:
cache、cache-ref、
select语句属性:id、parametertype、parametermap、resultmap、resultType、flushcache、usecache、timeout、fetchsize、statementType、resultSetType、databaseId、resultOrdered、resultsets
insert、update、delete语句属性:useGeneratedKeys、 keyProperty、keycolum

动态sql语句:
if、choose、when、otherwise、trim、where、set、foreash

注入方式:
xml、注解、配置类、框架注入

mybatis缓存使用方法:

~~~~未完待续,等有时间,仔细研究一下mybatis。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容