MyBatis框架

5.4 set

  • set 主要是用于解决修改操作中SQL语句中可能多出逗号的问题

<update id=“updateEmpByConditionSet”>

                   update  tbl_employee 

                   <set>

                            <if test=“lastName!=null &amp;&amp; lastName!=&quot;&quot;”>

                                      last_name = #{lastName},

                            </if>

                            <if test=“email!=null and email.trim()!=””>

                                      email = #{email} ,

                            </if>

                            <if test=“&quot;m&quot;.equals(gender) or &quot;f&quot;.equals(gender)”>

                                     gender = #{gender}

                            </if>

                   </set>

                    where id =#{id}

         </update>

 

5.5 choose(when、otherwise)

  • choose 主要是用于分支判断,类似于java中的switch case,只会满足所有分支中的一个

<select id=“getEmpsByConditionChoose” resultType=“com.atguigu.mybatis.beans.Employee”>

              select id ,last_name, email,gender from tbl_employee

              <where>

                     <choose>

                            <when test=“id!=null”>

                                   id = #{id}

                            </when>

                            <when test=“lastName!=null”>

                                   last_name = #{lastName}

                            </when>

                            <when test=“email!=null”>

                                   email = #{email}

                            </when>

                            <otherwise>

                                    gender = ‘m’

                            </otherwise>

                     </choose>

              </where>

</select>

 

 


上一篇:
下一篇:
关于尚硅谷
教育理念
名师团队
学员心声
资源下载
视频下载
资料下载
工具下载
加入我们
招聘岗位
岗位介绍
招贤纳师
联系我们
全国统一咨询电话:010-56253825
地址:北京市昌平区宏福科技园综合楼6层(北京校区)

深圳市宝安区西部硅谷大厦B座C区一层(深圳校区)

上海市松江区谷阳北路166号大江商厦6层(上海校区)

武汉市东湖高新开发区东湖网谷(武汉校区)