MyBatis Loading Study

After using mybatis for so long, let's see how it works today.

When configuring spring mybatis, we will have a spring-mybatis.xml file. which defines such a bean

fly.fky.restapi.dao  //这是一个包名, dao 的声明都在这里

When we start the service, the MapperScannerConfigurer class will parse the package we configured

Register in the global beanFactory

This configures some of our sql statement file paths

After these files are parsed, <insert>, <delete>, <update>, <select> will be parsed into MappedStatement objects.

A MappedStatement corresponds to an <insert>, <delete>, <update>, <select> in the mapper file, and the corresponding MappedStatement is obtained each time a MyBatis operation is performed.

Call selectOne through the SqlSessionTemplate class proxy 

Then enter DefaultSqlSession to find the MappedStatement parsed and stored above

This is where the sql statement is actually executed.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325471720&siteId=291194637