欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mybatis动态插入list传入List参数的实例代码

程序员文章站 2023-11-24 09:31:34
mybatis动态插入list的实例代码如下所述:

mybatis动态插入list的实例代码如下所述:

<insert id="saveprpcitemkindlist" parametertype="java.util.list">
insert into prpcitemkind
(riskcode, itemkindno, familyno, familyname, projectcode, clausecode,
clausename,
kindcode, kindname, itemno, itemcode, itemdetailname, groupno, modecode,
modename, startdate,
starthour, enddate, endhour, model, buydate, addressno, calculateflag, currency,
unitamount,
quantity, unit, value, amount, rateperiod, rate, shortrateflag, shortrate,
prepremium, calpremium,
basepremium, benchmarkpremium, discount, adjustrate, unitpremium, premium,
deductiblerate, deductible,
flag, inserttimeforhis, operatetimeforhis, taxrate, taxflag, taxfee,
netpremium, taxfee_gb, taxfee_lb, alltaxfee, allnetpremium,proposalno)
<foreach collection="list" item="item" index="index" separator="union all">
<trim prefix="select" suffix="from dual">
<choose>
<when test="item.riskcode != null">#{item.riskcode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.itemkindno != null">#{item.itemkindno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.familyno != null">#{item.familyno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.familyname != null">#{item.familyname},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.projectcode != null">#{item.projectcode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.clausecode != null">#{item.clausecode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.clausename != null">#{item.clausename},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.kindcode != null">#{item.kindcode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.kindname != null">#{item.kindname},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.itemno != null">#{item.itemno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.itemcode != null">#{item.itemcode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.itemdetailname != null">#{item.itemdetailname},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.groupno != null">#{item.groupno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.modecode != null">#{item.modecode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.modename != null">#{item.modename},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.startdate != null">#{item.startdate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.starthour != null">#{item.starthour},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.enddate != null">#{item.enddate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.endhour != null">#{item.endhour},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.model != null">#{item.model},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.buydate != null">#{item.buydate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.addressno != null">#{item.addressno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.calculateflag != null">#{item.calculateflag},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.currency != null">#{item.currency},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.unitamount != null">#{item.unitamount},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.quantity != null">#{item.quantity},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.unit != null">#{item.unit},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.value != null">#{item.value},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.amount != null">#{item.amount},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.rateperiod != null">#{item.rateperiod},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.rate != null">#{item.rate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.shortrateflag != null">#{item.shortrateflag},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.shortrate != null">#{item.shortrate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.prepremium != null">#{item.prepremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.calpremium != null">#{item.calpremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.basepremium != null">#{item.basepremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.benchmarkpremium != null">#{item.benchmarkpremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.discount != null">#{item.discount},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.adjustrate != null">#{item.adjustrate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.unitpremium != null">#{item.unitpremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.premium != null">#{item.premium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.deductiblerate != null">#{item.deductiblerate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.deductible != null">#{item.deductible},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.flag != null">#{item.flag},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.inserttimeforhis != null">#{item.inserttimeforhis},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.operatetimeforhis != null">#{item.operatetimeforhis},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxrate != null">#{item.taxrate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxflag != null">#{item.taxflag},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxfee != null">#{item.taxfee},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.netpremium != null">#{item.netpremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxfee_gb != null">#{item.taxfee_gb},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxfee_lb != null">#{item.taxfee_lb},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.alltaxfee != null">#{item.alltaxfee},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.allnetpremium != null">#{item.allnetpremium},</when>
<otherwise>null,</otherwise>
</choose>
#{item.proposalno}
</trim>
</foreach> 
 </insert>

mybatis 传入list参数的实例代码如下所述:

java代码

//dao 代码 如果传入的参数是数组,也一样 
void insertdefaultmsg(@param("idslist") arraylist<string> idslist); 
//xml文件 
<update id="insertdefaultmsg" parametertype="java.util.list"> 
    update  
     plf_pur_delivery_plan p  
    set 
     p.promise_delivery_amount = p.quantity_req, 
     p.promise_delivery_time = p.quantity_time  
    where p.id in 
    <foreach item="item" collection="idslist" separator="," open="(" close=")" index="">  
     #{item, jdbctype=varchar}  
    </foreach>  
  </update> 
//如果传入字符串 
//service 代码 
map<string, string> map = bean.getdatas().get(0); 
    string ids = map.get("ids"); 
    string[] idsarr = ids.split(","); 
    string inid = ""; 
    for (int i = 0; i < idsarr.length; i++) { 
      if (i != idsarr.length - 1) { 
        inid += "'" + idsarr[i] + "',"; 
      } else { 
        inid += "'" + idsarr[i] + "'"; 
      } 
    } 
    list<map<string, string>> list = purdeliveryplandao 
        .getplanlistmanual(inid); 
//dao层代码 
list<map<string, string>> getplanlistmanual(@param("inid") string inid); 
//xml 文件 
<select id="getplanlistmanual" parametertype="java.lang.string" resulttype="java.util.map"> 
    select  
     p.supplier_code, 
     p.pur_order_no, 
     if( 
      p.update_times > 0, 
      '修改订单', 
      '新订单' 
     ) as order_type  
    from 
     plf_pur_delivery_plan p  
    where p.is_notice = '0'  
     and p.is_delete = '1'  
     and p.id in(<![cdata[${inid}]]>) 
    group by p.supplier_code, 
     p.pur_order_no  
    order by p.supplier_code  
  </select> 

总结

以上所述是小编给大家介绍的mybatis动态插入list传入list参数的实例代码,希望对大家有所帮助