mybatis并没有if..else,在mybatis的sql mapper文件中,条件判断要用choose..when..otherwise。
<choose>
<when test="status == 'PROCES' or status == 'PENDNG'"> and batcol.status in('PROCES','PENDNG')</when>
<when test="status == 'PREAUD'"> and batcol.status = '--'</when>
<otherwise> and batcol.status = #{status,jdbcType=CHAR}</otherwise>
</choose>
<if test="status != null and status != 'all'" >
<choose>
<when test="status == 'PROCES' or status == 'PENDNG'"> and batcol.status in('PROCES','PENDNG')</when>
<when test="status == 'PREAUD'"> and batcol.status = '--'</when>
<otherwise> and batcol.status = #{status,jdbcType=CHAR}</otherwise>
</choose>
</if>
choose为一个整体,
when表示if ,(when可重复,即实现if..else if..else if..)
otherwise表示else。
注意: test里的等号用==,而不是=。
【IDEA使用mybatis插件】
IDEA2019或IDEA2020,files→settings→plugins,可以搜索Free Mybatis plugin。安装后会提高我们的应用开发效率。
- mybatis-generator
- 我们打开生成的接口具体操作数据的Dao.java(有的命名是***Mapper.java),就可以看到右边右箭头可以点击,就可以跳转到具体的映射xml
- xml也可以直接跳转到具体的接口