当前位置:Gxlcms > 数据库问题 > mybatis入门-动态sql

mybatis入门-动态sql

时间:2021-07-01 10:21:17 帮助过:24人阅读

<sql id="query_user_where"> 2 <if test="userCustom!=null"> 3 <if test="ids!=null"> 4 <!-- 使用 foreach遍历传入ids 5 collection:指定输入 对象中集合属性 6 item:每个遍历生成对象中 7 open:开始遍历时拼接的串 8 close:结束遍历时拼接的串 9 separator:遍历的两个对象中需要拼接的串 10 --> 11 <!-- 使用实现下边的sql拼接: 12 AND (id=1 OR id=10 OR id=16) 13 --> 14 <foreach collection="ids" item="user_id" open="AND (" close=")" separator="or"> 15 <!-- 每个遍历需要拼接的串 --> 16 id=#{user_id} 17 </foreach> 18 19 <!-- 实现 “ and id IN(1,10,16)”拼接 --> 20 <!-- <foreach collection="ids" item="user_id" open="and id IN(" close=")" separator=","> 21 每个遍历需要拼接的串 22 #{user_id} 23 </foreach> --> 24 25 </if> 26 </if> 27 </sql> View Code

 

mybatis入门-动态sql

标签:开始   div   bsp   代码块   src   item   ide   foreach   代码   

人气教程排行