The code copy is as follows:
function deleteAll() {
var all = document.getElementsByName("checkname");//Get the content you selected is an array
if (all == null || all.length == 1) {
alert("No order yet");
return;
} else {
var idStr = "";//Define a string of the id you want to delete
for ( var i = 0; i < all.length; i++) {
if (all[i].checked) {
idStr += all[i].value + ",";//Connect ids with commas and separate them
}
}
var result = confirm("Select Delete");
if (result) {
window.location.href = "deleteOrderAction?action=deleteAll&idStr="
+ idStr;
} else {
return null;
}
}
}
</script>
Finally, business processing
The code copy is as follows:
String[] arr = idStr.split(",");//The array of id strings will be obtained using comma split to obtain each id
for (String str : arr) {
int orderid = Integer.parseInt(str);
OrderService.deleteOrder(orderid);
}
Summary: The operation of deleting and clearing all is the process of splicing and splitting strings.