做如下操作:
1. 删除:将数据库name,表name,id发后端 删除之前先备份
先在后端将需要的name什么的传回来
2. 保留:一条notify
Delete(){
this.dialogDelete=true
},
ConfirmSave(){
this.dialogVisible=false
this.dialogVisibleQingxi=false
this.dialogDelete=false
this.$notify({
title: '保留成功',
message: '保留成功',
type: 'success'
});
},
Save(){
this.dialogVisible=false
this.dialogVisibleQingxi=false
this.$notify({
title: '保留成功',
message: '保留成功',
type: 'success'
});
},
前端的发送:
ConfirmDelete(){
// 这里获取id反正用axios
let params =new URLSearchParams()
params.append('dbname',this.tableData4.dbName)
params.append('dbid',this.dbid)
params.append('chartname',this.tableData4.chartName)
params.append('ids',this.tableData4.ids)
axios.post('api/DeleteZhengze',params).then(res=>{
if(res.data==1){
this.$notify({
title: '删除且备份成功',
message: '删除且备份成功',
type: 'success'
});
this.dialogVisible=false
this.dialogVisibleQingxi=false
this.dialogDelete=false
}
},)},
备份+删除
public void deleteZhengze(String Dbname, String ChartName, String[] ids) throws SQLException {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/"+Dbname;
String user = "root";
String password = "sherlock2218";
for(int i=0;i<ids.length;i++){
Connection connection=null;
try{
Class.forName(driver);
connection = DriverManager.getConnection(url, user, password);
String sql="delete from "+ChartName+" where id = " + ids[i];
PreparedStatement statement = connection.prepareStatement(sql);
int resultSet = statement.executeUpdate();
System.out.println(resultSet);
}catch (ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e){
e.printStackTrace();
}
connection.close();
}
}
拓展:选择行进行删除--如何实现?能知道这一行的所有信息,可以使用对应id删除法