Vue中axios傳送GET, POST, DELETE, PUT四種非同步請求,引數攜帶和接收問題

web.xml配置如下



1、GET請求

傳送GET請求:

<!--params是關鍵字,說明所攜帶的引數,json格式引數-->
axios.get('/edit.do', {params: {id: value}})
.then((response) => {
//TODO
})

Controller接收GET請求:

@GetMapping("/edit")
public Result edit(Integer id){
//TODO
}

2、POST請求

傳送POST請求:

var params = {
currentPage: this.pagination.currentPage, //當前頁碼
pageSize: this.pagination.pageSize, //頁面大小
queryString: this.pagination.queryString //搜尋條件
}
<!--POST請求第二個引數,可直接攜帶json格式的引數-->
axios.post('/findPage.do', params)
.then(response => {
//TODO
})

Controller接收POST請求:

public class QueryPageBean implements Serializable {
private Integer currentPage;//頁碼
private Integer pageSize;//每頁記錄數
private String queryString;//查詢條件
} @PostMapping("/findPage")
public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
//TODO
}

3、DELETE請求

傳送DELETE請求:

<!--DELETE請求第二個引數,可攜帶多個json格式的引數,但需要params作為json引數的關鍵字-->
axios.delete('/delete.do', {params: {id: value}})
.then((response) => {
//TODO
})

Controller接收DELETE請求:

@DeleteMapping("/delete")
public Result delete(Integer id){
//TODO
}

4、PUT請求

傳送PUT請求:

<!--PUT請求第二個引數,可直接攜帶json格式的引數-->
axios.put('/update.do', {name:userName,age:userAge,address:userAddress})
.then((response) => {
//TODO
})

Controller接收PUT請求:

public class User implements Serializable {
private String name;
private Integer age;
private String address;
} @PutMapping("/update")
public Result update(@RequestBody User user){
//TODO
}