On JSON data parsing with multiple nesting

Source: Internet
Author: User

Recent projects need to encapsulate a complex set of data models back to the front end, which is roughly how many orders a user can have, and there may be multiple policies under each order.

The approximate data model is as follows:

For the sake of description, first look at a user under an order, an order under the condition of an insurance order

Data: {

"Allcommunitytotalcontribution": "Total surplus contribution units of the Society",

"Mysumcontributionnumber": "My policy surplus contribution",

"Orderdetailmodel": [{

"OrderNumber": "Order Number",

"Policydetailmodel": {

"OrderNumber": "Order Number",

"Ordereffectivetime": "Order effective Time",

"Insurancename": Insurance name,

"nameofassured": "Name of the insured",

"Policyeffectivestate": "Policy-effective status",

"Surpluscontributionnumber": "The number of contribution units corresponding to policy surplus"

},
},
]
},

Success:true

At this point, you need to define the model for the database

The list<model> of the order level is also the model at the policy level.

The model under the policy level defines the relevant attributes of the policy

Here are the Mapperinterface and Mapper.xml files

Customize a Resultmap, the order level of the order_number and the order number corresponding to the policy number corresponding, because is a one-to-many, so with the label <collection>, so in the following <collection> Need to set an attribute, with order_number corresponding policy

Mybati automatically encapsulates parameters into model according to the resultmap of its own definition

The parameters returned are as follows:

{
"Data": {
"Allcommunitytotalcontribution": 10383837.27,
"Mysumcontributionnumber": 404316.24,
"Proportionvalue": "The proportion of total community is less than 0.1",
"Orderdetailmodel": [
{
"Ordereffectivetime": "2017-05-26",
"OrderNumber": "D000001725261991",
"Policydetailmodel": [
{
"Insurancecode": "iamgltd01a",
"Insurancename": "mutual trust life-long group pension Insurance",
"nameofassured": "Oars",
"OrderNumber": "D000001725261991",
"Policyeffectivestate": "1",
"Surpluscontributionnumber": 101079.06
}
]
},
{
"Ordereffectivetime": "2017-05-26",
"OrderNumber": "D000002265263965",
"Policydetailmodel": [
{
"Insurancecode": "iamgltd01a",
"Insurancename": "mutual trust life-long group pension Insurance",
"nameofassured": "Oars",
"OrderNumber": "D000002265263965",
"Policyeffectivestate": "1",
"Surpluscontributionnumber": 101079.06
}
]
},
{
"Ordereffectivetime": "2017-05-26",
"OrderNumber": "D000003875264027",
"Policydetailmodel": [
{
"Insurancecode": "iamgltd01a",
"Insurancename": "mutual trust life-long group pension Insurance",
"nameofassured": "Oars",
"OrderNumber": "D000003875264027",
"Policyeffectivestate": "1",
"Surpluscontributionnumber": 101079.06
}
]
},
{
"Ordereffectivetime": "2017-05-26",
"OrderNumber": "D000003265263561",
"Policydetailmodel": [
{
"Insurancecode": "iamgltd01a",
"Insurancename": "mutual trust life-long group pension Insurance",
"nameofassured": "Oars",
"OrderNumber": "D000003265263561",
"Policyeffectivestate": "1",
"Surpluscontributionnumber": 101079.06
}
]
}
]
},
"Success": True
}

On JSON data parsing with multiple nesting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.