当前位置: 首页 > 编程笔记 >

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

林铭
2023-03-14
本文向大家介绍mybatis动态插入list传入List参数的实例代码,包括了mybatis动态插入list传入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参数的实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

 类似资料:
  • 本文向大家介绍MyBatis传入参数的实例代码,包括了MyBatis传入参数的实例代码的使用技巧和注意事项,需要的朋友参考一下 在MyBatis的select、insert、update、delete这些元素中都提到了parameterType这个属性。MyBatis现在可以使用的parameterType有基本数据类型和JAVA复杂数据类型 基本数据类型:包含int,String,Date等。基

  • 本文向大家介绍Mybatis 传输List的实现代码,包括了Mybatis 传输List的实现代码的使用技巧和注意事项,需要的朋友参考一下 1. 当查询的参数只有一个时  1.1 如果参数的类型是List, 则在使用时,collection属性要必须指定为 list Xml代码  1.2 如果参数的类型是Array,则在使用时,collection属性要必须指定为 array Xml代码 2. 当

  • 本文向大家介绍Mybatis如何传入多个参数的实现代码,包括了Mybatis如何传入多个参数的实现代码的使用技巧和注意事项,需要的朋友参考一下 第一种方式:使用@Param注解方式 此种方式用法是我们在接口中写方法的参数时,在每个参数的前面加上一个@Param注解即可。 该注解有一个value属性,我们可以给加上注解的参数取个名字,在SQL语句中我们可以通过这个名字获取参数值。 由于传入了多个参数

  • 描述 (Description) 通过向list-block添加inset类, list-block块可以具有inset样式。 例子 (Example) 下面的示例演示了使用inset即使在Framework7列表视图中使列表块不是全宽样式 - <!DOCTYPE html> <html> <head> <meta name = "viewport" content = "wid

  • 问题内容: 我正在用C#编写一种从WCF服务查询SQL Server Express数据库的方法。我必须使用ADO.NET来做到这一点(然后稍后用LINQ重写它)。 该方法采用两个字符串(),然后从匹配记录中返回“ Health Insurance NO” (健康保险否)属性。我想将其读入列表(还有一些其他属性也可以检索)。 当前代码返回一个空列表。我要去哪里错了? 问题答案: 您正在尝试加载经>

  • 本文向大家介绍Mybatis的入门示例代码,包括了Mybatis的入门示例代码的使用技巧和注意事项,需要的朋友参考一下 首先新建一个JavaWeb项目并导入mybatis依赖的jar包,同时Mybatis是对数据库的操作所以我们需要在数据库中新建一个表user用来演示。 新建完表之后我们还需要建立相对应的实体类User.java并添加set和get方法: 在Mybatis中我们需要建立一个与实体类