当前位置:网站首页>12. 处理 JSON
12. 处理 JSON
2022-08-10 23:35:00 【要学就学灰太狼】
12.1 需求说明:演示返回 JSON 格式数据
12.2 应用实例
- SpringBoot 支持返回 JSON 格式数据,在启用 WEB 开发场景时,已经引入了相关依赖
- 创建 D:\xjs_springboot\springbootweb\src\main\java\com\xjs\springboot\controller\ResponseController.java
package com.xjs.springboot.controller;
import com.xjs.springboot.bean.Car;
import com.xjs.springboot.bean.Monster;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
/** * @Author: 谢家升 * @Version: 1.0 */
@Controller
public class ResponseController {
//编写方法,返回Monster数据-要求以json格式返回
@GetMapping("/get/monster")
@ResponseBody
public Monster getMonster() {
/** * 解读: * 1. 开发中 这里的 monster对象 是从数据库中获取的 * 2. 这里只是模拟一下,人为的设置一下数据 */
Monster monster = new Monster();
monster.setId(100);
monster.setName("霸波奔");
monster.setAge(99);
monster.setBirth(new Date());
monster.setIsMarried(false);
Car car = new Car();
car.setName("宝马");
car.setPrice(666.6);
monster.setCar(car);
return monster;
}
}
- Postman 完成测试
- Debug 一下 monster 对象以 Json 格式返回
边栏推荐
- 22年全国程序员1月薪资出炉,才知道年薪 40 万以上的有这么多?
- XSLeaks side channel attack (unfinished)
- Tencent Cloud Lightweight Application Server Configuration and Website Building Tutorial
- CSAPP lab1 DataLab
- ASIO4ALL是什么
- Talk预告 | 中国科学技术大学和微软亚洲研究院联合培养博士生冷燚冲:语音识别的快速纠错模型FastCorrect
- 【C语言】初识指针
- Flink(Pometheus监控)
- HGAME 2022 复盘 writeup
- 线程池如何监控,才能帮助开发者快速定位线上错误?
猜你喜欢
随机推荐
App基础优化三部曲:启动原理&黑白屏优化&启动时间优化
DASCTF X SU 2022 writeup
Doris建表注意事项,实时数仓的同学记得收藏
【C语言】C语言程序设计:动态通讯录(顺序表实现)
Blue Hat Cup 2022 web/misc writeup
C194铜合金C19400铁铜合金
ROS Experiment Notes - Validation of UZH-FPV Dataset
服务器小常识
ROS实验笔记之——UZH-FPV数据集的验证
Which translation software is more accurate [Free]
SAS数据处理技术(一)
Promote the high-quality development of denim clothing
线程相关知识点
C语言%(%d,%c...)
Microsoft: Into Focus with Scott Guthrie Scott Hanselman Rajesh Jha and Kevin Scott | KEY11
Deep Learning Transformer Architecture Analysis
【C语言】数据储存详解
祥云杯 2021 PackageManager writeup
【C语言篇】操作符之 位运算符详解(“ << ”,“ >> ”,“ & ”,“ | ”,“ ^ ”,“ ~ ”)
CSAPP lab0 实验环境搭建