前端ajax:
$.ajax({
url:"http://localhost:8099/createTable",
type:"post",
dataType:"json",
contentType: "application/json", // 这个不要忘记,不加后台接收时会报Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported异常
data:JSON.stringify(list),
success:function(data){
},error:function(data){
}
})
后端接收:
@PostMapping("/createTable")
public Integer createTable(@RequestBody List<String> list) {
sqlList.forEach(System.out::println);
return 1;
}
注意:
前端请求传Json对象则后端使用@RequestParam;
前端请求传Json对象的字符串则后端使用@RequestBody。
参考至:SpringBoot 出现 Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported