做了一个添加信息的demo,用了SpringMVC的form表单 //有一部分数据需要回显 <a href="emp">Add New Employee</a> //对应回显的控制器的方法 @RequestMapping(value="/emp",method = RequestMethod.GET) public String getDepts(Map<String, Object> map) { map.put("departments", departmentDao.getDepartments()); map.put("employee", new Employee()); return "add"; } //添加信息的表单 <center> <h4>添加员工</h4> <form:form action="emp" method="POST" modelAttribute="employee"> <!-- path属性值对应HTML表单标签的name属性值 --> Name:<form:input path="name"/> <br><br> Email:<form:input path="email"/> <br><br> <% Map<String,String> genders = new HashMap<String,String>(); genders.put("0", "Male"); genders.put("1", "Female"); request.setAttribute("genders", genders); %> Gender:<form:radiobuttons path="gender" items="${genders}"/> <br><br> Department:<form:select path="dept" items="${departments}" itemLabel="name" itemValue="id"></form:select> <br><br> <input type="submit" value="点击提交"> </form:form> </center> //对应添加信息控制器的方法 @RequestMapping(value="/emp",method = RequestMethod.POST) public String addEmp(Employee employee) { employeeDao.save(employee); return "redirect:/emps"; }
fullee
相关分类