Java将接收json参数转换为对象、列表

在实际开发中,有时候需要将请求体body中的json参数转换为我们可以在后端直接使用的对象或者列表。方法如下:

@PostMapping("/modifyStudent")
    public void modifyStudent(@RequestParam("student") String student,
                                     @RequestParam("studentList") String studentList
    ) {
    
    
    	//将接收的json转换为Student对象
        Student stu = JSON.parseObject(student, Student.class);
        //将接收的json转换为list
        List<Student> stuList = JSONObject.parseArray(studentList, Student.class);
        
    }

おすすめ

転載: blog.csdn.net/weixin_44123540/article/details/118488732