mybatis single pen batch storage method of entity data

  • 2020-12-26 05:42:56
  • OfStack

This article focuses on how to save entity data. The specific contents are as follows;

1. xml sample


<?xml version="1.0" encoding="GBK"?>
<!-- 1..1 -->
<cisReports batNo=" Query batch number " unitName=" Query unit name " subOrgan=" Branch name " queryUserID=" Query the operator login name " queryCount=" Number of query requests " receiveTime=" Enquiry of Application Time , format YYYYMMDD HH24:mm:ss">
  <!--  The following is the query result of each query application  1..n -->
  <cisReport reportID=" Report number " buildEndTime=" End time of report generation , format YYYY-MM-DD HH24:mm:ss" queryReasonID=" Query reason ID , see data dictionary for details " subReportTypes=" Query charges sub-report ID, Multiple billing sub-reports ID Comma separated " treatResult=" The number of charges per sub-report , with subReportTypes11 The corresponding , Greater than or equal to 0 The set of values of , Comma separated "  
  subReportTypesShortCaption=" Chinese name of the charge sub-report for query  " refID=" reference ID, For querying references in application conditions ID" hasSystemError=" Whether there is a system error, true : There is an error, false Error: no " 
  isFrozen=" Whether the customer has been frozen, true : Frozen, false : Not frozen ">
    <!-- 1 Query condition information  1..1 -->
    <queryConditions>
      <!-- 1..n -->
      <item>
        <name> English name of query condition </name>
        <caption> Query the Chinese name of the condition </caption>
        <value> Query condition value </value>
      </item>
    </queryConditions>
    <!--2 The identity authentication  1..1 -->
    <policeCheckInfo subReportType="10602" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode ="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
        <item>          
          <name> The name of the person inquired </name>
          <documentNo> Id number of the person being inquired </documentNo>
          <!--1 . 1 to  2, Don't 1 to  treatResult for 3 When is empty -->
          <result> The result of identity authentication, 1 . 1 to  2, Don't 1 to </result>
        </item>
    </policeCheckInfo>
    <!-- 3 Personal cell phone number check  1..1 -->
    <mobileCheckInfo subReportType="13612" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
        <!--treatresult for 2 , 3 , there are no following nodes -->
        <item>
          <nameCheckResult> Name verification results , There are: 1 And the basic 1 And don't 1 Unable to verify  </nameCheckResult>
          <documentNoCheckResult> The verification results of certificate number are as follows: 1 And don't 1 Unable to verify  </documentNoCheckResult>
          <phoneCheckResult> Check results of mobile phone number :1 Unable to verify  </phoneCheckResult>          
          <areaInfo> Number attribution place </areaInfo>
          <operator> Operator,  1 : China Telecom  2 : China Mobile  3: China Unicom  </operator>
        </item>
    </mobileCheckInfo>
    <!--4 Personal anti-fraud risk overview information  1..1 -->
    <personAntiSpoofingDescInfo subReportType="14225" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatsult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
      <!--treatresult for 2 , there are no following nodes -->
      <!--
       Personal Anti-fraud Overview information. As in the following example, it may be empty and may exist in it 0 Article or n Return based on the specific result. 
      1 ,   The anti-fraud risk score is 100 Point, the risk level is high, it is recommended to refuse. 
      2 ,   Telecom mobile Phone Number 131****1542 Lack of use 1 Months. 
      3 ,   Hit the wool party list. 
      4 ,   Hit fraud risk list. 
      5 ,   A list of high-risk targets. 
      6 ,   There are 7 An overdue credit record. 
      7 ,   There are 40 Personal risk profile. 
      8 ,   In the past two years by the agency query 23 Personal information.       
      -->      
      <personAntiSpoofingDesc> Personal Anti-fraud Overview information </personAntiSpoofingDesc>
    </personAntiSpoofingDescInfo>
    <!--5 Personal anti-fraud risk score information  1..1 -->
    <personAntiSpoofingInfo subReportType="14224" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
      <!--treatresult for 2 , 3 , there are no following nodes -->
      <riskScore> Risk score </riskScore>
      <riskLevel> Risk level, value: high, medium, low </riskLevel>
      <suggest> Risk recommendation, value: reject the proposal, review the proposal, pass the proposal </suggest>
      <hitTypes> Hit types: high-risk list, personal risk information, overdue credit list, information inquired by institutions, abnormal status of mobile phone number, low Internet age of mobile phone number, wool party list, fraud risk list, etc., which may be 1 One or more </hitTypes>
    </personAntiSpoofingInfo>
    <!-- 6 Cell phone number status information  1..1 -->
    <mobileStatusInfo subReportType="13611" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
        <!--treatresult for 2 , 3 , there are no following nodes -->
        <item>
          <operator> Operator,  1 : China Telecom  2 : China Mobile  3: China Unicom  </operator>
          <areaInfo> Where the cell phone number belongs  </areaInfo>
          <phoneStatus> Mobile phone state  1 : Normal in use  2:  downtime  3 That is not enabled  4 : already XiaoHao  5- other  6 Pre XiaoHao: </phoneStatus>
          <timeLength> The length of time the phone number is on the Internet, e.g., not enough time on the Internet 1 Months, 1-2 Months, 3-6 Months, 7-12 months  </timeLength>
          <cancelTime> Number cancellation time </cancelTime>
        </item>
    </mobileStatusInfo>
    <!--7 Whether to hit the wool party list  1..1-->
    <econnoisserurInfo subReportType="14228" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
      <!--treatresult for 2 , 3 , there are no following nodes -->
      <state> Whether to hit the wool Party list, value: 0/1 . 0 It means missing the Wool party list, 1 Indicates hit the Wool party list </state>
    </econnoisserurInfo>
    <!--8 Whether to hit the fraud risk list  1..1-->
    <fraudRiskInfo subReportType="14229" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
      <!--treatresult for 2 , 3 , there are no following nodes -->
      <state> Whether to hit the fraud risk list, value: 0/1 . 0 Represents the list of fraud risks not hit, 1 Represents the hit fraud risk list </state>
    </fraudRiskInfo>
    <!--9 Whether to hit the high risk list  1..1 -->
    <personRiskAssess subReportType="14226" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
        <!--treatresult for 2 , 3 , there are no following nodes -->
        <checkResult> Whether to hit the high risk list  1 : that's right. 2 : no </checkResult>
    </personRiskAssess>
    <!-- 10 Network credit overdue information  1..1 -->
    <microNearlyThreeYearsOverdueInfo subReportType="13204" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
       <!--treatresult for 2 , 3 , there are no following nodes -->
       <!-- Overdue summary information  0..1-->
        <stat>
          <overdueAmount> Overdue principal, unit: the currency of the basic information of the loan shall prevail </overdueAmount>
          <overdueDays> Overdue days interval , Value interval: overdue 1 Days above </overdueDays>
          <overdueCount> The total number of overdue days </overdueCount>
        </stat>
        <!--0..1-->
        <items>
          <!-- Overdue profile  1..5  Multiple records -->
          <item>
            <overdueAmount> Overdue principal, unit: the currency of the basic information of the loan shall prevail </overdueAmount>
            <overdueDays> Overdue days interval , Value interval: overdue 1-6 Day, late 7-29 Day, late 30-59 Day, late 60-89 Day, late 90 Days above </overdueDays>
            <overdueCount> The number of pens in the number of days overdue range </overdueCount>
          </item>
        </items>
    </microNearlyThreeYearsOverdueInfo>
    <!-- 11 Risk information  1..1 -->
    <personRiskInfo subReportType="14227" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
      <!--treatresult for 2 , 3 , there are no following nodes -->
      <!--  Summary information  0..1-->
      <stat>
        <totleCount> Summary summary number of entries </totleCount>
        <alCount> Number of judicial cases </alCount>
        <zxCount> Number of judicial enforcement messages </zxCount>
        <sxCount> Number of messages of judicial dishonesty </sxCount>
        <swCount> Tax administrative law enforcement information number </swCount>
        <cqggCount> The number of overdue notice information </cqggCount>
        <wdyqCount> Network credit overdue information number </wdyqCount>
      </stat>
      <!--  Summary information  end-->
      <!--  Profile information  0..1-->
      <summary>
        <!--  Judicial case Information Summary information  0..1 -->
        <als>
          <!--  Judicial case information Summary information content  1..n -->
          <item>
            <recordId> Record number </recordId>
            <bt> The title </bt>
            <ajlx> Case type </ajlx>
            <sjnf> Year of review, format: YYYY</sjnf>
            <dsrlx> Party type </dsrlx>
          </item>
        </als>
        <!--  Judicial Executive Information Summary information  0..1 -->
        <zxs>
          <!--  Judicial Executive Information Summary Information content  1..n -->
          <item>
            <recordId> Record number </recordId>
            <bt> The title </bt>
            <zxbd> Subject matter, unit: currency shall prevail </zxbd>
            <larq> Date of filing, format YYYY-MM-DD</larq>
          </item>
        </zxs>
        <!--  Summary information on judicial dishonesty  0..1 -->
        <sxs>
          <!--  Judicial dishonesty Information Summary information content  1..n -->
          <item>
            <recordId> Record number </recordId>
            <bt> The title </bt>
            <larq> Date of filing, format YYYY-MM-DD</larq>
            <fbrq> Release date, format YYYY-MM-DD</fbrq>
          </item>
        </sxs>
        <!--  Summary information on tax Administrative enforcement information  0..1 -->
        <sws>
          <!--  Tax administrative law enforcement information summary information content  1..n -->
          <item>
            <recordId> Record number </recordId>
            <bt> The title </bt>
            <ggrq> Announcement date, format YYYY-MM-DD</ggrq>
          </item>
        </sws>
        <!-- > Summary information of arrears announcement information  0..1 -->
        <cqs>
          <!--  Summary information content of overdue announcement information  1..n -->
          <item>
            <recordId> Record number </recordId>
            <bt> The title </bt>
            <fbrq> Release date, format YYYY-MM-DD</fbrq>
          </item>
        </cqs>
        <!--  Network loan overdue information summary information  0..1 -->
        <wdyqs>
          <!--  Network loan overdue information summary information content  1..n -->
          <item>
            <recordId> Record number </recordId>
            <bt> The title </bt>
            <fbrq> Release date, format YYYY-MM-DD</fbrq>
          </item>
        </wdyqs>
      </summary>
    </personRiskInfo>    
    <!--12 Personal query records for the past two years  1..1 -->
    <historySimpleQueryInfo subReportType="19902" subReportTypeCost="96040" treatResult=" Report the status of the query ,1 : Chad, 2 : Not found. 3 : Other reasons not checked " treatErrorCode="treatResult=3 Error code , See Data Dictionary for details ,treatResult!=3 when , This attribute does not exist " errorMessage="treatResult=3 , the error description message for ,treatResult!=3 when , The value of this property is null ">
      <!--treatresult for 2 , 3 , there are no following nodes -->
      <!--0..1-->
      <items>
        <!-- 1..n -->
        <item>
          <unitMember> Unit type name </unitMember>
          <last1Month> nearly 1 Query record number per month </last1Month>
          <last3Month> nearly 3 Query record number per month </last3Month>
          <last6Month> nearly 6 Query record number per month </last6Month>
          <last12Month> nearly 12 Query record number per month </last12Month>
          <last18Month> nearly 18 Monthly query record number </last18Month>
          <last24Month> nearly 24 Monthly query record number </last24Month>
        </item>
      </items>
      <!--0..1-->
      <count>
        <last1Month> nearly 1 Total number of query records of each unit type in months </last1Month>
        <last3Month> nearly 3 Total number of query records of each unit type in months </last3Month>
        <last6Month> nearly 6 Total number of query records of each unit type in months </last6Month>
        <last12Month> nearly 12 Total number of query records of each unit type in months </last12Month>
        <last18Month> nearly 18 Monthly total number of query records for each unit type </last18Month>
        <last24Month> nearly 24 Monthly total number of query records for each unit type </last24Month>      
      </count>
    </historySimpleQueryInfo>
  </cisReport>
