MyBatis introduce programming and problem-solving jdbc

Mybatis Introduction

Mybatis when a good persistence framework. It jdbc process of operation of the database encapsulation, is that developers need to focus on sql itself, without the need to take the process registration drive energy costs, create a connection, create a statement, manually set the parameters, the result set retrieval jdbc complex procedure code.

Xml MyBatis statement by various annotations manner or arranged to be performed together, and the final map generation sql statement executed by a java object and the sql statement, the last frame has mybatis execute sql and mapping the result to a Java object and returns.

Mybatis solve the problem jdbc programming

1. Create a database connection, the release of frequent system resources are wasted thus affecting the performance of the system, if you use a database connection pool to resolve this problem. MyBatis configuration data connection pool in the heart of the configuration file, use the connection pool management database connections.

2.Sql statement written in the code caused the code is not easy to maintain, practical application sql change may be larger, sql changes need to change the java code. Mybatis Sql statements in the configuration file Mapper disposed separated from the java code.

3. sql statement to pass parameters to the trouble, should not necessarily sql statement where conditions may be more or less a placeholder and required parameters one by one. In Mybatis automatically mapped to the formation java sql statement, the input parameters defined by the statement parameterType type.

4. The analytical result set trouble, sql parsing code change results in a change, and the need to facilitate before parsing, if the database record can mad to resolve objects pojo convenient. In Mybatis automatically mapped to the execution result sql java object, output type resultType defined in statement by results.

Guess you like

Origin www.cnblogs.com/jumpkin1122/p/11628295.html