MyBatis loop to get key and value in a map

Source: Internet
Author: User

Sometimes it is necessary to simply get all the keys and value from a map and spell it in the SQL statement. MyBatis provides a way to traverse the entryset in the map and then throw the key into the index, and the value is thrown into the item. An example of a specific use is as follows:

	<insert id= "OperationName" parametertype= "map" >
		INSERT INTO table_name (Hot_word, CNT)
		VALUES
		< foreach item= "value" index= "key" collection= "Mapdata.entryset ()" Open= "(" separator= "), (" close= ")" >
			#{key}, # {Value}
		</foreach> on
		DUPLICATE KEY UPDATE
		cnt=values (CNT)
	</insert>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.