春天& Thymeleaf形式

时间:2017-05-20 12:49:28

标签: spring thymeleaf

当我只有一个这样的对象时,

在表单中添加是微不足道的:

        <form th:action="|#{group/save}/${id}|" th:object="${groupForm}" method="post" class="col m8 s8 offset-m2">

            <div class="row">
                <div class="input-field">
                    <input th:field="${groupForm.name}" id="name" type="text" required="required"/>
                    <label for="name">Nazwa:</label>
                </div>
            </div>

            <div class="row">
                <button class="btn-success" type="submit" name="save">Wyślij<i class="mdi-content-send right"></i></button>
            </div>
        </form>

但我们假设groupForm有客户列表

public class Customer{
    private long id;
    private String firstName;
    private String lastName;
    private String nick;
}

如何将5个客户添加到班级组的列表中?我想在一个请求中实现。

1 个答案:

答案 0 :(得分:0)

假设您的Group类看起来像这样:

public class Group {
    private List<Customer> customers;
}

试试这个:

<input th:field="*{customers[0].name}" type="text" required="required"/>
<input th:field="*{customers[1].name}" type="text" required="required"/>
<input th:field="*{customers[2].name}" type="text" required="required"/>
<input th:field="*{customers[3].name}" type="text" required="required"/>
<input th:field="*{customers[4].name}" type="text" required="required"/>