Mybatis foreach usage, in multiple data dynamic conditions

The attributes of the foreach element mainly include item, index, collection, open, separator, close and other attributes

Example:

		DELETE FROM TABLE.XAENV XAENV
 		 WHERE XAENV.envidk IN
 		 <foreach collection="keyList" item="envidk" open="(" separator="," close=")">
 		 	#{envidk}
 		 </foreach>

1.#{envidk} The code block
executed 2.collection: The parameter passed in by the dao layer can be a list collection or an array
3. item: the alias of a single object, because the passed in is a collection of multiple objects
4. open: code block The character to be inserted at the beginning
5. close: the character executed after the code block loop
6. separator: the character inserted between the code block loop
Assuming that the keyId passed has luchan, winnie, and lucy changed as follows:

DELETE FROM TABLE.XAENV XAENV  WHERE XAENV.envidk IN ('luchan','winnie','lucy')
 		 	

Reference link: 1


  1. https://www.cnblogs.com/fnlingnzb-learner/p/10566452.html ↩︎

Guess you like

Origin blog.csdn.net/weixin_40620651/article/details/114363885