当前位置:网站首页>12. Handling JSON
12. Handling JSON
2022-08-10 23:49:00 【If you want to learn, learn Big Wolf】
12.1 需求说明:demo back JSON 格式数据
12.2 应用实例
- SpringBoot 支持返回 JSON 格式数据,在启用 WEB when developing the scene,Dependencies have been introduced
- 创建 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. 这里只是模拟一下,Set the data artificially */
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 格式返回
边栏推荐
猜你喜欢
随机推荐
How to determine how many bases a number is?
Promote the high-quality development of denim clothing
缓存知识总结
Kioptrix Level 1 靶机wp
7. yaml
Kubernetes 选举机制HA
宝塔实测-搭建PHP在线模拟考试系统
【C语言】C语言程序设计:动态通讯录(顺序表实现)
How to recover deleted files from the recycle bin, two methods of recovering files from the recycle bin
进程和线程
图片懒加载(纯手写)
Is there a way out in the testing industry if it is purely business testing?
Timers, synchronous and asynchronous APIs, file system modules, file streams
Unity--URP渲染管线实战教程系列之URP摄像机核心机制剖析
祥云杯 2021 PackageManager writeup
【C语言】数据储存详解
HGAME 2022 Week2 writeup
PyTorch官方文档学习笔记(备忘)
【ORACLE】什么时候ROWNUM等于0和ROWNUM小于0,两个条件不等价?
HCTF 2018 WarmUP writeup