mapperSQL中的预处理及尾处理

<!--    获取用户 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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容