1 回答

TA贡献1806条经验 获得超8个赞
由于您的方法提前返回,因此只有一条记录被删除。要解决此问题,请创建一个布尔变量以返回方法控制,而不是返回 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;
}
添加回答
举报