Home > Web Front-end > JS Tutorial > body text

axios sends post request springMVC cannot accept parameters how to handle

php中世界最好的语言
Release: 2018-04-12 11:35:45
Original
2440 people have browsed it

This time I will bring you axios to send post request springMVCHow to handle parameters that cannot be accepted, and solve the problem of axios sending post request springMVC cannot accept parametersNote What are the matters? Below are practical cases. Let’s take a look.

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';
Copy after login

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);
   })
Copy after login

3. Use @requestBody in the background to receive

@PostMapping(value = "/login")
public String testLogin(@RequestBody Map dataMap)
Copy after login

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:

How node.js implements network requests through axios

springmvc cannot accept parameters when axios sends a request

The above is the detailed content of axios sends post request springMVC cannot accept parameters how to handle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template