我在jsp中创建了可编辑的表,它从数据库中显示整个表,并且在我得到的最后一列旁边"编辑"更新特定行的按钮。问题是点击"编辑"编辑的行不想更新,任何错误都出现在控制台中。我做错了什么?
控制器:
@RequestMapping(value="/employeelist.html", method = RequestMethod.POST)
public ModelAndView editOrDeleteEmployee(Model model, @ModelAttribute("employee") Employee employee, @RequestParam String editEmployee) throws SQLException{
setAppContext();
clinicService.updateEmployee(employee, "2");
List<Employee> employees = clinicService.getAllEmployees();
model.addAttribute("employees", employees);
ModelAndView mstaff = new ModelAndView("EmployeeList");
return mstaff;
}
DAO:
public void updateEmployee(Employee employee, String id) {
String query = "update virtualclinic.employee SET name=?, lastname=?, gender=?,"
+ "position=?, salary=?, phonenumner=?, address=? WHERE idemployee=?";
Connection con = null;
PreparedStatement ps = null;
try{
con = dataSource.getConnection();
ps = con.prepareStatement(query);
ps.setString(1, employee.getName());
ps.setString(2, employee.getLastName());
ps.setString(3, employee.getGender());
ps.setString(4, employee.getPosition());
ps.setString(5, employee.getSalary());
ps.setString(5, employee.getPhoneNumber());
ps.setString(6, employee.getAddress());
ps.setString(7, employee.getId());
id = employee.getId();
int out = ps.executeUpdate();
}catch(SQLException e){
e.printStackTrace();
}
服务:
public void updateEmployee(Employee employee, String id) {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("clinicconfig.xml");
employeeDAO = ctx.getBean("employeeDAO", EmployeeDAOImpl.class);
employee.setName(employee.getName());
employee.setLastName(employee.getLastName());
employee.setGender(employee.getGender());
employee.setPosition(employee.getPosition());
employee.setSalary(employee.getSalary());
employee.setPhoneNumber(employee.getPhoneNumber());
employee.setAddress(employee.getAddress());
employee.setId(employee.getId());
id = employee.getId();
employeeDAO.updateEmployee(employee, id);
}
JSP文件:
<c:forEach items="${employees}" var="employee">
<tr style="font-size: 10">
<td>${employee.id}</td>
<td><div contentEditable='true'>${employee.name}</div></td>
<td><div contentEditable='true'>${employee.lastName}</div></td>
<td><div contentEditable='true'>${employee.gender}</div></td>
<td><div contentEditable='true'>${employee.position}</div></td>
<td><div contentEditable='true'>${employee.salary}</div></td>
<td><div contentEditable='true'>${employee.phoneNumber}</div></td>
<td><div contentEditable='true'>${employee.address}</div></td>
<td><form action="/VirtualClinic/employeelist.html?editEmployee=${employee.id}" method="POST"><input type="submit" value="Edit"/></form></td>
</tr>
</c:forEach>