mybatis batchinsert

时间:2022-09-23 23:25:18

<?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.xinwei.order.dao.OrderAlarmTblMapper" >
  <resultMap id="BaseResultMap" type="com.xinwei.order.entity.OrderAlarmTbl" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="alarm_id" property="alarmId" jdbcType="VARCHAR" />
    <result column="data_id" property="dataId" jdbcType="VARCHAR" />
    <result column="device_name" property="deviceName" jdbcType="VARCHAR" />
    <result column="device_id" property="deviceId" jdbcType="VARCHAR" />
    <result column="alarm_topic" property="alarmTopic" jdbcType="VARCHAR" />
    <result column="level" property="level" jdbcType="VARCHAR" />
    <result column="order_status" property="orderStatus" jdbcType="VARCHAR" />
    <result column="cost_time" property="costTime" jdbcType="VARCHAR" />
    <result column="proc_inst_id" property="procInstId" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
     <result column="alarm_type" property="alarmType" jdbcType="VARCHAR" />
    <result column="alarm_location" property="alarmLocation" jdbcType="VARCHAR" />
    <result column="ext" property="ext" jdbcType="VARCHAR" />
    <result column="suspend_reason" property="suspendReason" jdbcType="VARCHAR" />
  </resultMap>
 
      <delete id="deleteById" parameterType="java.lang.Long" >
        delete from order_alarm_tbl
        where id = #{id,jdbcType=BIGINT}
      </delete>
      
        <delete id="deleteAll">
        delete from order_alarm_tbl
      </delete>
      
        <delete id="deleteByAlarmId" parameterType="java.lang.String" >
        delete from order_alarm_tbl
        where alarm_id = #{alarmId,jdbcType=VARCHAR}
      </delete>
 
      <insert id="insert" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
        insert into order_alarm_tbl (id, alarm_id, data_id,
          device_name, device_id, alarm_topic, alarm_type, alarm_location,
          level, order_status, cost_time,
          proc_inst_id, create_time, ext,suspend_reason
          )
        values (#{id,jdbcType=BIGINT}, #{alarmId,jdbcType=VARCHAR}, #{dataId,jdbcType=VARCHAR},
          #{deviceName,jdbcType=VARCHAR}, #{deviceId,jdbcType=VARCHAR}, #{alarmTopic,jdbcType=VARCHAR},
          #{alarmType,jdbcType=VARCHAR}, #{alarmLocation,jdbcType=VARCHAR},  
          #{level,jdbcType=VARCHAR}, #{orderStatus,jdbcType=VARCHAR}, #{costTime,jdbcType=VARCHAR},
          #{procInstId,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{ext,jdbcType=VARCHAR}, #{suspendReason,jdbcType=VARCHAR}
          )
      </insert>
 
     <insert id="insertByBatch" parameterType="java.util.List">
        insert into order_alarm_tbl (id,alarm_id, data_id,
      device_name, device_id, alarm_topic, alarm_type, alarm_location,
      level, order_status, cost_time,
      proc_inst_id, create_time, ext,suspend_reason
      )
        values
        <foreach collection="list" item="item" index="index" separator=",">
         ( #{item.id,jdbcType=BIGINT},#{item.alarmId,jdbcType=VARCHAR}, #{item.dataId,jdbcType=VARCHAR},
      #{item.deviceName,jdbcType=VARCHAR}, #{item.deviceId,jdbcType=VARCHAR}, #{item.alarmTopic,jdbcType=VARCHAR},
      #{item.alarmType,jdbcType=VARCHAR}, #{item.alarmLocation,jdbcType=VARCHAR},  
      #{item.level,jdbcType=VARCHAR}, #{item.orderStatus,jdbcType=VARCHAR}, #{item.costTime,jdbcType=VARCHAR},
      #{item.procInstId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.ext,jdbcType=VARCHAR}, #{item.suspendReason,jdbcType=VARCHAR}
      )
        </foreach>
    </insert>
 
  <update id="updateByPrimaryKey" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
    update order_alarm_tbl
    set alarm_id = #{alarmId,jdbcType=VARCHAR},
    data_id = #{dataId,jdbcType=VARCHAR},
    device_name = #{deviceName,jdbcType=VARCHAR},
    device_id = #{deviceId,jdbcType=VARCHAR},
    alarm_topic = #{alarmTopic,jdbcType=VARCHAR},
    alarm_type = #{alarmType,jdbcType=VARCHAR},
    alarm_location = #{alarmLocation,jdbcType=VARCHAR},
    level = #{level,jdbcType=VARCHAR},
    order_status = #{orderStatus,jdbcType=VARCHAR},
    cost_time = #{costTime,jdbcType=VARCHAR},
    proc_inst_id = #{procInstId,jdbcType=VARCHAR},
    create_time = #{createTime,jdbcType=TIMESTAMP},
    ext = #{ext,jdbcType=VARCHAR},
    suspend_reason = #{suspendReason,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
 
    <update id="updateOrderStatusByDataId" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
    update order_alarm_tbl
    set order_status = #{orderStatus,jdbcType=VARCHAR}
    where data_id = #{dataId,jdbcType=VARCHAR}
  </update>
 
   <update id="updateSuspendReasonByDataId" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
    update order_alarm_tbl
    set suspend_reason = #{suspendReason,jdbcType=VARCHAR}
    where data_id = #{dataId,jdbcType=VARCHAR}
  </update>
 
   <update id="updateSuspendReasonByProcessInstId" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
    update order_alarm_tbl
    set suspend_reason = #{suspendReason,jdbcType=VARCHAR}
    where proc_inst_id = #{procInstId,jdbcType=VARCHAR}
  </update>
 
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    where id = #{id,jdbcType=BIGINT}
  </select>
 
    <select id="getByDataId" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    where data_id = #{dataId,jdbcType=VARCHAR}
  </select>
 
    <select id="getByAlarmId" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    where alarm_id = #{alarmId,jdbcType=VARCHAR}
  </select>
 
   <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    where id = #{id,jdbcType=BIGINT}
  </select>
 
  <select id="countMyApplyByCondition" resultType="java.lang.Long" >
    select count(1)
   from order_alarm_tbl
    where 1=1 <include refid="queryString" />
  </select>
 
   <select id="selectMyApplyByCondition" resultMap="BaseResultMap" >
 select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location,  level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryString" />
    limit #{startRow},#{pageSize}
  </select>

