新建maven项目

添加依赖

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

一个User类

public class User {

    private String name;
private int age;
private String address; public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}

一个Controller

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping("/")
public class UserController { @RequestMapping("/testJson")
public User testJson() {
User user = new User();
user.setName("lijia");
user.setAge(27);
user.setAddress("北京");
return user;
} }

一个启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class ApplicationApp { public static void main(String[] args) { SpringApplication.run(ApplicationApp.class, args);
}
}

启动,然后输入http://localhost:8080/testJson

是不是很简单

开始我不知道从哪里下手,真好看到了http://412887952-qq-com.iteye.com/category/356333,准备照着da毕竟有大神带路让我少走很多弯路

2、springboot返回json的更多相关文章

  1. SpringBoot返回JSON

    目录 1.SpringBoot返回JSON简介 2.整合jackson-databind 3.整合Gson 4.整合fastjson 1.SpringBoot返回JSON简介 随着web开发前后端分离 ...

  2. springboot - 返回JSON error 从自定义的 ErrorController

    使用AbstractErrorController(是ErrorController的实现),返回json error. 1.概览 2.基于<springboot - 映射 /error 到自定 ...

  3. springboot 返回json字符串格式化问题

    在idea中yml文件中添加以下注解就可以格式化json字符串效果 spring: jackson: serialization: indent-output: true 原返回json格式为: {& ...

  4. [转] SpringBoot返回json 数据以及数据封装

    作者:武哥     来源:武哥聊编程   https://mp.weixin.qq.com/s/QZk0sKxBX4QZiCTHQIA6pg 1. Spring Boot关于Json的知识点 在项目开 ...

  5. SpringBoot返回json和xml

    有些情况接口需要返回的是xml数据,在springboot中并不需要每次都转换一下数据格式,只需做一些微调整即可. 新建一个springboot项目,加入依赖jackson-dataformat-xm ...

  6. SpringBoot 返回json 字符串(jackson 及 fast json)

      一.jackson 1.Controller 类加注解@RestController 这个注解相当于@Controller 这个注解加 @ResponseBody 2.springBoot 默认使 ...

  7. SpringBoot 返回Json实体类属性大小写问题

    今天碰到的问题,当时找了半天为啥前台传参后台却接收不到,原来是返回的时候返回小写,但是前台依旧大写传参. 查了很多后发现其实是json返回的时候把首字母变小写了,也就是Spring Boot中Jack ...

  8. SpringBoot返回JSON日期格式问题

    SpringBoot中默认返回的日期格式类似于这样: "birth": 1537407384500 或者是这样: "createTime": "201 ...

  9. 【springBoot】springBoot返回json的一个问题

    首先看下面的代码 @Controller @RequestMapping("/users") public class UserController { @RequestMappi ...

  10. SpringBoot返回json格式到浏览器上,出现乱码问题

    在对应的Controller上的requestMapping中添加: @RestController@EnableAutoConfiguration@RequestMapping(value = &q ...

随机推荐

  1. [Swift]多维数组的表示和存储:N维数组映射到一维数组(一一对应)!

    数组:有序的元素序列. 若将有限个类型相同的变量的集合命名,那么这个名称为数组名.组成数组的各个变量称为数组的分量,也称为数组的元素,有时也称为下标变量.用于区分数组的各个元素的数字编号称为下标.数组 ...

  2. springboot 项目中 使用 原型 模式 实现每一次 都获取不同的实例

    直接 上代码:

  3. 安装mysqlclient, 链接mysql失败,提示“Library not loaded: @rpath/libmysqlclient.21.dylib”

    问题: >>> import MySQLdb Traceback (most recent call last): File "<stdin>", l ...

  4. [转] shell逻辑运算总结, 包括[[]]与[]的区别,&&与-a的区别,||与-o的区别

    [From] https://www.cnblogs.com/tony1314/p/8315666.html 1. 关于文件和目录 -f  判断某普通文件是否存在 -d  判断某目录是否存在 -b  ...

  5. dp--hdu1171(01背包)

    hdu1171 题目 Problem Description Nowadays, we all know that Computer College is the biggest department ...

  6. mongo嵌套查询

    db.getCollection('TradeBookingRepresentation').find({uitid:'168282:20190214010009224', tradeVersion: ...

  7. 本地DataGrip连接阿里云MySQL

    1.阿里云上开通MySQL端口 2.MySQL上的设置 1⃣️mysql -uroot -p2⃣️create user 'usrabc'@'%' identified by 'usrabc'; 3. ...

  8. UML-6.1-用例-示例

    1.总览要点:用例.摘要.非正式.详述.测试用例.用例分析与迭代联系起来. 2.示例:Process Sale 1).客户携带所购商品到达收银台. 2).收银员使用pos系统记录每件商品. 操作契约: ...

  9. 2.使用ngx_http_auth_basic_module模块为不带认证的资源添加授权

    1.首先需要生成用户名和密码 使用openssl来生成,生成命令(openssl在安装nginx的时候已经安装) echo "kibana:$(openssl passwd -crypt y ...

  10. linux(ubuntu-16.1) 下安装 odoo10 新版

    1.虚拟机(VMware)中安装 ubuntu-16.1(网络适配器选择桥接模式). 安装成功后,运行 ubuntu 提示 "CPU已被客户机操作系统禁用" 时,需要修改配置文件解 ...