• 课时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:代表当前数据库的名字

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

  • 相关阅读:
    JSONObject.fromObject--JSON与对象的转换
    oracle 10g学习6
    eclipse中导入svn的三种方式
    网络方面知识收集
    oracle 10g学习之分组函数
    求m阶矩阵的n次幂
    分解质因数
    字符串对比
    十六进制转十进制
    十进制转化十六进制
  • 原文地址:https://www.cnblogs.com/thisHBZ/p/12461726.html
Copyright © 2020-2023  润新知