How can springboot modify the json in this format?

{
  "code": 0,
  "msg": "",
  "count": 29,
  "data": [{
    "id": 10000,
    "username": "user-0",
    "sex": "",
    "city": "-0",
    "sign": "-0",
    "experience": 255,
    "logins": 24,
    "wealth": 82830700,
    "classify": "",
    "score": 57
  }, {
    "id": 10001,
    "username": "user-1",
    "sex": "",
    "city": "-1",
    "sign": "-1",
    "experience": 884,
    "logins": 58,
    "wealth": 64928690,
    "classify": "",
    "score": 27
  }, {
    "id": 10002,
    "username": "user-2",
    "sex": "",
    "city": "-2",
    "sign": "-2",
    "experience": 650,
    "logins": 77,
    "wealth": 6298078,
    "classify": "",
    "score": 31
  }, {
    "id": 10003,
    "username": "user-3",
    "sex": "",
    "city": "-3",
    "sign": "-3",
    "experience": 362,
    "logins": 157,
    "wealth": 37117017,
    "classify": "",
    "score": 68
  }, {
    "id": 10029,
    "username": "user-29",
    "sex": "",
    "city": "-29",
    "sign": "-29",
    "experience": 647,
    "logins": 107,
    "wealth": 97450636,
    "classify": "",
    "score": 27
  }]
}

ask springboot how to return json in this format.
only

in one data can be returned by default.

I want to write
clipboard.png

clipboard.png
but controller can"t write. I don"t know how to search.

Apr.06,2022

using java generics, I'll give you an example.
getter,setter I won't write about this

  

use @ ControllerAdvice and ResponseBodyAdvice. The Controller layer doesn't need to care at all about how to spell your json. It is all handled in advice.
or use aop. Block all controller or part of controller. It is handled in aop.
both of these are better than wrapping the return value directly in the business code or the controller layer, and you don't need to change every method when refactoring.

Menu