所以我有一个带有图像类型输入的表单,此表单中有7张图像,每个图像都有一个具有不同值的变量,我想将此变量传递给带有@PostMapping批注的controller方法,该怎么做?以及如何仅使用一种控制器方法来制作它?
// the form
<table>
<form th:action="@{/home/lab}" method="post">
<tr>
<td>
<div>
<center>
<input type="image" class="cornered-img" th:src="@{/images/labs/test1.png}" name="lab" value="test1" >
</center>
</div>
</td>
<td>
<div>
<center>
<input type="image" class="cornered-img" th:src="@{/images/labs/test2.png}" name="lab" value="test2">
</center>
</div>
</td>
<td>
<div>
<center>
<input type="image" class="cornered-img" th:src="@{/images/labs/test3.png}" name="lab" value="test3">
</center>
</div>
</td>
</tr>
<tr>
<td>
<div>
<center>
<input type="image" class="cornered-img" th:src="@{/images/labs/test4.png}" name="lab" value="test4">
</center>
</div>
</td>
<td>
<div>
<center>
<input type="image" class="cornered-img" th:src="@{/images/labs/test5.png}" name="lab" value="test5">
</center>
</div>
</td>
<td>
<div>
<center>
<input type="image" class="cornered-img" th:src="@{/images/labs/test6.png}" name="lab" value="test6">
</center>
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<div>
<center>
<input type="image" class="cornered-img" th:src="@{/images/labs/test7.png}" name="lab" value="test7">
</center>
</div>
</td>
<td>
</td>
</tr>
</form>
</table>
// the controller
@PostMapping("/lab")
public String toLab(@ModelAttribute("user") User user, String lab, Model model){
log.info(lab);
model.addAttribute("lab", lab);
return "redirect:/lab";
}
控制器中的参数“ lab”为空。