Home > Back-end >  Mybatis how to return a multi-table query results
Mybatis how to return a multi-table query results

Time:09-18


This is my through the multi-table query results,
I how the mapper XML file to write the return value

I need to get this data, return a List CodePudding user response:

Directly define an entity class receives the parameter line ah do not want to create the object using the map as a return value type also line ah

CodePudding user response:

reference 1st floor qq_35261789 response:
directly define an entity class receives the parameters under the line ah do not want to create the object using the map as a return value type line also ah

I am too entity class trouble, see this can not be done by change the return value,
If use the map back to me how to write the resultMap here?

CodePudding user response:

refer to the second floor qq_38619862 response:
Quote: refer to 1st floor qq_35261789 response:

Directly define an entity class receives the parameters under the line ah do not want to create the object using the map as a return value type line also ah

I am too entity class trouble, see this can not be done by change the return value,
If use the map back to me how to write the resultMap here?


Don't set set the resultMap resultType

CodePudding user response:

refer to the second floor qq_38619862 response:
Quote: refer to 1st floor qq_35261789 response:

Directly define an entity class receives the parameters under the line ah do not want to create the object using the map as a return value type line also ah

I am too entity class trouble, see this can not be done by change the return value,
If use the map back to me how to write the resultMap here?
this return should be a List

CodePudding user response:

reference 4 floor qq_35261789 response:
Quote: refer to the second floor qq_38619862 response:

Quote: refer to 1st floor qq_35261789 response:

Directly define an entity class receives the parameters under the line ah do not want to create the object using the map as a return value type line also ah

I am too entity class trouble, see this can not be done by change the return value,
If use the map back to me how to write the resultMap here?
this return should be a List

Ok thank you very much ~

CodePudding user response:

The mybatis resultmap need to define the
Using the built-in & lt; ResultMap> Tags to achieve

CodePudding user response:

 & lt; Select id="all" resultType="map" & gt; Select * from the user where flag=1 & lt;/select>//query all flag=1 data, return type for the map 
List All (@ Param (" flag ") Integer flag);//using parameters, do not use the bean, list Accept return data

CodePudding user response:

The return type List Map> ResultType="Map for Java. Util."

CodePudding user response:

The elder brothers you this idea a little problem, after the trouble with the map, can let a person very trouble...
Unless you are of this function is uncertain entities

CodePudding user response:

Return is a List< directly; Map> Each line, the inside of the Map is the corresponding relation of data and domain name

CodePudding user response:

Can be used directly resultType="map"

If you want to use resultMap, need custom


CodePudding user response:

The
reference minghao. The eighth floor response:
return type List Map> ResultType="Java. Util. Map"

There is nothing wrong with this,
The original poster is not abandon trouble, but are reluctant to accept have a class this type specification,
The development of the original poster is more suited for nodejs, which is fan type,
Java itself is the language classes and objects, the provisions of the first class, just can have the corresponding object,
At least I don't advocate using the Map as encapsulated data of the object, unless the query results of field can dynamically change,
Here's why:
1. For others to read your code will be relatively difficult, a JavaBean will more to understand;
2. The communication programming ideas and design ideas, the Map for others may become a black hole, inside put not the specific content of the image;
3. When the program you write more later, will have a better understanding of how to encapsulate, will realize, classes, Java programs after split into two major categories, will make the programming more simple and clear, that is the behavior and data two categories, one is to manipulate data, another saving data, only in the javabeans only save the data, we usually don't use the Map instead of a JavaBean, this need you to encapsulate the understanding of the word, whether achieved a certain degree,
  • Related