zoukankan      html  css  js  c++  java
  • 课时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:代表当前数据库的名字

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

  • 相关阅读:
    pythonsys.exit()
    Python字符串格式化
    Json概述以及python对json的相关操作
    python学习笔记——异常
    Python:sys.argv[]用法
    python学习笔记——字符串,列表,字典,集合,数值,sorted
    python class 的属性
    Python模块——unittest 单元测试
    从sql2000 复制数据到sql2005
    abstract、virtual及override
  • 原文地址:https://www.cnblogs.com/thisHBZ/p/12461726.html
Copyright © 2011-2022 走看看