In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I'll show you how to set the map results returned by mybatis in order. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
The map result returned by mybatis is set in order.
The map results returned by mybatis are set in order (consistent with the domain order of the query)
In this case, there is no sort.
If you want to come in the order of inquiry
Replace it with
Orderly display of query results in mybatis
How to display the results of sql query in mybatis in an orderly manner according to the self-defined resultMap?
1. Analyze why the result is out of order
Take a look at the following picture first:
The first is a select statement, and resultType is a class encapsulated by this project.
The second is the resultMap statement. Type is also a class encapsulated by this project.
The third is a class encapsulated by this project. You can see that it inherits HashMap.
From the above figure, we can see that most of the data accessed by HashMap are out of order, so the key points are found.
To get the results in order, replace HashMap with LinkedHashMap
2. Modification
Because the PageData wrapper class is also used elsewhere in this project, I only change the
Change resultType to java.util.LinkedHashMap
Change typeype to java.util.LinkedHashMap
Supplement
HashMap:
HashMap is the most commonly used Map, it stores data according to the HashCode value of the key, and its value can be obtained directly according to the key, so it has fast access speed.
HashMap can only allow the key of one record to be Null
Allow the value of multiple records to be Null
HashMap does not support thread synchronization, that is, multiple threads can write HashMap at any one time.
May lead to data inconsistencies.
LinkedHashMap:
LinkedHashMap is also a HashMap, but maintains a two-way linked list internally, which can keep the order.
This is how to set the order of the map results returned by mybatis. For more content related to the order of the map results returned by mybatis, you can search the previous articles or browse the following articles to learn! I believe the editor will add more knowledge to you. I hope you can support it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.