【springboot】springboot传入JSON对象参数

前言:

在使用springboot 传入JSON对象参数时,需要注意以下几点。

  1. 请求参数格式必须是正确的JSON。

  2. 在入参中使用注解@RequestBody,用于接收JSON参数,使其自动转对象

  3. 标识请求参数的格式为JSON—>> @PostMapping(value="/Test",produces = "application/json;charset=UTF-8")

具体实现

1.后端代码

@RestController
@RequestMapping("/Test")
public class TestController {
    
    @PostMapping(value="/Test",produces = "application/json;charset=UTF-8")
    public ContentSet Test(@RequestBody Student student){
 
        return null;
    }
}

2.实体类代码

@Getter
@Setter
@ToString
public class Student {
 
    private String name;
    private int age;
 }

3.PostMan模拟请求

  1. 添加header 信息。
    在这里插入图片描述

  2. 模拟数据
    在这里插入图片描述

完成!

posted @ 2022-11-10 19:25  彬在俊  阅读(424)  评论(0)    收藏  举报