在上一篇写了接口调用解析返回的xml,并赋值到实体。这一篇主要介绍,如何保存实体数据。

一,xml样例

<?xml version="1.0" encoding="GBK"?>
<!-- 1..1 -->
<cisReports batNo="查询批次号" unitName="查询单位名称" subOrgan="分支机构名称" queryUserID="查询操作员登录名" queryCount="查询请求数量" receiveTime="查询申请时间,格式YYYYMMDD HH24:mm:ss">
<!-- 以下为每个查询申请的查询结果 1..n -->
<cisReport reportID="报告编号" buildEndTime="报告生成结束时间,格式YYYY-MM-DD HH24:mm:ss" queryReasonID="查询原因ID,详见数据字典" subReportTypes="查询的收费子报告ID,多个收费子报告ID用逗号分隔" treatResult="对应的收费子报告收费次数,与subReportTypes一一对应,为大于等于0的值的集合,用逗号分隔"
subReportTypesShortCaption="查询的收费子报告中文名称 " refID="引用ID,为查询申请条件中的引用ID" hasSystemError="有否系统错误,true:有错误,false:无错误"
isFrozen="该客户是否被冻结,true:被冻结,false:未被冻结">
<!-- 1查询条件信息 1..1 -->
<queryConditions>
<!-- 1..n -->
<item>
<name>查询条件英文名称</name>
<caption>查询条件中文名称</caption>
<value>查询条件值</value>
</item>
</queryConditions> <!--2身份认证 1..1 -->
<policeCheckInfo subReportType="10602" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode ="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<item>
<name>被查询者姓名</name>
<documentNo>被查询者证件号码</documentNo>
<!--1,一致 2,不一致 treatResult为3时为空-->
<result>身份认证结果,1,一致 2,不一致</result>
</item>
</policeCheckInfo> <!-- 3个人手机号码核查 1..1 -->
<mobileCheckInfo subReportType="13612" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点-->
<item>
<nameCheckResult>姓名核查结果,有:一致、基本一致、不一致、无法核查 </nameCheckResult>
<documentNoCheckResult>证件号码核查结果,有:一致、不一致、无法核查 </documentNoCheckResult>
<phoneCheckResult>手机号码核查结果:一致、无法核查 </phoneCheckResult>
<areaInfo>号码归属地</areaInfo>
<operator>运营商 1:中国电信 2:中国移动 3:中国联通 </operator>
</item>
</mobileCheckInfo> <!--4个人反欺诈风险综述信息 1..1 -->
<personAntiSpoofingDescInfo subReportType="14225" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatsult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2时没有以下节点-->
<!--
个人反欺诈综述信息。如以下例子,可能为空,可能存在其中0条或n条,根据具体结果返回。
1、 反欺诈风险评分为100分,风险等级为高,建议拒绝。
2、 电信手机号码131****1542使用不足1个月。
3、 命中羊毛党名单。
4、 命中欺诈风险名单。
5、 命中高风险人员名单。
6、 存在7笔逾期的信贷记录。
7、 存在40条个人风险概要信息。
8、 在近两年被机构查询过23次个人信息。
-->
<personAntiSpoofingDesc>个人反欺诈综述信息</personAntiSpoofingDesc>
</personAntiSpoofingDescInfo> <!--5个人反欺诈风险评分信息 1..1 -->
<personAntiSpoofingInfo subReportType="14224" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点--> <riskScore>风险评分</riskScore>
<riskLevel>风险等级,取值:高,中度,低</riskLevel>
<suggest>风险建议,取值:建议拒绝,建议复核,建议通过</suggest>
<hitTypes>命中类型:高风险名单、个人风险信息、信贷逾期名单、被机构查询信息、手机号码状态异常、手机号码低网龄、羊毛党名单、欺诈风险名单等等,可能为1个或多个</hitTypes>
</personAntiSpoofingInfo> <!-- 6手机号码状态信息 1..1 -->
<mobileStatusInfo subReportType="13611" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点-->
<item>
<operator>运营商 1:中国电信 2:中国移动 3:中国联通 </operator>
<areaInfo>手机号码归属地 </areaInfo>
<phoneStatus>手机状态 1:正常在用 2: 停机 3:未启用 4:已销号 5-其他 6:预销号</phoneStatus>
<timeLength>手机号码在网时长,如:在网时长不足1个月,1-2个月,3-6个月,7-12个月 </timeLength>
<cancelTime>号码注销时间</cancelTime>
</item>
</mobileStatusInfo> <!--7是否命中羊毛党名单 1..1-->
<econnoisserurInfo subReportType="14228" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点-->
<state>是否命中羊毛党名单,取值:0/1,0表示未命中羊毛党名单,1表示命中羊毛党名单</state>
</econnoisserurInfo> <!--8是否命中欺诈风险名单 1..1-->
<fraudRiskInfo subReportType="14229" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点-->
<state>是否命中欺诈风险名单,取值:0/1,0表示未命中欺诈风险名单,1表示命中欺诈风险名单</state>
</fraudRiskInfo> <!--9是否命中高风险名单 1..1 -->
<personRiskAssess subReportType="14226" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点-->
<checkResult>是否命中高风险名单 1:是,2:否</checkResult>
</personRiskAssess> <!-- 10网贷逾期信息 1..1 -->
<microNearlyThreeYearsOverdueInfo subReportType="13204" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点--> <!--逾期汇总信息 0..1-->
<stat>
<overdueAmount>逾期本金,单位:以贷款基本信息的币种为准</overdueAmount>
<overdueDays>逾期天数区间,取值区间:逾期1天(含)以上</overdueDays>
<overdueCount>逾期天数区间的总笔数</overdueCount>
</stat> <!--0..1-->
<items>
<!--逾期概要信息 1..5 多个记录-->
<item>
<overdueAmount>逾期本金,单位:以贷款基本信息的币种为准</overdueAmount>
<overdueDays>逾期天数区间,取值区间:逾期1-6天,逾期7-29天,逾期30-59天,逾期60-89天,逾期90天(含)以上</overdueDays>
<overdueCount>逾期天数区间的笔数</overdueCount>
</item>
</items>
</microNearlyThreeYearsOverdueInfo> <!-- 11风险信息 1..1 -->
<personRiskInfo subReportType="14227" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点--> <!-- 汇总信息 0..1-->
<stat>
<totleCount>概要汇总条数</totleCount>
<alCount>司法案例信息条数</alCount>
<zxCount>司法执行信息条数</zxCount>
<sxCount>司法失信信息条数</sxCount>
<swCount>税务行政执法信息条数</swCount>
<cqggCount>催欠公告信息条数</cqggCount>
<wdyqCount>网贷逾期信息条数</wdyqCount>
</stat>
<!-- 汇总信息 end-->
<!-- 概要信息 0..1-->
<summary>
<!-- 司法案例信息概要信息 0..1 -->
<als>
<!-- 司法案例信息概要信息内容 1..n -->
<item>
<recordId>记录编号</recordId>
<bt>标题</bt>
<ajlx>案件类型</ajlx>
<sjnf>审结年份,格式:YYYY</sjnf>
<dsrlx>当事人类型</dsrlx>
</item>
</als>
<!-- 司法执行信息概要信息 0..1 -->
<zxs>
<!-- 司法执行信息概要信息内容 1..n -->
<item>
<recordId>记录编号</recordId>
<bt>标题</bt>
<zxbd>执行标的,单位:以币种为准</zxbd>
<larq>立案日期,格式YYYY-MM-DD</larq>
</item>
</zxs>
<!-- 司法失信信息概要信息 0..1 -->
<sxs>
<!-- 司法失信信息概要信息内容 1..n -->
<item>
<recordId>记录编号</recordId>
<bt>标题</bt>
<larq>立案日期,格式YYYY-MM-DD</larq>
<fbrq>发布日期,格式YYYY-MM-DD</fbrq>
</item>
</sxs>
<!-- 税务行政执法信息概要信息 0..1 -->
<sws>
<!-- 税务行政执法信息概要信息内容 1..n -->
<item>
<recordId>记录编号</recordId>
<bt>标题</bt>
<ggrq>公告日期,格式YYYY-MM-DD</ggrq>
</item>
</sws>
<!-- >催欠公告信息概要信息 0..1 -->
<cqs>
<!-- 催欠公告信息概要信息内容 1..n -->
<item>
<recordId>记录编号</recordId>
<bt>标题</bt>
<fbrq>发布日期,格式YYYY-MM-DD</fbrq>
</item>
</cqs>
<!-- 网贷逾期信息概要信息 0..1 -->
<wdyqs>
<!-- 网贷逾期信息概要信息内容 1..n -->
<item>
<recordId>记录编号</recordId>
<bt>标题</bt>
<fbrq>发布日期,格式YYYY-MM-DD</fbrq>
</item>
</wdyqs>
</summary>
</personRiskInfo> <!--12个人近两年历史查询记录 1..1 -->
<historySimpleQueryInfo subReportType="19902" subReportTypeCost="96040" treatResult="子报告查询状态,1:查得,2:未查得,3:其他原因未查得" treatErrorCode="treatResult=3时的错误代码,详见数据字典,treatResult!=3时,该属性不存在" errorMessage="treatResult=3时的错误描述信息,treatResult!=3时,该属性的值为空">
<!--treatresult为2、3时没有以下节点--> <!--0..1-->
<items>
<!-- 1..n -->
<item>
<unitMember>单位类型名称</unitMember>
<last1Month>近1个月查询记录数</last1Month>
<last3Month>近3个月查询记录数</last3Month>
<last6Month>近6个月查询记录数</last6Month>
<last12Month>近12个月查询记录数</last12Month>
<last18Month>近18月查询记录数</last18Month>
<last24Month>近24月查询记录数</last24Month>
</item>
</items>
<!--0..1-->
<count>
<last1Month>近1个月各单位类型查询记录总数</last1Month>
<last3Month>近3个月各单位类型查询记录总数</last3Month>
<last6Month>近6个月各单位类型查询记录总数</last6Month>
<last12Month>近12个月各单位类型查询记录总数</last12Month>
<last18Month>近18月各单位类型查询记录总数</last18Month>
<last24Month>近24月各单位类型查询记录总数</last24Month>
</count>
</historySimpleQueryInfo>
</cisReport>
</cisReports>

