Now there are two tables in mysql, one is: table_a, which saves some name, url, page and other field information of the page, and the other table table_b saves the external link information in the page: name, url, table_a, table_b They are related by ID, a one-to-many relationship. Please tell me how to query mysql to obtain the following json result set.
{
"name": "BeJson",
"url": "http://www.bejson.com",
"page": 88,
"isNonProfit": true,
"links": [
{
"name": "Google",
"url": "http://www.google.com"
},
{
"name": "Baidu",
"url": "http://www.baidu.com"
},
{
"name": "SoSo",
"url": "http://www.SoSo.com"
}
]
}
What is queried in Java is generally not JSON, but Object. When you want to return the Object to the front end or client, use Jackson or FastJSON to convert the Object into JSON format. I don't know where you want to use JSON, so I can only answer this.
It has nothing to do with the database, it has to do with the ormap you use, which is the dao layer implementation. Some dao implementations support automatically extracting n data from the database in the case of 1:n.