报错:
Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]
原因:根据错误信息可以看出,后端接口不支持Content-Type为application/x-www-form-urlencoded;charset=UTF-8的请求头。
解决方法:修改axios.post()方法的请求头为application/json,即将以下代码:
axios.post("/product/update", updateProduct).then((res) => {
this.$message({
message: res.data.message,
type: 'success'
});
})
修改为:
axios.post("/product/update", updateProduct, {
headers: {
'Content-Type': 'application/json'
}
}).then((res) => {
this.$message({
message: res.data.message,
type: 'success'
});
})
也就是在axios.post方法的参数中多加一个请求头属性,这样发送的请求头就是application/json,后端接口应该可以正确解析请求体了。