二,表结构设计

1,批次号:各表之间用最外层批次号关联。

2,主表:即把各层字段全部存在一个表中。

三,实体设计

分为三层:CisReportRoot ,CisReportChild ,ReportElement

public class CisReportRoot extends BasePojo implements Serializable {
private String docId;
private String batNo;//查询批次号
@JSONField(serialize = false)
private String xmlId;
private CisReportChild cisReportChild;
/**
* 2017/7/21.
* 报告节点属性以及子节点
*/
public class CisReportChild extends BasePojo {
/**
* 报告生成结束时间
**/
private String buildEndTime;
/**
* 是否有系统错误 true表示有 false表示没有
**/
private String hasSystemError;
/**
* 该客户是否被冻结
**/
private String isFrozen; private ReportElement reportElement;
public class ReportElement extends BasePojo {
private String phone;
private PoliceCheckInfo policeCheckInfo;//身份认证
private MobileCheckInfo mobileCheckInfo;//个人手机号码核查
private PersonAntiSpoofingDescInfo personAntiSpoofingDescInfo;//个人反欺诈风险综述信息
private PersonAntiSpoofingInfo personAntiSpoofingInfo;//个人反欺诈风险评分信息
private MobileStatusInfo mobileStatusInfo;//手机号码状态信息
private EconnoisserurInfo econnoisserurInfo;//是否命中羊毛党名单
private FraudRiskInfo fraudRiskInfo;//是否命中欺诈风险名单
private PersonRiskAssess personRiskAssess;//是否命中高风险名单
private MicroNearlyThreeYearsOverdueInfo microNearlyThreeYearsOverdueInfo;//网贷逾期信息
private PersonRiskInfo personRiskInfo;//风险信息
private HistorySimpleQueryInfo historySimpleQueryInfo;//个人近两年历史查询记录

四,代码

<1>单笔,批量无需主键

无论单笔还是批量都可以把数据存在map中,sql中通过map的键获取数据。

如:

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

sql:

