gpt4 book ai didi

java - Spring MVC 3.表单选择选项

转载 作者:行者123 更新时间:2023-12-01 14:52:56 25 4
gpt4 key购买 nike

我是 Spring MVC 的新手,我正在尝试从 Controller 获取 jsp 表单选择列表的值。显示选择列表,但它是空的。我尝试了不同的例子等,但仍然找不到问题出在哪里。

Controller :

@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";
}
}

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...
}

提前致谢

最佳答案

看看这个问题。

How to populate dropdown box in Spring MVC

这已经为您提供了答案。

关于java - Spring MVC 3.表单选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14662979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com