我是 Spring MVC 的新手,我正在尝试从控制器获取 jsp 表单选择列表的值。选择列表显示,但它是空的。我尝试了不同的示例等,但仍然找不到,问题出在哪里。
控制器:
@Controller
public class MainController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView login() {
return new ModelAndView("login", "command", new Person());
}
@RequestMapping(value = "/", method = RequestMethod.POST)
public String login(@ModelAttribute("xxx")Person person, ModelMap model) {
Map<String,String> list = new LinkedHashMap<String,String>();
list.put("opt1", "value1");
list.put("opt2", "value2");
model.put("list", list);
return "newView";
}
}
新视图.jsp:
<form:form method="POST" action="/xxx/saveUser" command="">
<table>
<tr>
<form:select path="name">
<form:options items="${list}" />
</form:select>
</tr>
</table>
</form:form>
Person.java 模型:
public class Person {
private String name;
//Getters and setters and more values etc...
}
提前致谢