mybatis的xml文件,单SQL操作多张表案例

业务场景需求:
12个月使用12张不同的表,操作表时,希望只使用单条sql操作多张表

引入字符:$

使用方法和#一致,使用时,直接将表名作为参数传入。
举个例子:


使用$操作多张表.png
使用$操作多张表2.png

另外附上万能模板,包含排序:

<update id="updateByLowerChangeHigh" parameterType="map" statementType="STATEMENT">
    update ${tableName} set ${sqlName} = ${sqlName} -1 where 1 = 1
    <if test="startNo != null and endNo!=null">
      and ${sqlName} between ${startNo} and ${endNo}
    </if>
    <if test="sqlName2!=null">
      and ${sqlName2}
    </if>

    and school_num = ${schoolNum}

  </update>
  <update id="updateByHighChangeLower" parameterType="map" statementType="STATEMENT">
    update ${tableName} set ${sqlName} = ${sqlName} +1 where 1 = 1
    <if test="startNo != null and endNo!=null">
      and ${sqlName} between ${startNo} and ${endNo}
    </if>
    <if test="sqlName2!=null">
      and ${sqlName2}
    </if>
    and school_num = ${schoolNum}
  </update>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容