
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 visitPHP 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!
The difference between static web pages and dynamic web pages
What is the difference between 4g and 5g mobile phones?
The difference between k8s and docker
The difference between JD.com's self-operated flagship store and its official flagship store
Introduction to hard disk interface types
Solution to gmail being blocked
What does data encryption storage include?
HTML to create web pages