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

鍍金池/ 問答/Java  HTML/ java spring項目,controller能否直接接受對象類型的List為

java spring項目,controller能否直接接受對象類型的List為入?yún)ⅲ?/h1>

spring boot 項目:

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);

   }

})

}

后臺報錯信息:

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"}]),

2017年5月2日 23:35