</cisReports>

2. Table structure design

1. Batch number: The outermost batch number is associated with each table.

2. Main table: That is, all the fields of each layer are stored in one table.

3. Solid design

There are three levels: CisReportRoot,CisReportChild and ReportElement


public class CisReportRoot extends BasePojo implements Serializable {
  private String docId;
  private String batNo;// Query batch number 
  @JSONField(serialize = false)
  private String xmlId;
  private CisReportChild cisReportChild;
/**
 * 2017/7/21.
 *  Report node attributes and child nodes 
 */
public class CisReportChild extends BasePojo {
  /**
   *  End time of report generation 
   **/
  private String buildEndTime;
  /**
   *  Is there a system error  true Said a  false Said there was no 
   **/
  private String hasSystemError;
  /**
   *  Whether the customer is frozen 
   **/
  private String isFrozen;
  private ReportElement reportElement;

public class ReportElement extends BasePojo {
  private String phone;
  private PoliceCheckInfo policeCheckInfo;// The identity authentication 
  private MobileCheckInfo mobileCheckInfo;// Personal cell phone number check 
  private PersonAntiSpoofingDescInfo personAntiSpoofingDescInfo;// Personal anti-fraud risk overview information 
  private PersonAntiSpoofingInfo personAntiSpoofingInfo;// Personal anti-fraud risk score information 
  private MobileStatusInfo mobileStatusInfo;// Cell phone number status information 
  private EconnoisserurInfo econnoisserurInfo;// Whether to hit the wool party list 
  private FraudRiskInfo fraudRiskInfo;// Whether to hit the fraud risk list 
  private PersonRiskAssess personRiskAssess;// Whether to hit the high risk list 
  private MicroNearlyThreeYearsOverdueInfo microNearlyThreeYearsOverdueInfo;// Network credit overdue information 
  private PersonRiskInfo personRiskInfo;// Risk information 
  private HistorySimpleQueryInfo historySimpleQueryInfo;// Personal query records for the past two years 

4, the code

< 1 > Single pen, batch without primary key

Data can be stored in map for either single or batch. In sql, data can be obtained through the key of map.

Such as:


