mybatis入门截图三

 

 

-----------------------------------------------

    <!-- 用户信息的综合查询 -->
    <select id="userlist" parameterType="org.mybatis.po.UserQueryVo" resultType="org.mybatis.po.UserCustom">
        <!-- 原来的sql -->
        <!-- select *from user where user.sex=#{userCustom.sex} and user.username like '%${userCustom.username}%' -->
        <!-- 动态sql -->
        select *from user 
        <where>
            <if test="userCustom!=null">
                <if test="userCustom.sex!=null and userCustom.sex!=''">
                    and user.sex=#{userCustom.sex}
                </if>
                <if test="userCustom.username!=null and userCustom.username!=''">
                    and user.username=#{userCustom.username}
                </if>
            </if>
        </where>
    </select>

这样在传入参数时,传递null  也不会报错。即sql语句没有where条件  查询所有  

------------------------------------------

-------------------------

 

原文地址:https://www.cnblogs.com/Joke-Jay/p/7471318.html