Home > Java > Java Tutorial > body text

The difference between ResultMap and ResultType

angryTom
Release: 2020-02-13 13:44:45
Original
9234 people have browsed it

The difference between ResultMap and ResultType

The difference between ResultMap and ResultType

When using mybatis for database connection operations, there are usually two ways to process the results returned by SQL statements. One One is resultType; the other is resultMap:

1, resultType: When using resultType to do the SQL statement return result type processing, the fields queried by the SQL statement are in the corresponding pojo There must be the same field corresponding to it, and the content in resultType is the position of pojo in this project.

Therefore, it is most appropriate to use resultType for single-table queries.

2. resultMap: When using resultMap to process the result type returned by the SQL statement, it is usually necessary to use mapper ResultMap is defined in .xml to correspond to pojo and corresponding table fields.

resultMap usually handles one-to-one table connections by adding a pojo that nests another table in the main table's pojo, and then uses the association node element in mapper.xml to connect to the other table. Processing

3. resultType directly represents the return type (corresponding to the entity in our model object)

resultMap is a reference to the external ResultMap (the relationship between db and model is defined in advance The implicit key-->value relationship), but resultType and resultMap cannot exist at the same time.

For more related tutorials, please visit PHP Chinese website.

The above is the detailed content of The difference between ResultMap and ResultType. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!