Spring mvc 使用thymeleaf访问窗体外部的值
我需要使用thymeleaf和spring获取输入值,但还不能这样做。由于我在控制器中的许多方法中都需要该值,所以我不能将该输入放在其中一个表单中 我尝试使用javascript将值传递给表单中的隐藏输入,但是因为我使用th:each,所以我只得到第一个输入的值 我还尝试向模型中添加一个字符串,然后尝试使用@modeldattribute访问该字符串,但也没有成功 这是html:Spring mvc 使用thymeleaf访问窗体外部的值,spring-mvc,spring-boot,thymeleaf,Spring Mvc,Spring Boot,Thymeleaf,我需要使用thymeleaf和spring获取输入值,但还不能这样做。由于我在控制器中的许多方法中都需要该值,所以我不能将该输入放在其中一个表单中 我尝试使用javascript将值传递给表单中的隐藏输入,但是因为我使用th:each,所以我只得到第一个输入的值 我还尝试向模型中添加一个字符串,然后尝试使用@modeldattribute访问该字符串,但也没有成功 这是html: <tr th:each="pro:${productos}"> <td th:text="
<tr th:each="pro:${productos}">
<td th:text="${pro.id}">id</td>
<!-- More code here omitted for brevity-->
<td>
<div>
<form th:action="@{|/actualizarMas/${pro.id}|}" method="post">
<button type="submit" id="mas">+</button>
</form>
<form th:action="@{|/actualizarMenos/${pro.id}|}" method="post">
<button type="submit" id="menos">-</button>
</form>
<input name="masomenos"/>
<form th:action="@{|/${pro.id}|}" method="post">
<button type="submit">Borrar</button>
</form>
</div>
</td>
</tr>
我需要访问名为“masomenos”的输入,如果可以,我怎么做?如果不能,我有什么选择?除了在所有表单中创建输入之外
非常感谢。看看,它可能会对您有所帮助,您能试试这个吗?它应该在你的标签里谢谢你们两位的建议,实际上另一篇文章很有帮助。我无法解决问题本身,但我能够解决它。请尝试在href
th:attr=“value=${id of the input tag}”
中使用它,它对我有效!!看看吧,它可能对你有帮助,你能试试这个吗?它应该在你的标签里谢谢你们两位的建议,实际上另一篇文章很有帮助。我无法解决问题本身,但我能够解决它。请尝试在hrefth:attr=“value=${id of the input tag}”
中使用它,它对我有效!!
@RequestMapping(value = "/actualizarMenos/{productosId}", method = RequestMethod.POST)
public String eliminarUno(@PathVariable int productosId, RedirectAttributes redirectAttributes, @RequestParam("masomenos") String masomenos) {
//Code here using that string omitted for brevity
return "redirect:/";
}