账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    SpringBoot JSON问题
    32
    0

    查询 使用SpringBoot 默认的json,数据库返回的JSON是这样的

    [{
        "bg_CycleId": null,
        "bg_BugId": null,
        "bg_Status": "Closed",
        "bg_Responsible": "范伟",
        "bg_Project": null,
        "bg_Subject": null,
        "bg_Summary": "1、教学实训教师无法选择教学任务和上传文件",
        "bg_Description": "<html><body>1、教学实训教师无法选择教学任务和上传文件</body></html>",
        "bg_DevComments": null,
        "bg_Reproducible": "Y",
        "bg_Severity": "1-一般缺陷",
        "bg_Priority": "5-Urgent",
        "bg_DetectedBy": null,
        "bg_TestReference": null,
        "bg_CycleReference": null,
        "bg_RunReference": null,
        "bg_StepReference": null,
        "bg_DetectionDate": null,
        "bg_DetectionVersion": null,
        "bg_PlannedClosingVer": null,
        "bg_EstimatedFixTime": null,
        "bg_ActualFixTime": null,
        "bg_ClosingDate": null,
        "bg_ClosingVersion": null,
        "bg_ToMail": null,
        "bg_Attachment": "Y",
        "bg_User01": null,
        "bg_User02": null,
        "bg_User03": null,
        "bg_User04": null,
        "bg_User05": null,
        "bg_User06": null,
        "bg_User07": null,
        "bg_User08": null,
        "bg_User09": null,
        "bg_User10": null,
        "bg_User11": null,
        "bg_User12": null,
        "bg_User13": null,
        "bg_User14": null,
        "bg_User15": null,
        "bg_User16": null,
        "bg_User17": null,
        "bg_User18": null,
        "bg_User19": null,
        "bg_User20": null,
        "bg_User21": null,
        "bg_User22": null,
        "bg_User23": null,
        "bg_User24": null,
        "bg_UserHr01": null,
        "bg_UserHr02": null,
        "bg_UserHr03": null,
        "bg_UserHr04": null,
        "bg_UserHr05": null,
        "bg_UserHr06": null,
        "bg_BugVerStamp": null,
        "bg_HasChange": null,
        "bg_Vts": "2017-08-23 14:11:59",
        "bg_ExtendedReference": null,
        "bg_TaskStatus": null
    }, {
        "bg_CycleId": null,
        "bg_BugId": null,
        "bg_Status": "Closed",
        "bg_Responsible": "王乡城",
        "bg_Project": null,
        "bg_Subject": null,
        "bg_Summary": "2、实训成绩导出excel所选信息学号和姓名位置错乱",
        "bg_Description": "<html><body>2、实训成绩导出excel所选信息学号和姓名位置错乱</body></html>",
        "bg_DevComments": null,
        "bg_Reproducible": "Y",
        "bg_Severity": "1-一般缺陷",
        "bg_Priority": "5-Urgent",
        "bg_DetectedBy": null,
        "bg_TestReference": null,
        "bg_CycleReference": null,
        "bg_RunReference": null,
        "bg_StepReference": null,
        "bg_DetectionDate": null,
        "bg_DetectionVersion": null,
        "bg_PlannedClosingVer": null,
        "bg_EstimatedFixTime": null,
        "bg_ActualFixTime": null,
        "bg_ClosingDate": null,
        "bg_ClosingVersion": null,
        "bg_ToMail": null,
        "bg_Attachment": "Y",
        "bg_User01": null,
        "bg_User02": null,
        "bg_User03": null,
        "bg_User04": null,
        "bg_User05": null,
        "bg_User06": null,
        "bg_User07": null,
        "bg_User08": null,
        "bg_User09": null,
        "bg_User10": null,
        "bg_User11": null,
        "bg_User12": null,
        "bg_User13": null,
        "bg_User14": null,
        "bg_User15": null,
        "bg_User16": null,
        "bg_User17": null,
        "bg_User18": null,
        "bg_User19": null,
        "bg_User20": null,
        "bg_User21": null,
        "bg_User22": null,
        "bg_User23": null,
        "bg_User24": null,
        "bg_UserHr01": null,
        "bg_UserHr02": null,
        "bg_UserHr03": null,
        "bg_UserHr04": null,
        "bg_UserHr05": null,
        "bg_UserHr06": null,
        "bg_BugVerStamp": null,
        "bg_HasChange": null,
        "bg_Vts": "2017-08-23 14:12:01",
        "bg_ExtendedReference": null,
        "bg_TaskStatus": null
    }]

    而LayUi要求返回的JSON格式是下面这样的:

    {
      "code": 0,
      "msg": "",
      "count": 1000,
      "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": 10004,
        "username": "user-4",
        "sex": "男",
        "city": "城市-4",
        "sign": "签名-4",
        "experience": 807,
        "logins": 51,
        "wealth": 76263262,
        "classify": "作家",
        "score": 6
      }, {
        "id": 10005,
        "username": "user-5",
        "sex": "女",
        "city": "城市-5",
        "sign": "签名-5",
        "experience": 173,
        "logins": 68,
        "wealth": 60344147,
        "classify": "作家",
        "score": 87
      }, {
        "id": 10006,
        "username": "user-6",
        "sex": "女",
        "city": "城市-6",
        "sign": "签名-6",
        "experience": 982,
        "logins": 37,
        "wealth": 57768166,
        "classify": "作家",
        "score": 34
      }, {
        "id": 10007,
        "username": "user-7",
        "sex": "男",
        "city": "城市-7",
        "sign": "签名-7",
        "experience": 727,
        "logins": 150,
        "wealth": 82030578,
        "classify": "作家",
        "score": 28
      }, {
        "id": 10008,
        "username": "user-8",
        "sex": "男",
        "city": "城市-8",
        "sign": "签名-8",
        "experience": 951,
        "logins": 133,
        "wealth": 16503371,
        "classify": "词人",
        "score": 14
      }, {
        "id": 10009,
        "username": "user-9",
        "sex": "女",
        "city": "城市-9",
        "sign": "签名-9",
        "experience": 484,
        "logins": 25,
        "wealth": 86801934,
        "classify": "词人",
        "score": 75
      }]
    }

    如何转换成layui官方要求的格式?还是说要用第三方的JSON架包

    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 天下孤言 普通会员 1楼

      在Spring Boot中,如果在某个JSON对象上使用了@JsonProperty注解,但是这个对象并没有在配置文件中设置JsonPath属性,那么在后续的代码中,使用这个对象的JsonPath属性将会报错。

      例如,假设我们有一个JSON对象:

      json { "name": "John", "age": 30, "city": "New York" }

      在配置文件中,我们并没有设置JsonPath属性,所以我们需要在控制器方法中添加JsonPath属性来访问这个对象:

      java @PostMapping("/user") public String getUser(@RequestBody User user) { String name = user.getName(); int age = user.getAge(); String city = user.getCity(); // 使用JsonPath属性访问user对象 return "Hello, " + name + ", you are " + age + " years old and you live in " + city; }

      在这个例子中,如果我们直接在方法体中使用user对象的JsonPath属性,那么就会报错:

      java @GetMapping("/user") public String getUser(@RequestBody User user) { String name = user.getName(); int age = user.getAge(); // 使用JsonPath属性访问user对象 return "Hello, " + name + ", you are " + age + " years old and you live in " + user.getCity(); }

      这就是Spring Boot中JsonPath属性的使用问题。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部