做了一个添加信息的demo,用了SpringMVC的form表单
//有一部分数据需要回显
Add New Employee
//对应回显的控制器的方法
@RequestMapping(value="/emp",method = RequestMethod.GET)
public String getDepts(Map map) {
map.put("departments", departmentDao.getDepartments());
map.put("employee", new Employee());
return "add";
}
//添加信息的表单
添加员工
Name:
Email:
Map genders = new HashMap();
genders.put("0", "Male");
genders.put("1", "Female");
request.setAttribute("genders", genders);
%>
Gender:
Department:
itemValue="id">
//对应添加信息控制器的方法
@RequestMapping(value="/emp",method = RequestMethod.POST)
public String addEmp(Employee employee) {
employeeDao.save(employee);
return "redirect:/emps";
}