使用Postman发送模拟请求的时候,Content-Type == application/x-www-form-urlencoded 可以接受到请求,而 Content-Type == application/json 的时候参数获取不到。并且会报错:HTTP Status 400 - Required String parameter ‘xx’ is not present
总结:
application/x-www-form-urlencoded请求是表单请求,可以用@RequestParam一个一个获取参数,当Content-Type == application/json 前端传来的是json串,用@RequestParam是获取不到的,需要用@RequestBody将json串华为对象
参考:
网友评论