In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "sample analysis of mybatis foreach cycle list", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample analysis of mybatis foreach cycle list".
Foreach Loop list (map)
Go directly to the code:
The overall demand is
1. There are map map and array objects in the paging object
two。 There is a list list in the paging object and an array of objects in the map map.
Public class Page {private Map maps; private List lists; public Map getMaps () {return maps;} public void setMaps (Map maps) {this.maps = maps;} public List getLists () {return lists;} public void setLists (List lists) {this.lists = lists;}} String [] str = {"1Magne2"}; Page page = new Page () Entity paging objects (including other page attributes) maps.put ("str", str); ID page.setMaps of batch queries (maps); maps objects are stored in paging properties List mapTest = userService.mapTest (page); System.out.println (mapTest)
Demand. When you request the front page, you need to send multiple order numbers, such as 1Pol 2.
However, other parameters should also be available. Use the paging entity in conjunction with the map to save other properties. Map saves the ID or order number to be looped
The mybatis.foreach loop is as follows
Here only do the demonstration of ID or order ID, the common attribute # {id} is fine.
Take page.maps.str (str is an array)
Write reference .maps directly in collection
If the input parameter is LIST
Just change it a little bit.
Source data
Maps.put ("str", str); list.add (maps); List mapTest = userService.mapTest1 (list); System.out.println (mapTest);-- > # {item}
The principle is to tell mybatis that I need to loop list first and then get the map.str in list.
Using foreach to deal with map in list
The data structure of the parameter is an ArrayList, which needs to update the data of the database in batches under the condition of String,Integer.
Encapsulate the parameters into a qv called JsonData, and the key code for JsonData is
The method in private ArrayList usersPlatforms; public ArrayList getUsersPlatforms () {return usersPlatforms;} public void setUsersPlatforms (ArrayList usersPlatforms) {this.usersPlatforms = usersPlatforms;} Mapper is updateXxxx (JsonData jsonData) The sql of Mapper.xml is UPDATE xxx SET `xx` = 10 # {key} # {value}. The above is all the contents of the article "sample Analysis of mybatis foreach Loop list". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.