search

Home  >  Q&A  >  body text

How to query mysql in java to get the following results in json format?

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"
    }
]

}

大家讲道理大家讲道理2749 days ago896

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-05-17 09:59:53

    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.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-17 09:59:53

    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.

    reply
    0
  • Cancelreply