当前位置:网站首页>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 格式返回
边栏推荐
- 2022牛客多校(七)K. Great Party博弈方法证明
- promise详解
- Anroid 组件化构架设计:细说为何需要使用组件化提高工程编译速度
- HPb59-1铅黄铜
- Kioptrix Level 1 靶机wp
- 从Todolist入门Svelte框架
- 浅析工业互联网
- There is no recycle bin for deleted files on the computer desktop, what should I do if the deleted files on the desktop cannot be found in the recycle bin?
- 一条SQL查询语句是如何执行的?
- 矩阵的迹(详解)
猜你喜欢
随机推荐
逮到一个阿里 10 年老 测试开发,聊过之后收益良多...
excel英文自动翻译成中文教程
高性能MySQL核心整理强势来袭
【C语言】初识指针
Mathematical modeling preparation knowledge
关于弱监督学习的详细介绍——A Brief Introduction to Weakly Supervised Learning
sklearn.datasets.make_circles
【C语言篇】表达式求值(隐式类型转换,算术转换)
互联网中不可缺失的网络优化:“App与Server的交互依赖于网络”
[C] the C language program design, dynamic address book (order)
Kioptrix Level 1 靶机wp
[C language] First understanding of pointers
烘干衣服问题
Parse method's parameter list (including parameter names)
mysql数据库高级操作
Excel English automatic translation into Chinese tutorial
HGAME 2022 复盘 writeup
CSAPP lab
[C language] Implementation of guessing number game
HGAME 2022 Final Pokemon v2 writeup