使用百里香叶获取外部形式的价值

时间:2017-10-26 04:53:13

标签: spring-mvc spring-boot thymeleaf

我需要获得使用百里香和春天的输入值,但是还没有能够这样做。由于我需要在控制器中的许多方法中使用该值,因此我无法将该输入放在其中一个表单中。

我尝试使用javascript将值传递给表单中的隐藏输入,但是因为我使用th:每个我只获得第一个输入的值。

我还尝试在模型中添加一个字符串,然后尝试使用@ModelAttribute访问该字符串,但它也没有锻炼。

这是html:

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

这是控制器:

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

我需要使用名称&#34; masomenos&#34;来访问输入,如果这是可行的,我怎么能这样做?如果没有,我有什么选择?除了在所有表格中创建输入外。

非常感谢。

0 个答案:

没有答案