在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ 前臺(tái)傳json對(duì)象數(shù)組,java后臺(tái)用List接受時(shí)報(bào)錯(cuò)

前臺(tái)傳json對(duì)象數(shù)組,java后臺(tái)用List接受時(shí)報(bào)錯(cuò)

spring 項(xiàng)目中的controller是不是不能直接接受對(duì)象類型的List為入?yún)??為什么?找了很多相關(guān)文檔,都說不行,要不就傳一個(gè)vo類,vo類里面有l(wèi)ist,要不就傳字符串,后臺(tái)解析字符串

spring boot 項(xiàng)目:

public class Tag {

int id;



String name;

此處省略了get,set

}

@RestController

public class HelloController {

@RequestMapping(value = "add", consumes = "application/json; charset=utf-8")

public String add(@RequestBody List<Tag> param) {

   System.out.println("param:" + param);

   return "成功";

}

}

commit(){

$.ajax({

    type:"post",

    url: 'add',

    contentType:"application/json; charset=utf-8",

    dataType:"json",

   data:{

       param:JSON.stringify([{id:1,name:'hello'},{id:2,name:'hello'}])

   },

   success:function(data){

       console.log(data);

   }

})

}

后臺(tái)報(bào)錯(cuò)信息:

2018-01-29 13:52:57.856 WARN 3148 --- [nio-8088-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized token 'param': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'param': was expecting ('true', 'false' or 'null')

回答
編輯回答
笨尐豬

data:JSON.stringify([{id:1,name:'hello'},{id:2,name:'hello'}])

2018年6月12日 23:46