gpt4 book ai didi

java - Spring MVC 多选列表框值无法返回 Controller

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

我在jsp中有一个多选列表框,并且该值无法返回到 Controller 。但其他领域工作得很好。

我已经尝试过从List或String[]中搜索Form类中的选项类型,但仍然没有数据返回。

代码如下: Controller :

@RequestMapping(value ="/test", method = RequestMethod.POST)
public void test(@ModelAttribute("searchForm") Search searchForm, HttpServletRequest request, HttpServletResponse response){
List<String> options = (List)searchForm.getOptions();
}

表格:

Public class Search{
private List<String> options;

}

JSP:

<select id="options" name="options" multiple="multiple">
<option value="1">option1</option>
<option value="2">option2</option>
<option value="3">option3</option>
</select>

有什么建议吗?

最佳答案

在您的 JSP 中,使用 spring 表单标记进行一些修改。

<form:form method="post" action="test" modelAttribute="search">
<form:select multiple="true" path="options">
<form:options items="${options}" />
</form:select>

<input type="submit" name="addOptions" value="Add Options">
</form:form>

我在 github 上有示例选择框项目,我也添加了多选选项。你自己看一下就知道了:https://github.com/jama707/SpringSelectBoxSample

关于java - Spring MVC 多选列表框值无法返回 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27054216/

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