Simple explanation of resultType and resultMap in mybatis

Anyone who has studied javaEE knows that the mybatis framework is being used by a large number of JAVA programmers because of its light weight and better support for complex queries. I have not continued to use it for a long time after learning mybatis. Now, I'm getting rusty. Recently, there are projects that need to be used, so I wrote this article, hoping to share it with the majority of programmers.

The most widely used in myBatis is the select tag, but some of the parameters may be a little confusing, such as resultMap, resultType and so on. Without further ado, let's start introducing it now.

resultMap: It is mainly used to encapsulate the id name of resultMap that has been mapped in other mybatis configuration files. Mybatis will automatically correspond to the column attribute of the mapping file according to the key in the map until all the corresponding ones are completed.

resultType: Mainly used to encapsulate data types that already exist in JDK, such as Map, String, int, etc., but pay attention. When you need to return a List collection of objects, you need to use ResultMap and set its value to the object you want to store in the List that has been mapped by the xml file.

The result of myBatis after using the select tag query is encapsulated by Map by default. where key is the field name and value is the value. So when you want to return some fields of the table directly, you need to set resultType to HashMap.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325741464&siteId=291194637
Recommended