课时18:trim标签与MyBatis内置参数

.1)trim标签的使用

  1.使用trim处理查询和修改操作

<!--查询操作处理-->
<select id="queryStudentByNoWithONGL" resultType="Student" parameterType="student">
        select * from student
        <trim prefix="where" prefixOverrides="and|or">
            <if test="stuName!=null and stuName!=''">and stuName like '%${stuName}%'</if>
            <if test="graName!=null and graName!=''">and graName like '%${graName}%'</if>
            <if test="stuAge!=null and stuAge!=''">and stuAge = #{stuAge} </if>
        </trim>
    </select>
<!--修改操作处理-->
<update id="updateSmbmsProviderByIdTrim" parameterType="SmbmsProvider">
        update smbms_provider
        <trim prefix="set" suffix="where id=#{id}" suffixOverrides=",">
        <if test="proCode!=null and proCode!=''">proCode=#{proCode},</if>
        <if test="proName!=null and proName!=''">proName=#{proName},</if>
        <if test="proDesc!=null and proDesc!=''">proDesc=#{proDesc},</if>
        <if test="proContact!=null and proContact!=''">proContact=#{proContact},</if>
        <if test="proPhone!=null and proPhone!=''">proPhone=#{proPhone},</if>
        <if test="proAddress!=null and proAddress!=''">proAddress=#{proAddress},</if>
        <if test="proFax!=null and proFax!=''">proFax=#{proFax},</if>
        <if test="createdBy!=null">createdBy=#{createdBy},</if>
        <if test="creationDate!=null">creationDate=#{creationDate},</if>
        <if test="modifyDate!=null">modifyDate=#{modifyDate},</if>
        <if test="modifyBy!=null">modifyBy=#{modifyBy},</if>
        </trim>
    </update>

  2.trim标签里面的属性的作用:

    2.1 prefix:在前缀加上标签或者加上一些语句 suffix:在后缀加上标签或者加上一些语句

    2.2 suffixOverrides:在后缀去某些信息 prefixOverrides:在在前缀去掉某些信息

 .2)mybatis的内置参数

  1.内置参数 _parameter :代表mybatis的输入参数

<select id="queryStudentByNoWithONGL" resultType="Student" parameterType="student">
        select * from student
        <trim prefix="where" prefixOverrides="and|or">
            <if test="stuName!=null and stuName!=''">and stuName like '%${_parameter.stuName}%'</if>
            <if test="graName!=null and graName!=''">and graName like '%${graName}%'</if>
            <if test="stuAge!=null and stuAge!=''">and stuAge = #{stuAge} </if>
        </trim>
    </select>

    1.1 如果是基本类型+String 直接填写这个内置参数即可

  2.内置参数_databaseId:代表当前数据库的名字

    这个标签的作用就是可以动态的知道数据库环境

 

posted @ 2020-03-11 13:00  何邦柱  阅读(203)  评论(1编辑  收藏  举报