如何将选定的下拉值传递给 Thymeleaf 中的控制器? [英] How do I pass the selected dropdown value to a controller in Thymeleaf?
本文介绍了如何将选定的下拉值传递给 Thymeleaf 中的控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将下拉列表(Thymeleaf)的选中值传递给控制器(Spring)?列表本身形成正常,问题出在按钮上.
控制器:
@RequestMapping(value="courier/notInTime", method = RequestMethod.POST)公共字符串删除用户(@RequestParam 字符串任务){System.out.println(任务);返回重定向:/快递";}
查看:
<select class="form-control" id="courierTasks" name="courierTasks"><option value="">选择禁用任务</option><option th:each="task : ${tasks}"th:value="${task}"th:text="${task}"></选项></选择><form th:action="@{/courier/notInTime}" method="post"><输入类型=隐藏"/><button type="submit">不及时</button></表单>
解决方案
@Sopheak @Ioannis many thx.
控制器:
@RequestMapping(value="courier/notInTime", method = RequestMethod.POST)public String deleteUser (@Valid String 任务) {System.out.println(任务);返回重定向:/快递";}
查看:
How to transfer the selected value of the drop-down list (Thymeleaf) to the controller (Spring)? The list itself is formed normally, the problem is in the button.
Controller:
@RequestMapping(value="courier/notInTime", method = RequestMethod.POST)
public String deleteUser (@RequestParam String task) {
System.out.println(task);
return "redirect:/courier";
}
View:
<div class="taskList" th:object="${task}">
<select class="form-control" id="courierTasks" name="courierTasks">
<option value="">Select task for disable</option>
<option th:each="task : ${tasks}"
th:value="${task}"
th:text="${task}">
</option>
</select>
<form th:action="@{/courier/notInTime}" method="post">
<input type="hidden"/>
<button type="submit">Not in time</button>
</form>
</div>
解决方案
@Sopheak @Ioannis many thx.
Controller:
@RequestMapping(value="courier/notInTime", method = RequestMethod.POST)
public String deleteUser (@Valid String task) {
System.out.println(task);
return "redirect:/courier";
}
View:
<form th:action="@{/courier/notInTime}" method="post">
<select class="form-control" id="task" name="task">
<option value="">Select task for disable</option>
<option th:each="task : ${tasks}"
th:value="${task}"
th:text="${task}">
</option>
</select>
<button type="submit">Not in time</button>
</form>
这篇关于如何将选定的下拉值传递给 Thymeleaf 中的控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文