Comparison of JdbcTemplate and mybatis

benefit:

  1. jdbcTemplate spring package is jdbc operation of the database, so that developers can write directly in the java file sql without xml configuration file.

  2. Simple fast efficiency

Disadvantages:

  1. Create a connection using the immediate release when not in use. Frequent connection opening and closing a waste of resources, affect the performance of the database.

      Solution: use the database connection pool, connection management database.

  2. The sql hard-coded into java code, if sql modify, recompile the java code, is not conducive to the maintenance of the system.

      Solution: sql statement defined in the xml configuration files, static resources

  3. locator and parameters are set in the statement, hard-coded into java code,

      When the result traversal result set, you need to get hard-coded map data, it is not conducive to maintenance.

 


 

So mybatis architecture solves part of the problem. For team development, rapid development of better support.

By way mybatis map provided by semi-automatic generation sql, most still require programmers to write sql.

core:

  Input mapping: the input parameters may be automatically inputted to the statement by mapping ongl expression,

  Output mapping: query result set to become flexible mapping of java object

mybatis structure

Then say about the general workflow of myabtis

1, mybatis configuration (two xml file)

    SqlMapConfig.xml, mybatis this file as a global configuration file to configure the operating environment mybatis information (data source, things, mapper mapping file).

    mapper.xml sql file that is mapped files, configure the operation of the database sql statement. This file needs to be loaded in SqlMapConfig.xml in.

2, i.e. the configuration information configured SqlSessionFactory session factory environment by mybatis

3. Create a session by a session that is sqlSession plant, operation of the database needs to be by sqlSession.

4, mybatis underlying actuator Executor customized database interface operation, there are two interfaces implemented Executor, it is a basic actuator, an actuator is a buffer.

5, Mapped Statement mybatis is a bottom package object that wraps mybatis sql configuration information and mapping information. mapper.xml a file corresponding to a sql Mapped Statement objects, sql Mapped statement that is the id of the id.

. 6, Mapped Statement performed on input parameters sql defined, including the HashMap, basic types, pojo, Executor by mapping java object Mapped Statement before performing sql inputted to sql input parameter mapping is jdbc programming set parameters preparedStatement.

. 7, Mapped Statement sql execution of the output is defined, comprising the HashMap, basic types, pojo, Executor by mapping Mapped Statement after performing sql java object outputs the result to the output result of the mapping process is equivalent jdbc programming parsing results process.

 


mybatis advantages:

  1, encapsulation of high abstraction mybatis the jdbc. To achieve the spring jdbc details many such mybatis more encapsulated object map.

  2, support for annotations face interface development, high efficiency, every minute to solve a sql.

  3, for complex SQL, springJDBC trouble writing, mybatis humane point.

  4, mybatis height of the package, the programmer can focus on a business layer, high development efficiency. So choose mybatis development company and more.

 

Guess you like

Origin www.cnblogs.com/scmath/p/11297006.html