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