Json object from database in java

前端 未结 4 554
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 14:53

Can anyone help me how to create a JSON Object from the database?

This is what the JSON output should look like:

{“devicelist”:{
    “de         


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 15:20

    With jOOQ, you could produce a similar JSON list from your database:

    String json = create.select(TYPE, NAME, DEMO)
                        .from(REGISTER_DEVICE)
                        .fetch()
                        .formatJSON();
    

    The JSON String would look like this (configurable):

    {fields:["TYPE","NAME","DEMO"],
     records:[["01","CAM","Livingroom"],["15","CAM","Kitchen"]]}
    

    See more here. Alternatively, you can use your RDBMS's native SQL/JSON capabilities to create arbitrarily nested JSON documents.

    (Disclaimer: I work for the company behind jOOQ)

提交回复
热议问题