mybatis 注解写法 多层嵌套foreach,调用存储过程,批量插入数据

Posted sbk613

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis 注解写法 多层嵌套foreach,调用存储过程,批量插入数据相关的知识,希望对你有一定的参考价值。

 1    @Select("<script>" +
 2   "DECLARE @edi_Invoice_Details edi_Invoice_Details;" +
 3   "DECLARE @edi_Invoice_OrderItem edi_Invoice_OrderItem;" +
 4 
 5   "INSERT INTO @edi_Invoice_Details (" +
 6    "oldso,so,po,invoiceTaxNo,invoiceType,invoiceTitle,\n" +
 7    "invoiceAddress,invoiceState,invoiceTaxRate,invoiceContent,\n" +
 8    "invoiceRatePrice,invoiceNoTaxPrice,invoiceId,invoiceDate,invoiceTaxPrice,invoiceNO,invoiceCode" +
 9    " ) " +
10    "VALUES " +
11    "<foreach collection=\"ediInvoiceDetails\" item=\"ediInvoiceDetail\" index=\"index\" separator=\",\" close=\";\">" +
12    "( " +
13      "#{ediInvoiceDetail.oldso},#{ediInvoiceDetail.so},#{ediInvoiceDetail.po},#{ediInvoiceDetail.invoiceTaxNo},#{ediInvoiceDetail.invoiceType},#{ediInvoiceDetail.invoiceTitle}," +
14      "#{ediInvoiceDetail.invoiceAddress},#{ediInvoiceDetail.invoiceState},#{ediInvoiceDetail.invoiceTaxRate},#{ediInvoiceDetail.invoiceContent},#{ediInvoiceDetail.invoiceRatePrice}," +
15      "#{ediInvoiceDetail.invoiceNoTaxPrice},#{ediInvoiceDetail.invoiceId},CONVERT(DATETIME,#{ediInvoiceDetail.invoiceDate},105),#{ediInvoiceDetail.invoiceTaxPrice},"+
16      "#{ediInvoiceDetail.invoiceNO},#{ediInvoiceDetail.invoiceCode}"+
17     " )" +
18      "</foreach> " +
19      "<foreach collection=\"ediInvoiceDetails\" item=\"ediInvoiceDetail\" index=\"index\" open=\"begin\" close=\";end;\" separator=\";\">" +
20      "INSERT INTO @edi_Invoice_OrderItem ( " +
21      "invoiceDetailsId, so, bomCode, agreementPrice,productAmount, productName " +
22      ") " +
23      "VALUES " +
24 
25      "<foreach collection=\"ediInvoiceDetail.sodetails\" item=\"sodetail\" index=\"index\" separator=\",\">( " +
26       "#{sodetail.invoiceDetailsId},#{sodetail.so},#{sodetail.bomCode},#{sodetail.agreementPrice},#{sodetail.productAmount},#{sodetail.productName} "+
27       " )</foreach></foreach> " +
28 
29      "EXEC up_EDI_Sync_SaveEDIInvoiceDetails @edi_Invoice_Details,@edi_Invoice_OrderItem"+
30     "</script>")
31     @Options(statementType = StatementType.CALLABLE)
32     void saveEdiInvoiceDetails(@Param("ediInvoiceDetails") List<EDIInvoiceDetails> ediInvoiceDetails);

 

以上是关于mybatis 注解写法 多层嵌套foreach,调用存储过程,批量插入数据的主要内容,如果未能解决你的问题,请参考以下文章

springboot mybatis注解方式批量insert和使用in语句查询

Mybatis的嵌套关联查询案例实战

MyBatis-Plus条件构造器 多个组合OR嵌套拼接写法

Mybatis通过注解实现映射中的嵌套语句和嵌套结果

MyBatis-Plus条件构造器 多个组合OR嵌套拼接写法

Python requests.post嵌套多层json参数调用接口