<select id="countAll" resultType="java.lang.Long" >
    SELECT COUNT(*)
    from order_alarm_tbl
   </select>

<select id="getAll" resultMap="BaseResultMap" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic, alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    limit #{startRow},#{pageSize}
  </select>
 
    <select id="selectAll" resultMap="BaseResultMap" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic, alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    order by create_time desc
  </select>
 
   <select id="selectAllAlarmType" resultType="java.lang.String" >
  SELECT DISTINCT alarm_type
    FROM order_alarm_tbl
  </select>
 
  <select id="getSuspendTask" resultMap="BaseResultMap" >
   SELECT * FROM order_alarm_tbl WHERE suspend_reason IS NOT null
    order by create_time desc
  </select>
 
  <select id="countByCondition" resultType="java.lang.Long" >
    SELECT COUNT(*)
      from order_alarm_tbl
      where 1=1
    <include refid="queryString" />
   </select>
   
    <select id="getByCondition" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location,  level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryString" />
    limit #{startRow},#{pageSize}
  </select>
 
     <select id="countExportByCondition" resultType="java.lang.Long" >
    SELECT COUNT(*)
      from order_alarm_tbl
      where 1=1
    <include refid="queryString" />
   </select>
 
    <select id="exportByCondition" resultMap="BaseResultMap" parameterType="java.lang.String" >
     select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryString" />
  </select>
 
    <select id="selectProcInstIdByCondition" resultType="java.lang.String" >
    select proc_inst_id
    from order_alarm_tbl
    where 1=1 <include refid="queryString" />
  </select>
 
    <select id="countTAToDoListByCondition" resultType="java.lang.Long" >
    SELECT COUNT(*)
      from order_alarm_tbl
      where 1=1
    <include refid="queryTAToDoListByCondition" />
   </select>
   
    <select id="getTAToDoListByCondition" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic, alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryTAToDoListByCondition" />
    limit #{startRow},#{pageSize}
  </select>
 
 
    <select id="getTAToDoListByConditionNoPage" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic, alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryTAToDoListByCondition" />
  </select>

<sql id="queryTAToDoListByCondition">
    
      <if test="alarmType != null and alarmType !=''">
     and alarm_type = #{alarmType,jdbcType=VARCHAR}
    </if>
    
      <if test="alarmLocation != null and alarmLocation !=''">
     and alarm_location = #{alarmLocation,jdbcType=VARCHAR}
    </if>
    
     <if test="level != null and level !=''">
     and level = #{level,jdbcType=VARCHAR}
    </if>
    
     <if test="alarmId != null and alarmId !=''">
     and alarm_id = #{alarmId,jdbcType=VARCHAR}
    </if>
    
    <if test="deviceId != null and deviceId !=''">
     and device_id = #{deviceId,jdbcType=VARCHAR}
    </if>
    
    <if test="alarmTopic != null and alarmTopic !=''">
     and alarm_topic LIKE '%${alarmTopic}%'
    </if>

