javaWeb deleted and a plurality of data

First, write dao

// Delete The ID 
@Delete ( "Delete from Product ID WHERE ID = # {}")
public void Delete (ID Integer);
two, and write a service implementation class
// delete a single 
public void Delete (ID Integer);
// delete multiple
public void deletes (Integer [] ids );

@Override 
public void Delete (Integer ID) {

productDao.delete (ID);
}
// delete a plurality of data according to the ID
public void Deletes (Integer [] IDS) {
IF (IDS = null!) {
For (Integer ID: IDS ) {
productDao.delete (ID);
}
}
}
Third, the write controller controller
// delete a data 
@RequestMapping ( "/ Delete")
public String Delete (Integer ID) {
productService.delete (ID);
return "the redirect: findByProduct";
}
// delete a plurality of data
@RequestMapping ( "/ deletes")
String Deletes public (Integer [] IDS) {
productService.deletes (IDS);
return "redirect: findByProduct"; (redirect page refresh)
}

Fourth, writing web documents
<button type="button" class="btn btn-default" title="删除"
onclick='deletes()'>
<i class="fa fa-trash-o"></i> 删除
</button>
<form ID = "delForm" Action = "$ {} pageContext.request.contextPath / Product / Deletes" Method = "POST"> 
... (herein, within the form table column name is omitted)
<Td> <input name = "ids" type = "checkbox" value = "$ {product.id}"> </ td> (checkbox value box will go to the value, for a plurality of ID according to the value obtained by deleting the )
... (omitted where the data in the table form corresponding to the columns)
<Button type = "button" class = "btn bg-olive btn-xs" onclick = 'delOne ($ {product.id})'> Delete </ button> (delete individual data)
</from>
<Script of the type = "text / JavaScript"> 
// delete a single
function DeLone (the above mentioned id) {
IF (Confirm The ( "Are you sure you want to do ????")) {
// delete
location.href = "$ {pageContext ? .request.contextPath} / Product / the delete the above mentioned id = "+ the above mentioned id;
}
}
function deletes () {
IF (Confirm The (" Are you sure you want to do ???? ")) {
var delForm = $ (" # delForm " );
delForm.submit ();
}
}
</ Script>

Guess you like

Origin www.cnblogs.com/zhangrongfei/p/11231668.html