Use axios to request the method of the interface annotated with @DeleteMapping

The front-end uses the delete method to access the interface, the back-end uses the @DeleteMapping annotation, and the method uses @PathVariable to receive parameters. Pay attention to the usage of: /{id} in the annotation.

后端接口:
// 根据ID删除用户
@DeleteMapping("/api/deleteUserById/{id}")
@ResponseBody
public String deleteUserById(@PathVariable("id") Integer id) {
    int rowsDeleted = userMapper.deleteUserById((long)id);
    if (rowsDeleted > 0) {
        return "数据删除成功!";
    } else {
        return "数据删除失败!";
    }
}

Front-end interface:
axios.delete('http://127.0.0.1:8080/api/deleteUserById/'+id)
.then(response => { // Processing successful response console.log('Delete successfully', response); }) .catch(error => { // Handle error response console.error('Deletion failed', error); });






Qiu Feng wrote in Zibo, Java learning notes. Since I am a novice in Java, experts are welcome to criticize and correct me!

Guess you like

Origin blog.csdn.net/hmwz0001/article/details/131914682