mybatis动态插入list传入List参数的实例代码
发布时间:2020-12-14 19:50:00 所属栏目:Java 来源:网络整理
导读:mybatis动态插入list的实例代码如下所述: insert id="savePrpcitemkindList" parameterType="java.util.List"insert into prpcitemkind(RISKCODE,ITEMKINDNO,FAMILYNO,FAMILYNAME,PROJECTCODE,CLAUSECODE,CLAUSENAME,KINDCODE,KINDNAME,ITEMNO,ITEMCODE,ITE
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},</otherwise> </choose> <choose> <when test="item.familyno != null">#{item.familyno},</otherwise> </choose> <choose> <when test="item.familyname != null">#{item.familyname},</otherwise> </choose> <choose> <when test="item.projectcode != null">#{item.projectcode},</otherwise> </choose> <choose> <when test="item.clausecode != null">#{item.clausecode},</otherwise> </choose> <choose> <when test="item.clausename != null">#{item.clausename},</otherwise> </choose> <choose> <when test="item.kindcode != null">#{item.kindcode},</otherwise> </choose> <choose> <when test="item.kindname != null">#{item.kindname},</otherwise> </choose> <choose> <when test="item.itemno != null">#{item.itemno},</otherwise> </choose> <choose> <when test="item.itemcode != null">#{item.itemcode},</otherwise> </choose> <choose> <when test="item.itemdetailname != null">#{item.itemdetailname},</otherwise> </choose> <choose> <when test="item.groupno != null">#{item.groupno},</otherwise> </choose> <choose> <when test="item.modecode != null">#{item.modecode},</otherwise> </choose> <choose> <when test="item.modename != null">#{item.modename},</otherwise> </choose> <choose> <when test="item.startdate != null">#{item.startdate},</otherwise> </choose> <choose> <when test="item.starthour != null">#{item.starthour},</otherwise> </choose> <choose> <when test="item.enddate != null">#{item.enddate},</otherwise> </choose> <choose> <when test="item.endhour != null">#{item.endhour},</otherwise> </choose> <choose> <when test="item.model != null">#{item.model},</otherwise> </choose> <choose> <when test="item.buydate != null">#{item.buydate},</otherwise> </choose> <choose> <when test="item.addressno != null">#{item.addressno},</otherwise> </choose> <choose> <when test="item.calculateflag != null">#{item.calculateflag},</otherwise> </choose> <choose> <when test="item.currency != null">#{item.currency},</otherwise> </choose> <choose> <when test="item.unitamount != null">#{item.unitamount},</otherwise> </choose> <choose> <when test="item.quantity != null">#{item.quantity},</otherwise> </choose> <choose> <when test="item.unit != null">#{item.unit},</otherwise> </choose> <choose> <when test="item.value != null">#{item.value},</otherwise> </choose> <choose> <when test="item.amount != null">#{item.amount},</otherwise> </choose> <choose> <when test="item.rateperiod != null">#{item.rateperiod},</otherwise> </choose> <choose> <when test="item.rate != null">#{item.rate},</otherwise> </choose> <choose> <when test="item.shortrateflag != null">#{item.shortrateflag},</otherwise> </choose> <choose> <when test="item.shortrate != null">#{item.shortrate},</otherwise> </choose> <choose> <when test="item.prepremium != null">#{item.prepremium},</otherwise> </choose> <choose> <when test="item.calpremium != null">#{item.calpremium},</otherwise> </choose> <choose> <when test="item.basepremium != null">#{item.basepremium},</otherwise> </choose> <choose> <when test="item.benchmarkpremium != null">#{item.benchmarkpremium},</otherwise> </choose> <choose> <when test="item.discount != null">#{item.discount},</otherwise> </choose> <choose> <when test="item.adjustrate != null">#{item.adjustrate},</otherwise> </choose> <choose> <when test="item.unitpremium != null">#{item.unitpremium},</otherwise> </choose> <choose> <when test="item.premium != null">#{item.premium},</otherwise> </choose> <choose> <when test="item.deductiblerate != null">#{item.deductiblerate},</otherwise> </choose> <choose> <when test="item.deductible != null">#{item.deductible},</otherwise> </choose> <choose> <when test="item.flag != null">#{item.flag},</otherwise> </choose> <choose> <when test="item.inserttimeforhis != null">#{item.inserttimeforhis},</otherwise> </choose> <choose> <when test="item.operatetimeforhis != null">#{item.operatetimeforhis},</otherwise> </choose> <choose> <when test="item.taxrate != null">#{item.taxrate},</otherwise> </choose> <choose> <when test="item.taxflag != null">#{item.taxflag},</otherwise> </choose> <choose> <when test="item.taxfee != null">#{item.taxfee},</otherwise> </choose> <choose> <when test="item.netpremium != null">#{item.netpremium},</otherwise> </choose> <choose> <when test="item.taxfee_gb != null">#{item.taxfee_gb},</otherwise> </choose> <choose> <when test="item.taxfee_lb != null">#{item.taxfee_lb},</otherwise> </choose> <choose> <when test="item.alltaxfee != null">#{item.alltaxfee},</otherwise> </choose> <choose> <when test="item.allnetpremium != null">#{item.allnetpremium},</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参数的实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的! 您可能感兴趣的文章:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |