长安网站优化,网站建设方式与信息化,企业网站建设开发多少钱,彩虹网站建设foreach标签简介 实践
demo1 简单的一个批量更新#xff0c;这里传入了一个List类型的集合作为参数#xff0c;拼接到 in 的后面 #xff0c;来实现一个简单的批量更新
update idupdateVislxble parameterTypejava.util.Listupdate model…foreach标签简介 实践
demo1 简单的一个批量更新这里传入了一个List类型的集合作为参数拼接到 in 的后面 来实现一个简单的批量更新
update idupdateVislxble parameterTypejava.util.Listupdate models set visible 0where llm_idINforeach collectionallVisible itemvisible open( separator, close)#{visible}/foreach/updatecollection“allVisible”allVisible代表传入的集合item“visible” visible代表集合的每一个元素open“(” 代表以 开头separator“,” 代表以“”分隔close“)” 代表以“”结束
本质上这里是个拼接所有要保证这里list不为空不然会报错
demo2 这里还是个批量更新但是传入的参数多了起来这里是的入参是个map,并且里面这个status是一个List类型的 select idgetModelEvaluateTaskPage parameterTypejava.util.Map resultTypecom.test.testselect * from evaluate_tasks twhereif teststatus !nulland t.status inforeach itemitem indexindex collectionstatusopen( separator, close)#{item}/foreach/ifif testtaskName !null and taskName!and t.task_name like concat(%,#{taskName},%)/ifif teststartTime !null and endTime!nulland t.created_time between #{startTime} and #{endTime}/ifand t.user_id #{userId}/whereorder by t.created_time ${sort}/selectdemo3 这里的场景传入了一个list里面是多个对象根据对象的属性A去更新属性B,这里额外使用了 case when then update idbitchUpdateStatueById parameterTypejava.util.ListUPDATE evaluate_tasksSET status CASE service_nameforeach collectionupdates itemupdate separator WHEN #{update.serviceName} THEN #{update.status}/foreachEND,updated_time CASE service_nameforeach collectionupdates itemupdate separator WHEN #{update.serviceName} THEN #{update.endTime}/foreachENDWHERE service_name INforeach collectionupdates itemupdate open( separator, close)#{update.serviceName}/foreach/update