1.mybatis development process
1.1 add MyBatis dependent jar
1.2 to develop a mapping entity class
1.3 Develop a SQL mapping file
Created under src / main / resource table corresponding to the current mapping file for SQL statements SQL statements
1.4 Development MyBatis core profile
Creating MyBatis-config.xml in src / main / resources as the core profile
1.5 Development MyBatis basic call flow
2.mybatis works
to sum up:
1. mybatis workflow
- Save the frame configuration file to the configuration objects
- The configuration as an attribute to our current DefaultSqlSessionFactory instance of the object (DefaultSqlSessionFactory is SqlSessionFactory implementation class), we wanted to this database configuration information is loaded into sqlSessionFactory, create a sqlSessionFactory factory.
- After creating an object will generate sqlSession good sqlSessionFactory factory.
4. Provides properties in objects created SqlSession
1) Configuration objects
2) dirty: true sql statement after the implementation of the transaction can be submitted
false sql statement is executed to send an error transaction rollback
3) Executor object performs:
Create a Statement object in the creation process of assigning content to rely on MapperStatement objects with placeholders to bind sql
5. SqlSession.commit (): The decision to commit and rollback case dirty properties
6. SqlSession.close();
2. Mybatis如何将sql语句id与sql语句进行定位
在这个MapperAnnotationBuilder中会判断是否有定义命名空间,如果没有或者定义出错就会报出错误 private void loadXmlResource() {
|
3. mybatis如何将数据绑定到sql命令
public int doUpdate(MappedStatement ms, Object parameter) throws SQLException {// parameter是传递进来的对象参数 var6 = handler.update(stmt); |
4. mybatis如何输送sql
在这个XMLConfigBuilder中读取配置的标签的内容 public Configuration parse() {
|
5. SqlSession中的dirty属性赋值的目的
this.dirty = true;//赋值的目的:sqlSession的一个属性 ErrorContext.instance().resource(ms.getResource()).activity("executing an update").object(ms.getId());//找到对应的mapper文件并且传递个ID匹配对应的sql语句 |
今天就先简单介绍下Mybatis的开发流程和与原理的个人总结,下一篇介绍的是对mybatis的配置文件标签的使用。
有问题邮箱:[email protected]