mybatise 动态sql

1. <if><choose>

动态sql 相当 <if> Java if  满足多个条件  <choose> <when>    java switch case 满足一个条件

2.<where> <set>

判断是否添加 and 或者 or

3.<foreach>

foreach元素的属性主要有 item,index,collection,open,separator,close。

item表示集合中每一个元素进行迭代时的别名.

index指 定一个名字,用于表示在迭代过程中,每次迭代到的位置.

open表示该语句以什么开始,separator表示在每次进行迭代之间以什么符号作为分隔 符.

close表示以什么结束.

<select id="selectTestForEach" parameterType="News" resultMap="NewsResultMapper">
  select * from t_news n where 
  <foreach collection="listTag" index="index" item="tag" open=""
    separator="or" close="">
   #{tag} in n.tags
  </foreach>
 </select>

原文地址:https://www.cnblogs.com/zxf330301/p/7140716.html