1 回答

TA貢獻1806條經驗 獲得超8個贊
由于您的方法提前返回,因此只有一條記錄被刪除。要解決此問題,請創(chuàng)建一個布爾變量以返回方法控制,而不是返回 true/false,同時將長度減 1 以避免 ArrayIndexOutOfBoundsException。這是可能對您有所幫助的代碼片段
@RequestMapping(value = "/delete_all", method = RequestMethod.POST)
@ResponseBody
public boolean deleteMultipleRecord(@RequestParam(value = "empList[]", required = false) String[] empListToBeRemoved, HttpServletRequest request) {
Employee emp = new Employee();
for (int i = 0; i <= empListToBeRemoved.length-1; i++) {
boolean result = false;
if (!empListToBeRemoved[i].equals("0")) {
emp.setEmpIdEnc(empListToBeRemoved[i]);
try {
List<OrgStructureTagging> list = orgStructureTaggingDAO.findEmpByProperty("EMP_ID", emp.getEmpId());
for (OrgStructureTagging structureTagging : list) {
System.out.println("all ids of employees" + structureTagging.getEmployee().getName());
orgStructureTaggingDAO.delete(structureTagging);
}
result = true;
} catch (Exception e) {
e.printStackTrace();
log.error("Error Occured While updating the field");
result = false;
}
}
}
return result;
}
添加回答
舉報