<selectid="selectUserWithEnumJudge"resultType="entity.SysUser"> select user_id,dept_id,login_name,user_name,user_type,email from sys_user <where> <iftest="code != null and code == @enums.StatusEnum@ONE.getCode()"> and user_name = 'admin' </if> <iftest="code != null and code == @enums.StatusEnum@TWO.getCode()"> and user_name = 'fix' </if> </where> </select>
</mapper>
数据库记录
请求接口
结果:
1 2 3 4 5 6 7 8
Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@667d3020] was not registered for synchronization because synchronization is not active JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e784cb9] will not be managed by Spring ==> Preparing: select user_id,dept_id,login_name,user_name,user_type,email from sys_user WHERE user_name = 'admin' ==> Parameters: <== Columns: user_id, dept_id, login_name, user_name, user_type, email <== Row: 1, 103, admin, admin, 00, admin@admin.com <== Total: 1
再次请求
结果:
1 2 3 4 5 6 7 8
Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5470f3e5] was not registered for synchronization because synchronization is not active JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3e784cb9] will not be managed by Spring ==> Preparing: select user_id,dept_id,login_name,user_name,user_type,email from sys_user WHERE user_name = 'fix' ==> Parameters: <== Columns: user_id, dept_id, login_name, user_name, user_type, email <== Row: 2, 105, fix, fix, 00, fix@fix.com <== Total: 1