当前位置:网站首页>Differences and application scenarios between resulttype and resultmap

Differences and application scenarios between resulttype and resultmap

2022-07-06 03:02:00 thoughtCodes

Project scenario :

Tips : Here is a brief introduction to the background of the project :
Very happy , This problem is solved by comparison , Or the original way to solve the problem :
1. check 2 Than 3 Cumulative


Problem description

Tips : The problems encountered in the project are described here :

One 、 See this problem , You may think that the entity class is not in mybatis-config.xml Configuring aliases in (alias) As a result of , As shown in the figure below :

After comparison , I found myself resultMap It has been written. resultType

Cause analysis :

Tips : Fill in the analysis of the problem here :
MyBatis In query select When mapping , Return type can be used resultType, It can also be used. resultMap,resultType Is a direct representation of the return type , and resultMap To the outside ResultMap References to , however resultType Follow resultMap Can't exist at the same time .
stay MyBatis Query mapping , In fact, every attribute found is put in a corresponding Map Inside , Where key is property name , Value is its corresponding value .
① When the return type property provided is resultType when ,MyBatis Will Map The key value pairs in it are assigned to resultType Property corresponding to the specified object . So actually MyBatis The return type of each query mapping of is ResultMap, Only when the return type property provided is resultType When ,MyBatis To assign a corresponding value to resultType Properties of the specified object .
And here is the capital corresponding map, Lowercase names correspond to map The number
② When the return type provided is resultMap when , because Map Can't represent domain model well , We need to further transform it into corresponding objects , This is often useful in complex queries .


Solution :

Tips : Fill in the specific solution to the problem here :

I fill in resulttype No problem. , There is something wrong with the assignment , however resultMap Applications that will be mapped .over. 2 Problems have been solved .

原网站

版权声明
本文为[thoughtCodes]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060300253148.html