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

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

  • 相关阅读:
    浅析String.intern()方法
    com.alibaba.druid.pool.DruidPooledConnection cannot be cast to oracle.jdbc.OracleConnection 异常解决办法
    ChannelEventRunnable handle RECEIVED operation error, channel is NettyChannel解决方法
    jsch channel is not opened原因及解决
    学习地址(oraclemysqllinux)
    python中数据分析常用函数整理
    Python之使用Pandas库实现MySQL数据库的读写
    Python数据分析
    如何用sql查询出连续三个月金额大于50的记录
    【Python项目实战】Pandas:让你像写SQL一样做数据分析(一)
  • 原文地址:https://www.cnblogs.com/thisHBZ/p/12461726.html
Copyright © 2011-2022 走看看