动态SQL
给xml配置文件中的SQL加入逻辑
1 .if
<select id="sel" resultType="people">
select * from people where 1=1
<!-- OGNL 表达式,直接写key 或对象的属性.不需要添加任
何特字符号-->
<if test="name!=null and name!=''">
and name=#{name}
</if>
<if test="id!=null and id!=''">
and id=#{id}
</if>
</select>
2.where
去掉第一个and
内有内容才生成where
<select id="sel" resultType="people">
select * from people
<where>
<if test="name!=null and name!=''">
and id=#{id}
</if>
<if test="id!=null and id!=''">
and id=#{id}
</if>
</where>
</select>
-
相当于switch