   <!--个人风险记录 -->
   //单笔
<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> <!--逾期详细记录 -->
   //批量
<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)保存数据
saveCisReport(cisReportRoot);
return cisReportRoot;
}

(1)保存数据

    @Transactional(rollbackFor = Exception.class)
@Override
public CisReportRoot saveCisReport(CisReportRoot cisReportRoot) throws Exception {
try {
ReportElement reportElement = cisReportRoot.getCisReportChild().getReportElement();
PersonRiskInfo personRiskInfo = reportElement.getPersonRiskInfo();
//(2)主表,保存xml所有节点信息(不包含个人风险信息),保存单笔数据
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)保存批量数据
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)保存主表

<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}
)

查询主表(多个条件拼接)

<!-- 查询征信主表 -->
<select id="queryCisReportRoot" parameterType="PyQueryBean" resultMap="cisReportRootMap">
SELECT * FROM (
SELECT
BATNO,to_char(BUILDENDTIME,'yyyy-MM-dd hh24:mi:ss') as 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
FROM
TABLE_CISREPORT
<trim prefix="where" prefixOverrides="AND | OR ">
<if test="name != null and name != '' ">
AND PCI_NAME = #{name,jdbcType=VARCHAR}
</if>
<if test="documentNo != null and documentNo != '' ">
AND PCI_DOCUMENTNO=#{documentNo,jdbcType=VARCHAR}
</if>
<if test="phone != null and phone!= '' ">
AND PHONE = #{phone}
</if>
<if test="docId != null and docId != '' ">
AND BATNO = #{docId,jdbcType=VARCHAR}
</if>
<![CDATA[AND BUILDENDTIME >= add_months(sysdate,-1)]]>
</trim>
ORDER BY BUILDENDTIME DESC )
WHERE <![CDATA[ ROWNUM <= 1 ]]>
</select>

