分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

关于多重嵌套的JSON数据解析

发布时间:2023-09-06 02:00责任编辑:沈小雨关键词:暂无标签

最近项目中需要封装一套复杂的数据模型返回给前端,大致就是一个用户会有多笔订单,每个订单下可能会有多笔保单,

大致的数据模型如下:

为了方面描述,先看一下一个用户下有一条订单,一条订单下有一个保险订单的情况

data: {

" allCommunityTotalContribution ": "全社总盈余贡献单位数",
???
???????" mySumContributionNumber ": "我的保单盈余贡献",
???
???????" orderDetailModel ": [{
???????
                        “orderNumber”:“订单号”,
???????
                       " policyDetailModel ":{
???????
                                          “orderNumber”:“订单号”,

                                         “orderEffectiveTime”:“订单生效时间”,

                                          “insuranceName”: 保险名称,
???????
                                          “nameOfAssured”:“被保险人姓名”,
???????
                                           “policyEffectiveState”:“保单生效状态”,
???????
                                            “surplusContributionNumber”:“对应保单盈余贡献单位数”

                                        },
                         },
                ]
??},
??
???success: true

此时,需要定义数据库对应的Model

订单层面的list<model>下还有保单层面的model

 保单层面下的model定义了保单的相关属性 

 下面是mapperInterface和mapper.xml文件

自定义一个resultmap,将订单层面的ORDER_NUMBER和该订单号对应的保单号对应,因为是一对多,所以用标签<collection>,,因此在下面的<collection>中需要多定一个属性,用ORDER_NUMBER对应保单

mybati会自动根据自己定义的resultMap去封装参数到model中

返回的参数如下:

{
???"data": {
???????"allCommunityTotalContribution": 10383837.27,
???????"mySumContributionNumber": 404316.24,
"proportionValue":"占全社总数比例小于万分之0.1",
???????"orderDetailModel": [
???????????{
???????????????"orderEffectiveTime": "2017-05-26",
???????????????"orderNumber": "D000001725261991",
???????????????"policyDetailModel": [
???????????????????{
???????????????????????"insuranceCode": "IAMGLTD01A",
???????????????????????"insuranceName": "互信一生终身团体养老年金保险",
???????????????????????"nameOfAssured": "沈静",
???????????????????????"orderNumber": "D000001725261991",
???????????????????????"policyEffectiveState": "1",
???????????????????????"surplusContributionNumber": 101079.06
???????????????????}
???????????????]
???????????},
???????????{
???????????????"orderEffectiveTime": "2017-05-26",
???????????????"orderNumber": "D000002265263965",
???????????????"policyDetailModel": [
???????????????????{
???????????????????????"insuranceCode": "IAMGLTD01A",
???????????????????????"insuranceName": "互信一生终身团体养老年金保险",
???????????????????????"nameOfAssured": "沈静",
???????????????????????"orderNumber": "D000002265263965",
???????????????????????"policyEffectiveState": "1",
???????????????????????"surplusContributionNumber": 101079.06
???????????????????}
???????????????]
???????????},
???????????{
???????????????"orderEffectiveTime": "2017-05-26",
???????????????"orderNumber": "D000003875264027",
???????????????"policyDetailModel": [
???????????????????{
???????????????????????"insuranceCode": "IAMGLTD01A",
???????????????????????"insuranceName": "互信一生终身团体养老年金保险",
???????????????????????"nameOfAssured": "沈静",
???????????????????????"orderNumber": "D000003875264027",
???????????????????????"policyEffectiveState": "1",
???????????????????????"surplusContributionNumber": 101079.06
???????????????????}
???????????????]
???????????},
???????????{
???????????????"orderEffectiveTime": "2017-05-26",
???????????????"orderNumber": "D000003265263561",
???????????????"policyDetailModel": [
???????????????????{
???????????????????????"insuranceCode": "IAMGLTD01A",
???????????????????????"insuranceName": "互信一生终身团体养老年金保险",
???????????????????????"nameOfAssured": "沈静",
???????????????????????"orderNumber": "D000003265263561",
???????????????????????"policyEffectiveState": "1",
???????????????????????"surplusContributionNumber": 101079.06
???????????????????}
???????????????]
???????????}
???????]
???},
???"success": true
}

关于多重嵌套的JSON数据解析

原文地址:https://www.cnblogs.com/renyuanwei/p/9203026.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved