mybatis 批量插入和where条件使用

摘要:
BEGIN插入PTS_online_resultvalues(SEQ_PTS_online_RESULT.nextval,#{item.app_name,jdbcType=VARCHAR},#{item.app_trade,jdbc类型=VARCCHAR}),#{item.action_name,jdbcType=VARCHAR},#item.con_user,jdbtType=VARCHAR}、#{itet.press_time,jdbbcType=VARCHAR},#1 item.avg_time、jdbcType=VARCHAR},#,#{item.succ_action,jdbcType=VARCHAR},#{item.fail_action、jdbcType=VARCHAR},#{item.succ_rate,jdbcType=VARCHAR},#{item.app_cpu_util,jdbc类型=VARCHA},#{itet.db_cpu_til,jdbC类型=VARCHAR}、#{tem.scenario_type,jbcType=VARCCHAR}、#{item.app_version,jdbcType=VAR CHAR},#{tem.online_developer,jdb类型=VAR charr},s、sysdate、sysdata);结束;BEGINinsertintops_batch_resultvalues(SEQ_PTS_batch_RESULT.nextval,#{item.batch_app_name,jdbcType=VARCHAR},#{item.bach_app_trade,jdbc类型=VARCCHAR}),#{item.perpare_data,jdbc-Type=VARCHAR},#{itet.total_cost,jdbtType=VARCHAR},#item.succ_record,jcbcType=VARCHAR},#{tem.fail_record、jdbcType=VARCHAR},=VARCHAR},#{item.batch_app_cpu_util,jdbcType=VARCCHAR}#{item.batch_db_cpu_util,jdbcType=VARCHAR},#{item.scenario_type,jdbtType=VARCHAR}、#{tem.batch_app_version,jdbc type=VAR CHAR}、#{itet.batch_tester、jdbcType=VARCHAR}、#{itep.batch_developer、jdbc type=VAR char},#{tem.remark、jdbtType=VARCHAR}、sysdate、sys date);结束;选择。结果_ ID,t。应用程序名称,t。应用_贸易,t。行动_名称,t。CON_用户,t。压力_时间,t。平均时间,t.TPS,t。SUCC_动作,t。故障_动作,t。吸入速率,t。应用程序_ CPU _实用程序,t。DB_ CPU_ UTIL,吨。场景类型,t。应用版本,t。在线测试仪,t。在线_开发商,t。备注,to_ char(t.CREATE_TIME,'yyy-mm-ddhh24:mi:ss'),to_ char(t.UPDATE_TIME,'yyy-mm-ddhh24:mi:ss')来自(selectrownumrn,p1.*来自(selection*frompts.pts_online_resultporderbyp.result_addesc)p1和p1.app_ namelikeconcat('%',concat)(#{perResult模型.app_nname,jdbcType=VARCHAR},'%')ario_type!=nullandperResultModel.scenario_ttype!=“”“˃和p1.scenario_typelikeconcat(“%”,concat)(#{perResultModel.scenario_type,jdbcType=VARCHAR},“%”)˂iftest=“perResultModel.app_trade!=nullandperResultodel.app_ttrade!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.dao.IPerformanceResultDao">
        <insert id="addOnlineResult"parameterType="java.util.List">BEGIN
            <foreach collection="list"item="item"index="index"separator=";">insert into pts_online_result values(
                    SEQ_PTS_ONLINE_RESULT.nextval,
                    #{item.app_name,jdbcType=VARCHAR},
                    #{item.app_trade,jdbcType=VARCHAR},
                    #{item.action_name,jdbcType=VARCHAR},
                    #{item.con_user,jdbcType=VARCHAR},
                    #{item.press_time,jdbcType=VARCHAR},
                    #{item.avg_time,jdbcType=VARCHAR},
                    #{item.tps,jdbcType=VARCHAR},
                    #{item.succ_action,jdbcType=VARCHAR},
                    #{item.fail_action,jdbcType=VARCHAR},
                    #{item.succ_rate,jdbcType=VARCHAR},
                    #{item.app_cpu_util,jdbcType=VARCHAR},
                    #{item.db_cpu_util,jdbcType=VARCHAR},
                    #{item.scenario_type,jdbcType=VARCHAR},
                    #{item.app_version,jdbcType=VARCHAR},
                    #{item.online_tester,jdbcType=VARCHAR},
                    #{item.online_developer,jdbcType=VARCHAR},
                    #{item.remark,jdbcType=VARCHAR},
                    sysdate,
                    sysdate
                )
            </foreach>;end;
        </insert>
        
            <insert id="addBatchResult"parameterType="java.util.List">BEGIN
            <foreach collection="list"item="item"index="index"separator=";">insert into pts_batch_result values(
                    SEQ_PTS_BATCH_RESULT.nextval,
                    #{item.batch_app_name,jdbcType=VARCHAR},
                    #{item.batch_app_trade,jdbcType=VARCHAR},
                    #{item.perpare_data,jdbcType=VARCHAR},
                    #{item.total_cost,jdbcType=VARCHAR},
                    #{item.succ_record,jdbcType=VARCHAR},
                    #{item.fail_record,jdbcType=VARCHAR},
                    #{item.succ_rate,jdbcType=VARCHAR},
                    #{item.batch_app_cpu_util,jdbcType=VARCHAR},
                    #{item.batch_db_cpu_util,jdbcType=VARCHAR},
                    #{item.scenario_type,jdbcType=VARCHAR},
                    #{item.batch_app_version,jdbcType=VARCHAR},
                    #{item.batch_tester,jdbcType=VARCHAR},
                    #{item.batch_developer,jdbcType=VARCHAR},
                    #{item.remark,jdbcType=VARCHAR},
                    sysdate,
                    sysdate
                )
            </foreach>;end;
        </insert>
        <select id="queryOnlineResultList"resultType="com.pts.model.PerformanceOnlineResultModel" >select t.RESULT_ID
                    ,t.APP_NAME
                    ,t.APP_TRADE
                    ,t.ACTION_NAME
                    ,t.CON_USER
                    ,t.PRESS_TIME
                    ,t.AVG_TIME
                    ,t.TPS
                    ,t.SUCC_ACTION
                    ,t.FAIL_ACTION
                    ,t.SUCC_RATE
                    ,t.APP_CPU_UTIL
                    ,t.DB_CPU_UTIL
                    ,t.SCENARIO_TYPE
                    ,t.APP_VERSION
                    ,t.ONLINE_TESTER
                    ,t.ONLINE_DEVELOPER
                    ,t.REMARK
                    ,to_char(t.CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss')
                      ,to_char(t.UPDATE_TIME, 'yyyy-mm-dd hh24:mi:ss') 
                from ( select 
                   rownum rn ,p1.*
                   from 
                   (select * from pts.pts_online_result p order by p.result_id desc) p1
             <where>
                <if test="perResultModel.app_name != null and perResultModel.app_name != ''">and p1.app_name like concat('%',concat(#{perResultModel.app_name,jdbcType=VARCHAR},'%'))
                </if> 
                <if test="perResultModel.scenario_type != null and perResultModel.scenario_type != ''">and p1.scenario_type like concat('%',concat(#{perResultModel.scenario_type,jdbcType=VARCHAR},'%'))
                </if>        
                 <if test="perResultModel.app_trade != null and perResultModel.app_trade != ''">and p1.app_trade like concat('%',concat(#{perResultModel.app_trade,jdbcType=VARCHAR},'%'))
                </if>
                <if test="perResultModel.online_tester != null and perResultModel.online_tester != ''">and p1.online_tester like concat('%',concat(#{perResultModel.online_tester,jdbcType=VARCHAR},'%'))
                </if>
                <if test="perResultModel.action_name != null and perResultModel.action_name != ''">and p1.action_name like concat('%',concat(#{perResultModel.action_name,jdbcType=VARCHAR},'%'))
                </if>
                <if test="perResultModel.app_version != null and perResultModel.app_version != ''">and p1.app_version like concat('%',concat(#{perResultModel.app_version,jdbcType=VARCHAR},'%'))
                </if>
             </where>) t 
         where t.rn &lt;= #{rows,jdbcType=NUMERIC}
               and t.rn &gt;#{start,jdbcType=NUMERIC}
         order by result_id desc
        </select>
        <select id="queryOnlineResultCount"resultType="java.lang.Integer" >select count(*)
             from (select * from pts.pts_online_result p order by p.result_id desc) p1
             <where>
                <if test="perResultModel.app_name != null and perResultModel.app_name != ''">and p1.app_name like concat('%',concat(#{perResultModel.app_name,jdbcType=VARCHAR},'%'))
                </if> 
                <if test="perResultModel.scenario_type != null and perResultModel.scenario_type != ''">and p1.scenario_type like concat('%',concat(#{perResultModel.scenario_type,jdbcType=VARCHAR},'%'))
                </if>        
                 <if test="perResultModel.app_trade != null and perResultModel.app_trade != ''">and p1.app_trade like concat('%',concat(#{perResultModel.app_trade,jdbcType=VARCHAR},'%'))
                </if>
                <if test="perResultModel.online_tester != null and perResultModel.online_tester != ''">and p1.online_tester like concat('%',concat(#{perResultModel.online_tester,jdbcType=VARCHAR},'%'))
                </if>
                <if test="perResultModel.action_name != null and perResultModel.action_name != ''">and p1.action_name like concat('%',concat(#{perResultModel.action_name,jdbcType=VARCHAR},'%'))
                </if>
                <if test="perResultModel.app_version != null and perResultModel.app_version != ''">and p1.app_version like concat('%',concat(#{perResultModel.app_version,jdbcType=VARCHAR},'%'))
                </if>
             </where> 
        </select>
        <select id="queryOnlineResultDetail"resultType="com.pts.model.PerformanceOnlineResultModel">select * from pts.pts_online_result p 
                where p.result_id=#{result_id,jdbcType=NUMERIC}
        </select>
        <delete id="delOneOnlineResult">delete from pts.pts_online_result p 
                where p.result_id=#{result_id,jdbcType=NUMERIC}            
        </delete>
        <update id="editOnlineResultDetail">update pts.pts_online_result p 
                set P.APP_NAME=#{porModel.app_name,jdbcType=VARCHAR}
                    ,P.APP_TRADE=#{porModel.app_trade,jdbcType=VARCHAR}
                    ,P.ACTION_NAME=#{porModel.action_name,jdbcType=VARCHAR}
                    ,P.CON_USER=#{porModel.con_user,jdbcType=VARCHAR}
                    ,P.PRESS_TIME=#{porModel.press_time,jdbcType=VARCHAR}
                    ,P.AVG_TIME=#{porModel.avg_time,jdbcType=VARCHAR}
                    ,P.TPS=#{porModel.tps,jdbcType=VARCHAR}
                    ,P.SUCC_ACTION=#{porModel.succ_action,jdbcType=VARCHAR}
                    ,P.FAIL_ACTION=#{porModel.fail_action,jdbcType=VARCHAR}
                    ,P.SUCC_RATE=#{porModel.succ_rate,jdbcType=VARCHAR}
                    ,P.APP_CPU_UTIL=#{porModel.app_cpu_util,jdbcType=VARCHAR}
                    ,P.DB_CPU_UTIL=#{porModel.db_cpu_util,jdbcType=VARCHAR}
                    ,P.SCENARIO_TYPE=#{porModel.scenario_type,jdbcType=VARCHAR}
                    ,P.APP_VERSION=#{porModel.app_version,jdbcType=VARCHAR}
                    ,P.ONLINE_TESTER=#{porModel.online_tester,jdbcType=VARCHAR}
                    ,P.ONLINE_DEVELOPER=#{porModel.online_developer,jdbcType=VARCHAR}
                    ,P.REMARK=#{porModel.remark,jdbcType=VARCHAR}
                    ,P.UPDATE_TIME=sysdate
                where p.result_id=#{result_id,jdbcType=NUMERIC}
        </update>
        <select id="queryBatchResultList"resultType="com.pts.model.PerformanceBatchResultModel">select 
                t.BATCH_RESULT_ID
                ,t.BATCH_APP_NAME
                ,t.BATCH_APP_TRADE
                ,t.PERPARE_DATA
                ,t.TOTAL_COST
                ,t.SUCC_RECORD
                ,t.FAIL_RECORD
                ,t.SUCC_RATE
                ,t.BATCH_APP_CPU_UTIL
                ,t.BATCH_DB_CPU_UTIL
                ,t.SCENARIO_TYPE
                ,t.BATCH_APP_VERSION
                ,t.BATCH_TESTER
                ,t.BATCH_DEVELOPER
                ,t.REMARK
                ,to_char(t.CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss')
                  ,to_char(t.UPDATE_TIME, 'yyyy-mm-dd hh24:mi:ss')
             from ( 
                select rownum rn , p1.*from 
                (select * from pts.pts_batch_result p order by p.batch_result_id desc) p1
                 <where>
                    <if test="perResultModel.batch_app_name != null and perResultModel.batch_app_name != ''">and p1.batch_app_name like concat('%',concat(#{perResultModel.batch_app_name,jdbcType=VARCHAR},'%'))
                    </if>             
                     <if test="perResultModel.batch_app_trade != null and perResultModel.batch_app_trade != ''">and p1.batch_app_trade like concat('%',concat(#{perResultModel.batch_app_trade,jdbcType=VARCHAR},'%'))
                    </if>
                    <if test="perResultModel.batch_tester != null and perResultModel.batch_tester != ''">and p1.batch_batch_tester like concat('%',concat(#{perResultModel.batch_batch_tester,jdbcType=VARCHAR},'%'))
                    </if>
                    <if test="perResultModel.batch_app_version != null and perResultModel.batch_app_version != ''">and p1.batch_app_version like concat('%',concat(#{perResultModel.batch_app_version,jdbcType=VARCHAR},'%'))
                    </if>
                 </where>) t
            where t.rn &lt;=#{rows,jdbcType=NUMERIC}
                  and t.rn &gt;#{start,jdbcType=NUMERIC}
            order by batch_result_id desc
        </select>
        <select id="queryBatchResultCount"resultType="java.lang.Integer" >select count(*)
             from (select * from pts.pts_batch_result p order by p.batch_result_id desc) p1
             <where>
                    <if test="perResultModel.batch_app_name != null and perResultModel.batch_app_name != ''">and p1.batch_app_name like concat('%',concat(#{perResultModel.batch_app_name,jdbcType=VARCHAR},'%'))
                    </if>             
                     <if test="perResultModel.batch_app_trade != null and perResultModel.batch_app_trade != ''">and p1.batch_app_trade like concat('%',concat(#{perResultModel.batch_app_trade,jdbcType=VARCHAR},'%'))
                    </if>
                    <if test="perResultModel.batch_tester != null and perResultModel.batch_tester != ''">and p1.batch_tester like concat('%',concat(#{perResultModel.batch_tester,jdbcType=VARCHAR},'%'))
                    </if>
                    <if test="perResultModel.batch_app_version != null and perResultModel.batch_app_version != ''">and p1.batch_app_version like concat('%',concat(#{perResultModel.batch_app_version,jdbcType=VARCHAR},'%'))
                    </if>
                 </where>
        </select>
        <select id="queryBatchResultDetail"resultType="com.pts.model.PerformanceBatchResultModel">select * from pts.pts_batch_result p 
                where p.batch_result_id=#{batch_result_id,jdbcType=NUMERIC}
        </select>
        <delete id="delOneBatchResult">delete from pts.pts_batch_result p 
                where p.batch_result_id=#{batch_result_id,jdbcType=NUMERIC}            
        </delete>
        <update id="editBatchResultDetail">update pts.pts_batch_result p 
                set p.BATCH_APP_NAME=#{pbrModel.batch_app_name,jdbcType=VARCHAR}
                    ,p.BATCH_APP_TRADE=#{pbrModel.batch_app_trade,jdbcType=VARCHAR}
                    ,p.PERPARE_DATA=#{pbrModel.perpare_data,jdbcType=VARCHAR}
                    ,p.TOTAL_COST=#{pbrModel.total_cost,jdbcType=VARCHAR}
                    ,p.SUCC_RECORD=#{pbrModel.succ_record,jdbcType=VARCHAR}
                    ,p.FAIL_RECORD=#{pbrModel.fail_record,jdbcType=VARCHAR}
                    ,p.SUCC_RATE=#{pbrModel.succ_rate,jdbcType=VARCHAR}
                    ,p.BATCH_APP_CPU_UTIL=#{pbrModel.batch_app_cpu_util,jdbcType=VARCHAR}
                    ,p.BATCH_DB_CPU_UTIL=#{pbrModel.batch_db_cpu_util,jdbcType=VARCHAR}
                    ,p.SCENARIO_TYPE=#{pbrModel.scenario_type,jdbcType=VARCHAR}
                    ,p.BATCH_APP_VERSION=#{pbrModel.batch_app_version,jdbcType=VARCHAR}
                    ,p.BATCH_TESTER=#{pbrModel.batch_tester,jdbcType=VARCHAR}
                    ,p.BATCH_DEVELOPER=#{pbrModel.batch_developer,jdbcType=VARCHAR}
                    ,p.REMARK=#{pbrModel.remark,jdbcType=VARCHAR}
                    ,p.UPDATE_TIME=sysdate 
                where p.batch_result_id=#{batch_result_id,jdbcType=NUMERIC}
        </update>
</mapper>

免责声明:文章转载自《mybatis 批量插入和where条件使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇MyBatis直接执行SQL查询及批量插入数据EF Core 难道不支持GroupBy吗?下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

使用HQL查询

  HQL是Hibernate Query Language的缩写,语法很想SQL,但是HQL是一种面向对象的查询语言。SQL的操作对象是数据列、表等数据库对象,而HQL操作的是类、实例、属性。   HQL查询依赖于Query类,每个Query实例对应一个查询对象,使用HQL查询按如下步骤进行:   1.获取Hibernate Session对象   2....

oracle之数据限定与排序

数据限定与排序6.1 简单查询语句执行顺序from, where, group by, having, order by, selectwhere限定from后面的表或视图,限定的选项只能是表的列或列单行函数或列表达式,where后不可以直接使用分组函数SQL> select empno,job from emp where sal>2000;...

springboot-easycode配置文件修改

网上抄的然后不能够使用,自己又改了该就可以了entity ##引入宏定义 $!define ##使用宏定义设置回调(保存位置与文件后缀) #save("/entity", ".java") ##使用宏定义设置包后缀 #setPackageSuffix("entity") ##使用全局变量实现默认包导入 $!autoImport import lo...

HiveSQL——row_number() over() 使用

语法格式:row_number() over(partition by 分组列 order by排序列 desc) row_number() over()分组排序功能: 在使用 row_number() over()函数时候,over()里头的分组以及排序的执行晚于 where 、group by、 order by 的执行。 例一: 表数据: creat...

Mock

一、Mock 1.1 什么是 Mock mock 是在测试过程中,对于一些不容易构造/获取的对象,创建一个 mock 对象来模拟对象的行为。 1.2 什么时候使用 * 单元测试时,使用外部资源或第三方库代码 * 并行开发时,另一方还没有开发完毕 1.3 Mock 分类 Mock 对象 主要适用于单元测试,写入一些预期的值,通过它进行自己想要的测...

SQL Server 通过“with as”方法查询树型结构

一、with as 公用表表达式   类似VIEW,但是不并没有创建对象,WITH  AS 公用表表达式不创建对象,只能被后随的SELECT语句,其作用:   1. 实现递归查询(树形结构)   2. 可以在一个语句中多次引用公用表表达式,使其更加简洁 二、非递归的公共表达式   可以是定义列或自动列和select into 效果差不多 --指定列 wi...