Mybatis(四):动态sql语句

1 < where> < if>

1.1< if>

语法:

<if test="判断java对象的属性值">
         部分sql语句
</if>

1.2< where>

用来包含 多个的, 当多个if有一个成立的, 会自动增加一个where关键字,并去掉 if中多余的 and ,or等。
通常这两个一起使用。

2 < foreach>

循环java中的数组,list集合的。 主要用在sql的in语句中。
比如:学生id是 1001,1002,1003的三个学生

  select * from student where id in
  <foreach collection="" item="" open="" close="" separator="">
        #{stu.id}
    </foreach>

猜你喜欢

转载自blog.csdn.net/qq_41984117/article/details/110522765