mybatis interview summary (1) - Introduction mybatis

If the interviewer directly Let me introduce mybatis, I will introduce the following aspects to this framework:
What 1.mybatis that?
mybatis is an excellent persistence framework, he is encapsulated to process jdbc database operations, allowing developers the only concern sql itself, not to be concerned such as registration drive, load the link, get complicated process statement, the result set and so on.
mybatis through xml or annotation manner, various configurations sql statement to execute them, and a final map generation sql statement by statement Java objects and sql statement, sql statement executed by the mybatis last frame, and map the result to the Java objects return.
2. Works
mybatis create a configuration file sqlsessionFactory, sqlsessionFactory comes from two aspects according to the configuration files, configuration files: one is xml, one is in Java annotations, get sqlSession. SQLSession contains all the methods executed sql statement, sql statement SQLSession can run directly mapped to the completion of additions and deletions to change search the data and submit things work, close SQLSession used up.
3. Working process
mapper interfaces:

Full class name of the interface is xml file namespace value.

  • The interface method name is xml file mapperstatement the id value.
  • Method parameter is passed to the interface parameter of sql
  • mapper interfaces are not implemented class, when you call a method, the full name of the class interface locate a configuration file, the name of the interface method of locating a mapperStatment this configuration file, so that the method name mapper is not overloaded, because mapperStatment preservation and looking strategy.
  • mapper interface is the working principle, mybatis use jdk dynamic proxy way mapper interface to create a proxy object method interface proxy object intercepts in favor of the implementation of sql statement mapperStatment represented, then the result of the implementation of the package will be returned.

4.mybatis problem

  • 1. Use the links database connection pool management, to avoid the frequent create a close link, waste of resources, performance problems impact.
  • 2. Management xml sql statement, sql statement to make Java code and separate, making the code easier to maintain.
  • 3. solve the problem of uncertain parameters sql statement. xml sql statement can be decided by the condition where condition parameters. mybatis map Java objects to sql statement, defined by an input parameter of type parameterType statement.
  • 4.mybatis result set automatically packaged as Java objects, resultType defined by the type of output statement. Sql avoid problems caused by changes in the result set processing trouble.
Published 77 original articles · won praise 39 · views 80000 +

Guess you like

Origin blog.csdn.net/qq_33824312/article/details/73771008