后端代码
// 删
@DeleteMapping("/delete/{id}")
@ResponseBody
public String delete(@PathVariable("id") Integer id){
boolean b = saleService.removeById(id);
if (b){
return "删除成功";
}else {
return "删除失败";
}
}
前端代码
//删除
del:function (id){
axios.delete('/sale/delete/'+id) //切记这里是特定delete方法
.then(function (response) {
window.location.reload(); //刷新当前页面
})
.catch(function (error) {
// console.log(error.data);//undefined,之前以为这样可以拿到错误信息
// console.log(error.response.data.rentCarTime);//可以拿到后端返回的信息
});
},