This time I will bring you the problem that springmvc cannot accept parameters when axios sends a request, and springmvc cannot accept parameters when axios sends a request. What are the precautions?The following is a practical case, let's take a look one time.
There are three solutions:
1. Set the default request header of axios
//设置全局的 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; var instance = axios.create({}) // 这样创建出来的 只需要: instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
2. Use URLSearchParams to construct parameters
var params = new URLSearchParams(); params.append("username", _this.username); params.append("password", _this.password); axios.post("/service/login", paramsOfJson ).then(function (response) { console.log(response); }).catch(function (error) { console.log(error); })
3. Use @requestBody in the background to receive
@PostMapping(value = "/login") public String testLogin(@RequestBody Map dataMap)
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Detailed explanation of the use of js data types
What is the difference between method and computed in Vue
The above is the detailed content of springmvc cannot accept parameters when axios sends request. For more information, please follow other related articles on the PHP Chinese website!