mybatis使用

这篇博客介绍了MyBatis中进行批量插入数据的两种方法,包括简单的INSERT语句和使用BEGIN-END包裹的存储过程调用。同时展示了如何在插入时根据字段值进行条件判断,并给出了调用存储过程的示例,该过程接收输入参数并返回结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


mybatis批量插入
1.  INSERT INTO test (a, b, c) VALUES
<foreach collection="list" item="item" separator=",">
    (#{item.a}, #{item.b}, #{item.c})
</foreach>

 

2. <select id="insertBatchBillWechat" parameterType="List">
    
        BEGIN
        <foreach collection ="list" item="billWechat" index="index" separator =";">
            INSERT INTO t_bill_wechat
                    (lsh,jysj ,appid ,mchid , sonmchid,wechatorder ,shddh, userid,jylx , jystatus,fkryh ,hbzl ,zje ,qyhbje,wechattkorder ,shtkorder ,tkje ,qyhbtkje ,tklx ,tkzt ,shmc , sxf,fl ,xzqhdm ,jktzsbh ,zsdwbm ,tzslx,bankid,pay_code )
            VALUES
             (T_BILL_WECHAT_SEQ.Nextval,#{billWechat.jysj} ,#{billWechat.appid} ,#{billWechat.mchid} , #{billWechat.sonmchid},#{billWechat.wechatorder} , #{billWechat.shddh}, #{billWechat.userid},#{billWechat.jylx} , #{billWechat.jystatus},#{billWechat.fkryh} ,#{billWechat.hbzl} ,#{billWechat.zje},#{billWechat.qyhbje} ,#{billWechat.wechattkorder} ,#{billWechat.shtkorder} ,#{billWechat.tkje} ,#{billWechat.qyhbtkje} ,#{billWechat.tklx} ,#{billWechat.tkzt} ,#{billWechat.shmc} , #{billWechat.sxf},#{billWechat.fl} ,#{billWechat.xzqhdm} ,#{billWechat.jktzsbh} ,#{billWechat.zsdwbm} ,#{billWechat.tzslx},#{billWechat.bankid} ,#{billWechat.pay_code})
        </foreach >
        ;END ;
    </select>

 

inser各字段判断

<insert id="addConfigMerid" parameterType="com.hisun.fspay.domain.TConfigMerid">
      insert into t_config_merid
      <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="czqhnm != null">
                    CZQHNM,
                </if>
     </trim>
      <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="czqhnm != null">
                    #{czqhnm,jdbcType=VARCHAR},
                </if>
     </trim>
  </insert>

调用包中过程
 <select id="checkSffs" parameterType="com.vision.czzh.modules.base.entity.ZwJcsjEntity" resultType="java.lang.Object" statementType="CALLABLE">
   <![CDATA[  
    {
        call pkg_acc_checkfs.test(
    #{kmdm,mode=IN,jdbcType=VARCHAR},
    #{out_result,mode=OUT,jdbcType=VARCHAR,javaType=String})
    }
      ]]>
    </select>

 

like '${timestart}%'
= #{timestart}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值