</sql>
 
  <sql id="queryString">
     <if test="alarmId != null and alarmId !=''">
     and alarm_id = #{alarmId,jdbcType=VARCHAR}
    </if>
    
    <if test="deviceId != null and deviceId !=''">
     and device_id = #{deviceId,jdbcType=VARCHAR}
    </if>
    
    <if test="alarmTopic != null and alarmTopic !=''">
     and alarm_topic LIKE '%${alarmTopic}%'
    </if>
    
     <if test="startTime != null and endTime != null">
        and DATE_FORMAT(create_time,'%m-%d-%Y')
           between DATE_FORMAT(#{startTime,jdbcType=VARCHAR},'%m-%d-%Y')
           and DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%m-%d-%Y')
    </if>
 </sql>
</mapper>

mybatis batchinsert的更多相关文章

  1. MyBatis6:MyBatis集成Spring事物管理(下篇)

    前言 前一篇文章<MyBatis5:MyBatis集成Spring事物管理(上篇)>复习了MyBatis的基本使用以及使用Spring管理MyBatis的事物的做法,本文的目的是在这个的基 ...

  2. MyBatis&lowbar;ibatis和mybatis的区别【转】

    1. ibatis3.*版本以后正式改名为mybaits,它也从apache转到了google code下:也就是说ibatis2.*,mybatis3.*. 2. 映射文件的不同 ibatis的配置 ...

  3. 基于Oracle的Mybatis 批量插入

    项目中会遇到这样的情况,一次性要插入多条数据到数据库中,有两种插入方法: 方法一: Mybatis本身只支持逐条插入,比较笨的方法,就是遍历一个List,循环中逐条插入,比如下面这段代码 for(Da ...

  4. MyBatis6:MyBatis集成Spring事务管理(下篇)

    前言 前一篇文章<MyBatis5:MyBatis集成Spring事务管理(上篇)>复习了MyBatis的基本使用以及使用Spring管理MyBatis的事务的做法,本文的目的是在这个的基 ...

  5. MyBatis(6):MyBatis集成Spring事务管理(下)

    前一篇文章复习了MyBatis的基本使用以及使用Spring管理MyBatis的事务的做法,本文的目的是在这个的基础上稍微做一点点的进阶:多数据的事务处理.文章内容主要包含两方面: 1.单表多数据的事 ...

  6. mybatis批量update&lpar;mysql&rpar;

    Mapper文件中的写法 <insert id="batchUpdateTjData"> <foreach collection="list" ...

  7. MyBatis浅尝笔记

    MyBatis应属于一种轻量级的java持久层技术,它通过简单的SQL xml或注解,将数据库数据映射到接口与POJO.最近项目要用到mybatis,所以学习之后在这里做个总结,文中的示例以xml配置 ...

  8. mybatis 自动生成代码(mybatis generator)

    pom.xml 文件配置 引入 mybatis generator <properties> <mysql.connector.version>5.1.44</mysql ...

  9. mybatis mysql 批量插入

    场景描述: 使用mybatis操作mysql数据库,进行批量插入数据,提高代码质量和执行效率. 环境: mybatis spring mysql java xml配置文件 <insert id ...

随机推荐

  1. maven install 构建报错&lpar;2&rpar;

    错误:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin: 2.3 . 2 :compile ( default ...

  2. JSPatch学习笔记

    本文参考JSPatch wiki :https://github.com/bang590/JSPatch/wiki 1.概念 JSPatch是一个轻量的JS引擎,能够使用JavaScript语言来调用 ...

  3. Mac OS Storm+Kafka&plus;Zookeeper配置

    先补充一个前两天mac配置的文档. 首先确定由jdk scala环境 JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/Cu ...

  4. python中的引用

    作为一个python初学者,今天被一个python列表和词典引用的问题折磨了很久,但其实了解了缘由也很简单,记录在此备忘. 首先背书python中的引用对象问题: 1. python不允许程序员选择采 ...

  5. Create Custom Modal Dialog Windows For User Input In Oracle Forms

    An example is given below to how to create a modal dialog window in Oracle Forms for asking user inp ...

  6. hadoop 补充(转)

    1.输入文件: 文件是MapReduce任务的数据的初始存储地.正常情况下,输入文件一般是存在HDFS里.这些文件的格式可以是任意的:我们可以使用基于行的日志文件,也可以使用二进制格式,多行输入记录或 ...

  7. java中遍历map对象的多种方法

    在Java中如何遍历Map对象   How to Iterate Over a Map in Java 在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有ma ...

  8. 连接字符串中Min Pool Size的理解是错误,超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。

    Min Pool Size的理解是错误的 假设我们在一个ASP.NET应用程序的连接字符串中将Min Pool Size设置为30: <add name="cnblogs" ...

  9. java中对象的创建过程

    public class Test1 { public static void main(String[] args) { new B(); System.out.println("---- ...

  10. logging 日志

    1. 四步: import logging #初始化 logger = logging.getLogger("log_name") #设置级别 logger.setLevel(lo ...