我有一个模块,我必须更新每个学生的出勤率。代码如下:
public void updateDailyAttendance(ActionRequest areq, ActionResponse aRes) throws Exception{
int totalEmployees = EmployeeLocalServiceUtil.getEmployeesCount();
String attendanceValue = getAttendanceValue(areq);
//long attPKey = CounterLocalServiceUtil.increment(Employee.class.getName());
for (int i = 0; i < totalEmployees; i++) {
// use attendanceValue to update employee entry
//String attendanceValue = getAttendanceValue(areq);
// parameterValue is value of radio button parameter
long attPKey = CounterLocalServiceUtil.increment(Employee.class.getName());
Attendance newAttendanceInstance = new AttendanceImpl();
newAttendanceInstance.setAttId(attPKey);
newAttendanceInstance.setAttStatus(attendanceValue);
AttendanceLocalServiceUtil.addAttendance(newAttendanceInstance);
} }
private String getAttendanceValue(ActionRequest areq) {
Enumeration parameters = areq.getParameterNames();
while (parameters.hasMoreElements()) {
String parameterName = parameters.nextElement().toString();
if (parameterName.startsWith("updateattendance")) {
return areq.getParameter(parameterName);
}
}
throw new IllegalStateException("Parameter updateattendance cannot be found!!");
}
当我使用上面的代码时,我的数据库得到更新,但出勤(为第一位员工输入的出席/缺席被视为其他员工的值,即使我为其他员工标记了不同的值(出席/缺席)
我应该如何修改上面的代码,以便存储为每个员工输入的单选按钮值?