zoukankan      html  css  js  c++  java
  • mybatis框架中动态SQL的编写

    1.动态SQL:在SQL语句中加入流程控制。比如加入ifforeach等。

     重点掌握if语句:

     案例1

    <update id="updateItem" parameterType="com.gxa.bj.model.UserInfo">

             update userinfo set

             <if test="userName!=null">

                 userName = #{userName},

             </if>

             <if test="userPwd!=null">

                 userPwd = #{userPwd},

             </if>

             <if test= "userEmail!=null">

                 userEmail = #{userEmail},

             </if>

             <if test= "userAddress!=null">

                 userAddress = #{userAddress},

             </if>

             <if test= "regReason!=null">

                regReason = #{regReason},

             </if>

              userId=#{userId} Where userId=#{userId}

       </update>

    案例2

    <select id="getList" parameterType="com.gxa.bj.model.UserInfo" resultType="com.gxa.bj.model.UserInfo">

            Select * From userInfo Where 1=1

            <if test="userName!=null">

                And userName like #{userName}

            </if>

            <if test="userId>0">

                And userId =#{userId}

            </if>

            <if test="userPwd!=null And userPwd!=''">

                And userPwd like #{userPwd}

            </if>

            

       </select>

  • 相关阅读:
    递归二分法和另类二分法(不推荐,因为占用资源)
    内置函数汇总
    非递归二分法
    2018.10.23习题随笔
    java中的类修饰符、成员变量修饰符、方法修饰符。
    js函数中的this关键字
    HTML5 <script>元素async,defer异步加载
    那些迷糊人的回调
    js函数prototype属性学习(二)
    js函数prototype属性学习(一)
  • 原文地址:https://www.cnblogs.com/hyj-zy/p/5648897.html
Copyright © 2011-2022 走看看