 private void savePersonRiskInfo(String batNo, PersonRiskInfo personRiskInfo) throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("batNo", batNo);
     // single 
    map.put("item", personRiskInfo);
    pyMapper.savePersonRiskInfo(map);
    if (!ListUtil.isEmpty(personRiskInfo.getAlList())) {
       // batch 
      map.put("list", personRiskInfo.getAlList());
      pyMapper.saveAlInfoList(map);
    }

sql:


<!-- Personal Risk Record  -->
   // single 
  <insert id="savePersonRiskInfo" parameterType="java.util.Map">
    INSERT INTO TABLE_PERSON_RISK_INFO(BATNO,TOTLECOUNT,ALCOUNT,ZXCOUNT,SXCOUNT,SWCOUNT,CQGGCOUNT,WDYQCOUNT)
    VALUES (#{batNo,jdbcType=VARCHAR},
    #{item.totleCount,jdbcType=NUMERIC},
    #{item.alCount,jdbcType=NUMERIC},#{item.zxCount,jdbcType=NUMERIC},#{item.sxCount,jdbcType=NUMERIC},
    #{item.swCount,jdbcType=NUMERIC},#{item.cqggCount,jdbcType=NUMERIC},#{item.wdyqCount,jdbcType=NUMERIC})
  </insert>
  <!-- Overdue detail record  -->
   // batch 
  <insert id="saveMicroNearlyThreeYearsOverdueInfoList" parameterType="java.util.Map">
    INSERT INTO TABLE_MNTYOI (BATNO,OVERDUEAMOUNT,OVERDUEDAYS,OVERDUECOUNT)
    <foreach collection="list" item="item" separator="union all">
      (
      SELECT #{batNo,jdbcType=VARCHAR},
      #{item.overdueAmount,jdbcType=VARCHAR},
      #{item.overdueDays,jdbcType=VARCHAR},
      #{item.overdueCount,jdbcType=NUMERIC}
      FROM DUAL
      )
    </foreach>
  </insert>

 private CisReportRoot invokePy(PyQueryBean pyQueryBean) throws Exception {
    pyQueryBean.setQueryFromPy(QUERY_FROM_PY);
    //call py service
    CisReportRoot cisReportRoot = queryCisReportFromPyServer(pyQueryBean);
    cisReportRoot.getCisReportChild().getReportElement().setPhone(pyQueryBean.getPhone());
    //cacheService.save(cisReportRoot);
     // ( 1 ) Save data 
    saveCisReport(cisReportRoot);
    return cisReportRoot;
  }

(1) Save data


 @Transactional(rollbackFor = Exception.class)
  @Override
  public CisReportRoot saveCisReport(CisReportRoot cisReportRoot) throws Exception {
    try {
      ReportElement reportElement = cisReportRoot.getCisReportChild().getReportElement();
      PersonRiskInfo personRiskInfo = reportElement.getPersonRiskInfo();
      // ( 2 ) Main table, save xml All node information (not including personal risk information), save a single data 
      pyMapper.saveCisReport(cisReportRoot);
      if (SUCCESS.equals(cisReportRoot.getCisReportChild().getReportElement().getPersonRiskInfo().getTreatResult())) {
        savePersonRiskInfo(cisReportRoot.getBatNo(), personRiskInfo);
      }
      if (cisReportRoot.getCisReportChild().getReportElement().getHistorySimpleQueryInfo().getTreatResult().equals(SUCCESS)) {
        Map<String, Object> map = new HashMap<>();
          // ( 3 ) Save batch data 
        map.put("batNo", cisReportRoot.getBatNo());
        if (!ListUtil.isEmpty(cisReportRoot.getCisReportChild().getReportElement().getHistorySimpleQueryInfo().getItemList())) {
          map.put("list", cisReportRoot.getCisReportChild().getReportElement().getHistorySimpleQueryInfo().getItemList());
          pyMapper.saveHistorySimpleQueryInfoList(map);
        }
        if (!ListUtil.isEmpty(cisReportRoot.getCisReportChild().getReportElement().getMicroNearlyThreeYearsOverdueInfo().getList())) {
          map.put("list", cisReportRoot.getCisReportChild().getReportElement().getMicroNearlyThreeYearsOverdueInfo().getList());
          pyMapper.saveMicroNearlyThreeYearsOverdueInfoList(map);
        }
      }
      return cisReportRoot;
    } catch (Exception e) {
      logger.error("saveCisReport@PyserviceImpl_Exception", e);
      throw e;
    }
  }

(2) Save the main table


<insert id="saveCisReport" parameterType="java.util.Map">
    INSERT INTO TABLE_CISREPORT
    (BATNO,BUILDENDTIME,ISFROZEN,
    MCI_NAMECHECKRESULT,MCI_AREAINFO,MCI_DOCUMENTNOCHECKRESULT,MCI_OPERATOR,MCI_PHONECHECKRESULT,
    PCI_DOCUMENTNO,PCI_NAME,PCI_RESULT,
    PASDI_DESC,
    PASI_HITTYPES,PASI_RISKLEVEL,PASI_RISKSCORE,PASI_RISKSUGGEST,
    MS_AREAINFO,MS_CAnCELTIME,MS_OPERATOR,MS_PHONESTATUS,MS_TIMELENGTH,
    ECONNOISSERUR,
    FRAUDRISK,
    PRA_CHECKRESULT,
    MNTYOI_OVERDUEAMOUNT,MNTYOI_OVERDUECOUNT,MNTYOI_OVERDUEDAYS,
    HS_LAST1MONTH,HS_LAST3MONTH,HS_LAST6MONTH,HS_LAST12MONTH,HS_LAST18MONTH,HS_LAST24MONTH,
    PHONE,XMLID)
    VALUES
    (#{batNo,jdbcType=VARCHAR},
    to_date(#{cisReportChild.buildEndTime},'yyyy-MM-dd hh24:mi:ss'),
    #{cisReportChild.isFrozen,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.mobileCheckInfo.nameCheckResult,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.mobileCheckInfo.areaInfo,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.mobileCheckInfo.documentNoCheckResult,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.mobileCheckInfo.operator,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.mobileCheckInfo.phoneCheckResult,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.policeCheckInfo.documentNo,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.policeCheckInfo.name,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.policeCheckInfo.result,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.personAntiSpoofingDescInfo.personAntiSpoofingDesc,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.personAntiSpoofingInfo.hitTypes,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.personAntiSpoofingInfo.riskLevel,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.personAntiSpoofingInfo.riskScore,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.personAntiSpoofingInfo.suggest,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.mobileStatusInfo.areaInfo,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.mobileStatusInfo.cancelTime,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.mobileStatusInfo.operator,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.mobileStatusInfo.phoneStatus,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.mobileStatusInfo.timeLength,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.econnoisserurInfo.state,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.fraudRiskInfo.state,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.personRiskAssess.checkResult,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.microNearlyThreeYearsOverdueInfo.overdueAmount,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.microNearlyThreeYearsOverdueInfo.overdueCount,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.microNearlyThreeYearsOverdueInfo.overdueDays,jdbcType=VARCHAR},
    #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last1Month,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last3Month,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last6Month,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last12Month,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last18Month,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.historySimpleQueryInfo.totalCount.last24Month,jdbcType=NUMERIC},
    #{cisReportChild.reportElement.phone,jdbcType=VARCHAR},
    #{xmlId,jdbcType=VARCHAR}
    )

(3) Save batch data (primary key is not generated automatically)


<!-- Personal query records for the past two years  -->
  <insert id="saveHistorySimpleQueryInfoList" parameterType="java.util.Map">
    INSERT INTO
    TABLE_HISTORY_SIMPLE_QUERY
    (BATNO,UNIT_MEMBER,LAST1MONTH,LAST3MONTH,LAST6MONTH,LAST12MONTH,LAST18MONTH,LAST24MONTH)
    <foreach collection="list" item="item" separator="union all">
      (
      SELECT
      #{batNo,jdbcType=VARCHAR},
      #{item.unitMember,jdbcType=VARCHAR},
      #{item.last1Month,jdbcType=NUMERIC},#{item.last3Month,jdbcType=NUMERIC},
      #{item.last6Month,jdbcType=NUMERIC},#{item.last12Month,jdbcType=NUMERIC},
      #{item.last18Month,jdbcType=NUMERIC},#{item.last24Month,jdbcType=NUMERIC}
      FROM DUAL
      )
    </foreach>
  </insert>

< 2 > Single pen, batch need to insert the main key

A single pen contains a primary key


  DataServiceDetailResult dataServiceDetailResult = tdService.getDataServiceDetailResult(tdReportRoot);
    int n = tdDataServiceMapper.insertDataServiceDetailResult(dataServiceDetailResult);

 <!-- Information verification interface -->
  <!--DATASERVICE-->
  <insert id="insertDataServiceDetailResult" parameterType="DataServiceDetailResult">
    <selectKey keyProperty="id" resultType="BigDecimal" order="BEFORE">
      select SEQ_ICS_TD_DATASERVICE.nextval as id from dual
    </selectKey>
    insert into ICS_TD_DATASERVICE (ID, RECORDID, REASON_DESC, REASON_CODE,
    SUCCESS)
    values (#{id,jdbcType=DECIMAL}, #{recordId,jdbcType=DECIMAL}, #{reasonDesc,jdbcType=VARCHAR},
    #{reasonCode,jdbcType=VARCHAR},
    #{success,jdbcType=DECIMAL})
  </insert>

Batch save contains the primary key


 if (!ListUtil.isEmpty(interfacesList)) {
      map.put("recordId", id);
      map.put("list", interfacesList);
      tdDataServiceMapper.addBatchInterfaces(map);
    }

sql:


<!-- Batch saving interfaces-->
  <insert id="addBatchInterfaces" parameterType="java.util.List">
    <!--
     Comments for mysql Insert mode, can insert but cause the data cannot be rolled back 
     The following for oracle Insert mode: note parameterType : java.util.List or java.util.Map Can be 
    BEGIN
    <foreach collection="list" item="item" index="index" separator="">
      INSERT INTO ICS_TD_INTERFACES(ID, RECORDID, TYPE)
      VALUES
      (
      BLOANCRDTDATA.SEQ_ICS_TD_INTERFACES.nextval,
      #{recordId,jdbcType=DECIMAL},
      #{item.type,jdbcType=VARCHAR}
      );
    </foreach>
    COMMIT;
    END;-->
    insert into ICS_TD_INTERFACES (ID,RECORDID, TYPE)
    SELECT SEQ_ICS_TD_INTERFACES.nextval ID, A.*
    FROM(
    <foreach collection="list" item="item" index="index" separator="union all">
      SELECT
      #{recordId,jdbcType=DECIMAL},
      #{item.type,jdbcType=VARCHAR}
      FROM DUAL
    </foreach>
    ) A
  </insert>

conclusion


Related articles: