MyBatis 动态SQL
1.概念 根据不同的条件需要执行不同的 SQL 命令.称为动态 SQL MyBatis 中动态 SQL 在 mapper.xml 中添加逻辑判断等. 3. If 使用 <select id="selByAccinAccout" resultType="log"> select * from log where 1=1 <!-- OGNL 表达式,直接写 key 或对象的属性.不需要添加任 何特字符号 --> <if test="accin!=null and accin!=''"> and accin=#{accin} </if> <if test="accout!=null and accout!=''"> and accout=#{accout} </if> </select> 4.1 当编写 where 标签时,如果内容中第一个是 and 去掉第一个 and 4.2 如果<where>中有内容会生成 where 关键字,如果 没有内容不 生成 where 关键字 4.3 使用示例 比直接使用<if>少写 where 1=1 <select id="selByAccinAccout" resultType="log"> select * from log <where> <if test="accin!=null and accin!=''"> and accin=#