(3)保存批量数据(不自动生成主键)

<!--个人近两年历史查询记录 -->
<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>单笔,批量需要插入主键
单笔含主键

        DataServiceDetailResult dataServiceDetailResult = tdService.getDataServiceDetailResult(tdReportRoot);
int n = tdDataServiceMapper.insertDataServiceDetailResult(dataServiceDetailResult);
  <!--信息核验接口-->
<!--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>

批量保存包含主键

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

sql:

 <!--批量保存interfaces-->
<insert id="addBatchInterfaces" parameterType="java.util.List">
<!--
注释为mysql插入方式,可以插入但是导致数据回滚不了
下面为oracle插入方式:注意parameterType:java.util.List或java.util.Map都可以
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>

mybatis单笔批量保存的更多相关文章

  1. mybatis批量保存的两种方式(高效插入)

    知识点:mybatis中,批量保存的两种方式 1.使用mybatis foreach标签 2.mybatis ExecutorType.BATCH 参考博客:https://www.jb51.net/ ...

  2. mybatis 批量保存,并且唯一约束

    1.主键返回在insert配置中添加两个属性 useGeneratedKeys="true" keyProperty="id" 2.唯一约束冲突可以使用 ON ...

  3. 使用SpringBoot-JPA进行自定义的保存及批量保存

    更多精彩博文,欢迎访问我的个人博客 说明 SpringBoot版本:2.1.4.RELEASE java版本:1.8 文中所说JPA皆指spring-boot-starter-data-jpa 使用J ...

  4. mybatis执行批量更新update

    Mybatis的批量插入这里有http://ljhzzyx.blog.163.com/blog/static/38380312201353536375/.目前想批量更新,如果update的值是相同的话 ...

  5. 161102、MyBatis中批量插入

    方法一: <insert id="insertbatch" parameterType="java.util.List"> <selectKe ...

  6. .NET DLL 保护措施应用实例(百度云批量保存工具)

    最近做了个小工具,将保护措施思路全部应用到了此工具中. 点我下载   百度云批量保存工具是一款专门用于自动批量保存百度云分享的软件. 本软件特点:1:完全模拟人工操作:2:可以批量保存百度分享的文件( ...

  7. mybatis foreach批量插入数据:Oracle与MySQL区别

    mybatis foreach批量插入数据:Oracle与MySQL不同点: 主要不同点在于foreach标签内separator属性的设置问题: separator设置为","分 ...

  8. Mybatis+mysql批量插入性能分析测试

    前言 今天在网上看到一篇文章(后文中的文章指的就是它) https://www.jianshu.com/p/cce617be9f9e 发现了一种有关于mybatis批量插入的新方法,而且看了文章发现我 ...

  9. mybatis之批量插入

    一.导入功能优化 普通for循环,对于导入大量数据时非常耗时.可以通过Mybatis的批量插入功能提高效率.每批次导入的数据不能太多,否则会报错.通过测试发现,每批次200条为宜. 测试结果: 开启事 ...

随机推荐

  1. jQuery Form

    https://github.com/jquery-form/form#type 概念 jQuery表单插件允许您轻松,无差错地升级HTML表单以使用AJAX. 主要方法ajaxForm和ajaxSu ...

  2. word安装楷体gb2312方法。

    1:下载:楷体gb2312.http://www.downza.cn/soft/7732.html 2: 双击安装,将会下载楷体2312  的压缩文件,解压得到楷体2312.ttf. 3:  打开控制 ...

  3. hadoop2.x Federation

    单Active NN的架构使得HDFS在集群扩展性和性能上都有潜在的问题,当集群大到一定程度后,NN进程使用的内存可能会达到上百G,NN成为了性能的瓶颈 常用的估算公式为1G对应1百万个块,按缺省块大 ...

  4. Selenium IDE的一些操作

    1.运行速度过快时,可能出现找不到元素的情况,影响运行结果,将速度调慢慢一些,就可以运行成功. 如果为其他情况找不到元素,则需要另外找原因,有可能元素定位有问题,有可能无该元素. 2.导出录制的脚本为 ...

  5. HTML5中的本地、WebSql、离线应用存储

    1.   HTML5存储相关API a)   Localstorage 本地存储 b)   Web Sql DataBase 本地数据库存储 c)   .manifest 离线应用存储 2.   HT ...

  6. MongoDB之Replica Set(复制集复制)

    MongoDB支持两种复制模式: 主从复制(Master/Slave) 复制集复制(Replica Set) 下面主要记录我在centos虚拟机上安装replica set,主要参考:http://d ...

  7. 运行.xcworkspace项目后报错:'React/RCTBundleURLProvider.h’ file not found

    情况:根据https://github.com/rebeccahughes/react-native-device-info添加依赖库,运行.xcworkspacea项目后报错 解决:Delete n ...

  8. WCF For Silverlight跨域策略

    在WCF的根目录下添加跨域文件 <?xml version="1.0" encoding="utf-8" ?> <access-policy& ...

  9. PR曲线 ROC曲线的 计算及绘制

    在linear model中,我们对各个特征线性组合,得到linear score,然后确定一个threshold,linear score < threshold 判为负类,linear sc ...

  10. Bootstrap风格zTree树形菜单插件

    这是一款bootstrap风格jQuery zTree树形菜单插件,支持自定义编辑.添加列表菜单.删除列表等功能的jQuery树形菜单代码.在线演示 具体代码实现: <!DOCTYPE html ...