先在pom.xml添加 json 库

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.35</version>
</dependency>

controller :

package com.example.demo.controller;

import com.example.demo.RequestCon;
import com.example.demo.ReturnBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class HomeController { @RequestMapping("/test")
public String Index() { return "1111";
} @RequestMapping("/test2")
public ReturnBody test2(@RequestBody RequestCon req) { ReturnBody rb = new ReturnBody(); try {
rb.code = "server 0";
rb.setMsg(req.msg + " server"); } catch (Exception ex) { rb.setCode("0");
rb.setMsg("ex " + ex.getMessage()); }
return rb;
} }
RequestCon:
package com.example.demo;

public class RequestCon {

    public String code;
public String msg; /**
* @param code the code to set
*/
public void setCode(String code) {
this.code = code;
}
/**
* @return the code
*/
public String getCode() {
return code;
}
/**
* @param msg the msg to set
*/
public void setMsg(String msg) {
this.msg = msg;
}
/**
* @return the msg
*/
public String getMsg() {
return msg;
} }
ReturnBody:
package com.example.demo;

public class ReturnBody {

    public String code;
public String msg; /**
* @param code the code to set
*/
public void setCode(String code) {
this.code = code;
}
/**
* @return the code
*/
public String getCode() {
return code;
}
/**
* @param msg the msg to set
*/
public void setMsg(String msg) {
this.msg = msg;
}
/**
* @return the msg
*/
public String getMsg() {
return msg;
} }

--

post main 测试:

--

springboot maven 收发JSON的更多相关文章

  1. Springboot+ajax传输json数组以及单条数据的方法

    Springboot+ajax传输json数组以及单条数据的方法 下面是用ajax传输到后台单条以及多条数据的解析的Demo: 结构图如下: 下面是相关的代码: pom.xml: <?xml v ...

  2. SpringBoot+Maven 多模块项目的构建、运行、打包实战

    前言 最近在做一个很复杂的会员综合线下线上商城大型项目,单模块项目无法满足多人开发和架构,很多模块都是重复的就想到了把模块提出来,做成公共模块,基于maven的多模块项目,也好分工开发,也便于后期微服 ...

  3. springboot+maven整合spring security

    springboot+maven整合spring security已经做了两次了,然而还是不太熟悉,这里针对后台简单记录一下需要做哪些事情,具体的步骤怎么操作网上都有,不再赘述.1.pom.xml中添 ...

  4. springboot maven项目,为什么build成功,build path也没错误,project-->clean 也没用,项目上面还是有个红x呢?

    springboot maven项目,为什么build成功,build path也没错误,project-->clean 也没用,项目上面还是有个红x呢? 看错误信息有提示:  Descript ...

  5. SpringBoot+Maven 多模块项目的构建、运行、打包

    SpringBoot+Maven 多模块项目的构建.运行.打包 https://blog.csdn.net/zekeTao/article/details/79413919

  6. java springboot+maven发送邮件

    springboot+maven发送邮件 废话不多说直接上代码 1. pom 文件导入jar包 <!--邮件发送--> <dependency> <groupId> ...

  7. 工具IDEA 配置springboot+maven项目

    工具IDEA 配置springboot+maven项目 首先安装IDEA,至于怎么安装就不介绍了.. 第一步 配置maven环境 首先安装maven,先在网上下载一个maven包.在IDEA的sett ...

  8. springboot+maven——打war包方式

    转载 Springboot打包war包部署到自己的tomcat中 一.springboot+maven工程——打war包步骤如下: 1.修改父pom.xml文件: <packaging>p ...

  9. 转 使用Docker部署 spring-boot maven应用

    转自:https://blog.csdn.net/u011699931/article/details/70226504/ 使用Docker部署 spring-boot maven应用 部署过程分为以 ...

随机推荐

  1. git 在 A 项目中引用 B 项目

    git 在 A 项目中引用 B 项目   场景: 需要在项目calcDLL(http://XXX/XXXA.git) 中 引用 项目libindex(http://XXX/XXXB.git). 解决方 ...

  2. linux 文件解压缩

    转载 https://blog.csdn.net/qq_27803491/article/details/52785838 01-.tar格式 解包:[*******]$ tar xvf FileNa ...

  3. (21)打鸡儿教你Vue.js

    组件化思想: 组件化实现功能模块的复用 高执行效率 开发单页面复杂应用 组件状态管理(vuex) 多组件的混合使用 vue-router 代码规范 vue-router <template> ...

  4. Ceph osd故障恢复

    1  调高osd的日志等级 加上红框那一行就可以了 osd的日志路径:/var/log/ceph/ceph-osd.3.log 注意:加上了这一行后日志会刷很多,所以要特别注意日志容量的变化,以防把v ...

  5. ORA-01578: ORACLE 数据块损坏 (文件号 13, 块号 2415081) ORA-01110: 数据文件XXXXXX

    1.使用DBV检查数据文件,在cmd执行:dbv file='E:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF' blocksize=8192:然后等待检测结 ...

  6. vue中全局filter和局部filter怎么用?

    需求: 将价值上加上元单位符号(全局filter) <template> <div> 衣服价格:{{productPrice|formatTime}} </div> ...

  7. css自定义属性和简单效果

    简介 CSS Variables,一个并不是那么新的东西,但对css来说绝对是一场革命. 之前使用变量的时候,需要借助sass.less等预处理工具来实现,现在我们可以直接使用css来声明变量. 兼容 ...

  8. V语言 基本使用

    新手必看-如何安装配置vlang运行环境(linux,macOS篇) 前置条件 发稿截止前只有Linux 或者 macOS系统能编译通过. 你需要安装clang或gcc 如果是macOS上需运行xco ...

  9. mysql group by 报错 ,only_full_group_by 三种解决方案

    报错信息  Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'data ...

  10. Chapter Two

    Web容器配置 ~Tomcat配置 server.port配置了Web容器的端口号 error.path配置了当项目出错时跳转去的页面 session.timeout配置了session失效的时间 c ...