mybatis执行批量更新batch update 的方法(Oracle /Mysql)

mybatis在使用批量更新时mysql和oracle有一些差别,记录下以免下次忘记。

一、mybatis执行批量更新batch update 的方法(mysql数据库)
1、数据库连接必须配置:&allowMultiQueries=true(切记一定要加上这个属性,否则会有问题!)

jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true

2、批量修改并加判断条件


    
       update HSP_DOCADVICE_INF
        
		      
		        VST_CAD = #{hspDocadviceInf.vstCad,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_ISDAT = #{hspDocadviceInf.docadviceIsdat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_BEDAT = #{hspDocadviceInf.docadviceBedat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_NAM = #{hspDocadviceInf.docadviceNam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_NUIMDAT = #{hspDocadviceInf.docadviceNuimdat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_NUIMNAM = #{hspDocadviceInf.docadviceNuimnam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_DOCSTDAT = #{hspDocadviceInf.docadviceDocstdat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_DOCSTNAM = #{hspDocadviceInf.docadviceDocstnam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_NUSTDAT = #{hspDocadviceInf.docadviceNustdat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_NUSTNAM = #{hspDocadviceInf.docadviceNustnam,jdbcType=VARCHAR},
		      
		      
		        CREATE_DAT = #{hspDocadviceInf.createDat,jdbcType=TIMESTAMP},
		      
		      
		        CREATE_NUM = #{hspDocadviceInf.createNum,jdbcType=VARCHAR},
		      
		      
		        CREATE_NAM = #{hspDocadviceInf.createNam,jdbcType=VARCHAR},
		      
		      
		        UPDATE_DAT = #{hspDocadviceInf.updateDat,jdbcType=TIMESTAMP},
		      
		      
		        UPDATE_NUM = #{hspDocadviceInf.updateNum,jdbcType=VARCHAR},
		      
		      
		        UPDATE_NAM = #{hspDocadviceInf.updateNam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_WAY = #{hspDocadviceInf.docadviceWay,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_TYPE = #{hspDocadviceInf.docadviceType,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_FLAG = #{hspDocadviceInf.docadviceFlag,jdbcType=CHAR},
		      
		      
		        DOCADVICE_YYJL = #{hspDocadviceInf.docadviceYyjl,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_BZ = #{hspDocadviceInf.docadviceBz,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_MAINFLG = #{hspDocadviceInf.docadviceMainflg,jdbcType=VARCHAR},
		      
		      
		        PX = #{hspDocadviceInf.px,jdbcType=VARCHAR},
		      
		      
		        GYFSMC = #{hspDocadviceInf.gyfsmc,jdbcType=VARCHAR},
		      
		      
		        SL = #{hspDocadviceInf.sl,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_STATUS = #{hspDocadviceInf.docadviceStatus,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_CHECKNAM = #{hspDocadviceInf.docadviceChecknam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_NUIMNAM2 = #{hspDocadviceInf.docadviceNuimnam2,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_CONTENT = #{hspDocadviceInf.docadviceContent,jdbcType=CLOB},
		      
		    
        
            DOCADVICE_SEQ = #{hspDocadviceInf.docadviceSeq,jdbcType=VARCHAR}
        
    

3、java 接口

public int updateNewYzxx(@Param(value = "list") List list);

二、mybatis执行批量更新batch update 的方法(oracle数据库)


    
       update HSP_DOCADVICE_INF
        
		      
		        VST_CAD = #{hspDocadviceInf.vstCad,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_ISDAT = #{hspDocadviceInf.docadviceIsdat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_BEDAT = #{hspDocadviceInf.docadviceBedat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_NAM = #{hspDocadviceInf.docadviceNam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_NUIMDAT = #{hspDocadviceInf.docadviceNuimdat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_NUIMNAM = #{hspDocadviceInf.docadviceNuimnam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_DOCSTDAT = #{hspDocadviceInf.docadviceDocstdat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_DOCSTNAM = #{hspDocadviceInf.docadviceDocstnam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_NUSTDAT = #{hspDocadviceInf.docadviceNustdat,jdbcType=TIMESTAMP},
		      
		      
		        DOCADVICE_NUSTNAM = #{hspDocadviceInf.docadviceNustnam,jdbcType=VARCHAR},
		      
		      
		        CREATE_DAT = #{hspDocadviceInf.createDat,jdbcType=TIMESTAMP},
		      
		      
		        CREATE_NUM = #{hspDocadviceInf.createNum,jdbcType=VARCHAR},
		      
		      
		        CREATE_NAM = #{hspDocadviceInf.createNam,jdbcType=VARCHAR},
		      
		      
		        UPDATE_DAT = #{hspDocadviceInf.updateDat,jdbcType=TIMESTAMP},
		      
		      
		        UPDATE_NUM = #{hspDocadviceInf.updateNum,jdbcType=VARCHAR},
		      
		      
		        UPDATE_NAM = #{hspDocadviceInf.updateNam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_WAY = #{hspDocadviceInf.docadviceWay,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_TYPE = #{hspDocadviceInf.docadviceType,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_FLAG = #{hspDocadviceInf.docadviceFlag,jdbcType=CHAR},
		      
		      
		        DOCADVICE_YYJL = #{hspDocadviceInf.docadviceYyjl,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_BZ = #{hspDocadviceInf.docadviceBz,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_MAINFLG = #{hspDocadviceInf.docadviceMainflg,jdbcType=VARCHAR},
		      
		      
		        PX = #{hspDocadviceInf.px,jdbcType=VARCHAR},
		      
		      
		        GYFSMC = #{hspDocadviceInf.gyfsmc,jdbcType=VARCHAR},
		      
		      
		        SL = #{hspDocadviceInf.sl,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_STATUS = #{hspDocadviceInf.docadviceStatus,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_CHECKNAM = #{hspDocadviceInf.docadviceChecknam,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_NUIMNAM2 = #{hspDocadviceInf.docadviceNuimnam2,jdbcType=VARCHAR},
		      
		      
		        DOCADVICE_CONTENT = #{hspDocadviceInf.docadviceContent,jdbcType=CLOB},
		      
		    
        
            DOCADVICE_SEQ = #{hspDocadviceInf.docadviceSeq,jdbcType=VARCHAR}
        
    

2、java接口

public int updateNewYzxx(@Param(value = "list") List list);

**

总结:mysql批量更改数据源配置文件中必须配置:&allowMultiQueries=true Oracle批量修改数据时foreach中要配置 open=“begin” close=";end;" separator=";"

**

你可能感兴趣的:(MyBatis,Java基础)