1.模型
public class User implements Serializable { private Integer deptId; public User() { super(); } …
2.控制器
@RequestMapping("/selectForm") public String selectForm( Model model ) { User user = new User(); //设置deptId的值,页面的select下拉框对应的option项会被选中 user.setDeptId(2); //向model添加user model.addAttribute("user", user); return "selectForm"; }
3.视图
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <form:form method="post" modelAttribute="user" action="register"> <form:select path="deptId"> <form:option value="1">部门1</form:option> <form:option value="2">部门2</form:option> <form:option value="3">部门3</form:option> </form:select> </form:form>