mybatis入门截图三

Posted 乔克叔叔

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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条件  查询所有  

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

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

 

 

 

以上是关于mybatis入门截图三的主要内容,如果未能解决你的问题,请参考以下文章

mybatis入门截图二

mybatis入门截图四(订单商品数据模型 一对一,一对多,多对多)

mybatis快速入门

mybatis入门

MyBatis入门配置

mybatis入门系列三之类型转换器