MyBatis自行学习

本文深入探讨了MyBatis框架的核心特性,包括自定义SQL、存储过程、高级映射等功能,详细介绍了MyBatis的装载过程,从引入包到创建SqlSessionFactory实例,再到通过SqlSession进行数据库操作的方法。同时,文章还解析了mybatis.xml配置参数,以及mapper.xml配置文件的元素使用,如动态SQL标签和SQL语句构建器的运用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1、What is MyBatis

keyword 摘自官网:

1、persistence framework
2、costum SQL
3、stored procedures
4、advanced mapping
----
5、eliminate almost JDBC code
6、manual setting param and retrival of results
----
7、use xml or annotation and map primitives
8、map interface and JOPO to DB

2、官网学习

2.1、装载过程
1、引入package
2、装配congfiguration
3、SqlSessionFactoryBuilder.build(configuration),装载SqlSessionFactory实例
4、sqlSessionFactory实例获取sqlSession
4.1、可以sqlSession.SelectOne(namespace,param)操作db
4.2、sqlSession 获取SqlSession.getMapper(),获取mapper 并操作实例
说明:mapper sql的调用形式:xml ,annotation
2.2 Scope
Bean 名称作用域作用
SQLSessionFactoryBuildermethod 最佳只为创建sqlsessionFactory存在
SQLSessionFactoryApplication 最佳单例模式或者静态单例模式
SqlSessionrequest、method最佳finally中关闭;确保每个请求中只有一个sqlSession;SqlSessionFactory.openSQLSession()获取session 对象
custom mapperrequest、method最佳和SqlSession的作用域相同;获取:session.getMapper(namespace)
2.3 mybatis.xml config param

各个属性信息的说明见官网

http://www.mybatis.org/mybatis-3/zh/configuration.html#

configuration

1、properties
2、settings
3、typeAliases
4、typeHandlers :自定义TypeHandle extends more TypeHanders
5、plugins:Executor ,ParameterHandler ,ResultSetHandler ,StatementHandler 谨慎修改
6、environments
7、mappers
2.4 mapper.xml configuration

元素说明:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html

1、select
2、insert,update,delete
3、参数
4、resultMap
4.1、嵌套查询
4.2、嵌套结果
4.3、关联多结果集
4.4、
5、集合 collection
6、缓存
2.5、动态sql标签
1、where
2、choose
3、if
4、set
5、trim
6、forEach
7、script
2.6、SQL语句构建器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值