复杂嵌套类型
有些时候,在查询数据的时候,会出现嵌套的类型,比如一个object里面有一个list,在表设计的时候,设计成了,两个表格,关系是一对多的一个关系,在查询的时候想多个的数据都查询出来,比如如下类型,这样通过一个sql语句直接查询出来。
{
"type_id": "002",
"name": "PLC",
"time": "2019-08-14T15:57:38.000+0000",
"desc": null,
"testList": [
{
"product_id": "201908140835486360075",
"name": "PLC",
"time": "2019-08-14T15:57:38.000+0000",
"descs": "sadadasdsadsa",
"details": "Hardware devices that connect two or more networks and act as gateways between networks"
},
{
"product_id": "201908141038547337647",
"name": "PLC",
"time": "2019-08-14T15:57:38.000+0000",
"descs": "sadadasdsadsa",
"details": "ssssssssssssssssssssssssssssss"
},
{
"product_id": "201908141040023726318",
"name": "PLC",
"time": "2019-08-14T15:57:38.000+0000",
"descs": "sadadasdsadsa",
"details": null
},
{
"product_id": "201908141040345042388",
"name": "PLC",
"time": "2019-08-14T15:57:38.000+0000",
"descs": "sadadasdsadsa",
"details": null
}
]
}
首先应该建立一个model,用来存储这个类型数据,方便查找。红线部分就是嵌套的数据类型。这个写在xml里面。
当然在model里面也要建立好对应的model类。
之后便是sql语句了,其实就是简单的左连接语句。
之后写个controller和service里面,利用postman就可以查询出来对应的的结构数据了。
来源:CSDN
作者:人生有点bug的程序员
链接:https://blog.csdn.net/qq_34237136/article/details/103487657