后端接收数据封装成 复杂对象 List 中
// Score 类
// 学生分数
public class Score {
private Integer math;
private Integer english;
// Student 类, 以下省略 getter and setter
// 自动映射等操作的话,肯定是需要 getter and setter
public class Student{
private String name;
private Integer age;
private List<Score> scores;
@RequestBody 注解 将数据封装到复杂对象中 Student stu // Controller 层
@RestController
public class mycontroller {
@RequestMapping(value = "/listuser" , method = RequestMethod.POST)
public Object testRequestList(@RequestBody Student student){
①. 踩小坑
使用 postman 带上 Json 数据请求后端
结果
不知道为什么传的是sorces[i], 但一直是只能接收一条 List -- scores , 而且, 竟然已经赋值上了,那就应该没有映射不对叭,应该是传参的时候出问题了.
②. 把 Json 换成 Row 带来参数
然后接收成功了
List<Student> stus @RestController
public class mycontroller {
@RequestMapping(value = "/listuser" , method = RequestMethod.POST)
public Object testRequestList(@RequestBody List<Student> student){
①. 踩小坑
数组
的形式,不然会报错,如下:
返回信息
控制台 输出 :
at [Source: (PushbackInputStream); line: 1, column: 1]]
②. 这样写