美文网首页
mapperSQL中的预处理及尾处理

mapperSQL中的预处理及尾处理

作者: 旦暮何枯 | 来源:发表于2019-11-07 21:32 被阅读0次
<!--    获取用户 sql-->
<!--    trim prefixOverrides 标签预处理, if(null != id and ''!= id)  则 添加搜索条件 and id=#{id} -->
    <select id="getUserInfo" parameterType="com.course.usertest.model.User" resultType="com.course.usertest.model.User">
        select * from user
        <trim prefix="where" prefixOverrides="and">
            <if test="null != id and ''!= id">
                and id = #{id}
            </if>
            <if test="null != userName and '' != useName">
                and userName=#{userName}
            </if>
            <if test="null != password and '' != password">
                and password=#{password}
            </if>
            <if test="null != age and '' != age">
                and age=#{age}
            </if>
            <if test="null != sex and '' != sex">
                and sex=#{sex}
            </if>
            <if test="null != permission and '' != permission">
                and permission=#{permission}
            </if>
            <if test="null != isDelete and '' != isDelete">
                and isDelete=#{isDelete}
            </if>
        </trim>
    </select>

<!--    更新/ 删除用户信息-->
<!--    trim suffixOverrides 标签尾处理 -->
    <update id="updateUserInfo" parameterType="com.course.usertest.model.User">
        update user
        <trim prefix="SET" suffixOverrides=",">
            <if test="null != userName and '' != useName">
                and userName=#{userName},
            </if>
            <if test="null != password and '' != password">
                and password=#{password},
            </if>
            <if test="null != age and '' != age">
                and age=#{age},
            </if>
            <if test="null != sex and '' != sex">
                and sex=#{sex},
            </if>
            <if test="null != permission and '' != permission">
                and permission=#{permission},
            </if>
            <if test="null != isDelete and '' != isDelete">
                and isDelete=#{isDelete},
            </if>
        </trim>
    </update>

相关文章

网友评论

      本文标题:mapperSQL中的预处理及尾处理

      本文链接:https://www.haomeiwen.com/subject/pdrbbctx.html