" + "insert into zx_tendaysreport t\n" + " (REPORTID,PLACEPOINTID,USEDAY,GATHERTYPE,REALMONEY,BANCIMONEY,FINANCEMONEY,uploadflag,docno,STATUS)\n" + "selec_foreach u">
当前位置:   article > 正文

Mybatis批量foreach进行insert、update操作_foreach update

foreach update

insert的foreach

@DslDataSource(MASTER)
    @Insert("<script>" +
            "insert into zx_tendaysreport t\n" +
            "  (REPORTID,PLACEPOINTID,USEDAY,GATHERTYPE,REALMONEY,BANCIMONEY,FINANCEMONEY,uploadflag,docno,STATUS)\n" +
            "select zx_tendaysreport_seq.nextval REPORTID,a.* from (\n" +
            " <foreach collection=\"inReportMapList\" item=\"item\" index=\"index\" separator=\"union all\">\n" +
            "(select " +
            "#{item.placepointid} PLACEPOINTID," +
            "to_date(#{item.useday},'yyyy-MM-dd') USEDAY," +
            " #{item.gathertype} GATHERTYPE," +
            "'0' REALMONEY," +
            "'0' BANCIMONEY," +
            "#{item.financemoney} FINANCEMONEY," +
            "'N' uploadflag," +
            "#{item.docno} docno," +
            "'1' STATUS\n" +
            "from dual)\n" +
            " </foreach>"+
            ") a\n" +
            "</script>")
    public int insTenDaysReport(@Param("inReportMapList")List<ReportItem> inReportMapList);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

update的foreach

@DslDataSource(MASTER)
    @Update("<script>" +
            "<foreach collection='upReportMapList' item='item' index='index' open='begin' close=';end;' separator=';'>\n" +
            "update zx_tendaysreport set financemoney = #{item.financemoney} where placepointid = #{item.placepointid} and gathertype = #{item.gathertype} and useday = to_date(#{item.useday},'yyyy-MM-dd')" +
            "</foreach>" +
            "</script>")
    public int upTenDaysReport(@Param("upReportMapList")List<ReportItem> upReportMapList);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

分批调用mybatis的接口方法


  int inPointDataLimit = 50;//每一批的数量
  List<ReportItem> inNewList = new ArrayList<ReportItem>();
  for (int i = 0; i < inReportMapList.size(); i++) {
      //分批次处理
      inNewList.add(inReportMapList.get(i));
      if(inPointDataLimit == inNewList.size() || i == inReportMapList.size() - 1){
          tenDaysToHubMapper.insTenDaysReport(inNewList);
          inNewList.clear();
      }
  }


  int upPointDataLimit = 50;//每一批的数量
  List<ReportItem> upNewList = new ArrayList<ReportItem>();
  for (int i = 0; i < upReportMapList.size(); i++) {
      //分批次处理
      upNewList.add(upReportMapList.get(i));
      if(upPointDataLimit == upNewList.size() || i == upReportMapList.size() - 1){
          tenDaysToHubMapper.upTenDaysReport(upNewList);
          upNewList.clear();
      }
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/749189
推荐阅读
相关标签
  

闽ICP备14008679号