Twitter bootstrap 3 使用Spring Boot&;编辑表格数据;百里香

Twitter bootstrap 3 使用Spring Boot&;编辑表格数据;百里香,twitter-bootstrap-3,thymeleaf,Twitter Bootstrap 3,Thymeleaf,我还在学习Thymeleaf、Bootstrap和JQuery,请原谅我的无知。我有一个spring boot应用程序,它的UI是Thymeleaf和Bootstrap。我有一个在表中显示的用户列表,并希望对其进行编辑。我目前的想法是,用户可以选择行上的图标,并将该记录填充到一个模式对话框表单中,在该表单中可以通过调用进行更新。我不确定这是否是最好的,但这就是我现在的处境 <div class="modal-body"> <form cl

我还在学习Thymeleaf、Bootstrap和JQuery,请原谅我的无知。我有一个spring boot应用程序,它的UI是Thymeleaf和Bootstrap。我有一个在表中显示的用户列表,并希望对其进行编辑。我目前的想法是,用户可以选择行上的图标,并将该记录填充到一个模式对话框表单中,在该表单中可以通过调用进行更新。我不确定这是否是最好的,但这就是我现在的处境

        <div class="modal-body">
            <form class="form-horizontal bv-form" action="addUser" th:action="@{/addUser}" th:object="${user}" method="put" id="loginForm">
                <div class="form-group">
                    <label class="col-md-3 control-label">Username</label>
                    <div class="col-md-5">
                        <input type="text" name="username" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Password</label>
                    <div class="col-md-5">
                        <input type="password" name="password" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Confirm Password</label>
                    <div class="col-md-5">
                        <input type="password" name="cpassword" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Company</label>
                    <div class="col-md-5">
                        <input type="text" name="companyName" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Status</label>
                    <div class="col-md-5">
                        <select class="form-control" name="enabled" th:field="*{enabled}">
                            <option value="true">Active</option>
                            <option value="false">Inactive</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-5 control-label">
                        <button class="btn btn-default" type="submit">Update</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div
这是我的html:

 <div class="container">
        <div class="well well-lg">
            <div class="container-fluid">
                <h5>CNET OFAC Users</h5>

                <div th:if="${userList != null and not #lists.isEmpty(userList)}">
                    Found <span th:text="${#lists.size(userList)}"></span> Users
                </div>
                <div th:if="${userList == null or #lists.isEmpty(userList)}">
                    <div>"No Users were found"</div>
                </div>
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>UserName</th>
                        <th>Company</th>
                        <th>Role</th>
                        <th>Active</th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="user : ${userList}">
                        <td th:text="${user.username}"></td>
                        <td th:text="${user.companyName}"></td>
                        <td th:text="${user.roles[0].authorities}"></td>
                        <td th:text="${user.enabled}"></td>
                        <td><a data-toggle="modal" data-target="#editModal"><span class="glyphicon glyphicon-edit"></span></a></td>

                    </tr>
                    </tbody>
                </table>
                <button data-target="#loginModal" data-toggle="modal" class="btn btn-default">Add User</button>

                <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
            </div>
        </div>
    </div>
        <div class="modal-body">
            <form class="form-horizontal bv-form" action="addUser" th:action="@{/addUser}" th:object="${user}" method="put" id="loginForm">
                <div class="form-group">
                    <label class="col-md-3 control-label">Username</label>
                    <div class="col-md-5">
                        <input type="text" name="username" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Password</label>
                    <div class="col-md-5">
                        <input type="password" name="password" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Confirm Password</label>
                    <div class="col-md-5">
                        <input type="password" name="cpassword" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Company</label>
                    <div class="col-md-5">
                        <input type="text" name="companyName" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Status</label>
                    <div class="col-md-5">
                        <select class="form-control" name="enabled" th:field="*{enabled}">
                            <option value="true">Active</option>
                            <option value="false">Inactive</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-5 control-label">
                        <button class="btn btn-default" type="submit">Update</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div

CNET OFAC用户
找到用户
“未找到任何用户”
用户名
公司
角色
忙碌的
添加用户
其中包括更新表格: × 编辑用户

        <div class="modal-body">
            <form class="form-horizontal bv-form" action="addUser" th:action="@{/addUser}" th:object="${user}" method="put" id="loginForm">
                <div class="form-group">
                    <label class="col-md-3 control-label">Username</label>
                    <div class="col-md-5">
                        <input type="text" name="username" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Password</label>
                    <div class="col-md-5">
                        <input type="password" name="password" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Confirm Password</label>
                    <div class="col-md-5">
                        <input type="password" name="cpassword" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Company</label>
                    <div class="col-md-5">
                        <input type="text" name="companyName" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Status</label>
                    <div class="col-md-5">
                        <select class="form-control" name="enabled" th:field="*{enabled}">
                            <option value="true">Active</option>
                            <option value="false">Inactive</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-5 control-label">
                        <button class="btn btn-default" type="submit">Update</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div

用户名
暗语
确认密码
公司
地位
忙碌的
不活跃的
使现代化

这是一个管理界面吗?这听起来像是一个你可以看到用户列表并编辑他们的地方

        <div class="modal-body">
            <form class="form-horizontal bv-form" action="addUser" th:action="@{/addUser}" th:object="${user}" method="put" id="loginForm">
                <div class="form-group">
                    <label class="col-md-3 control-label">Username</label>
                    <div class="col-md-5">
                        <input type="text" name="username" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Password</label>
                    <div class="col-md-5">
                        <input type="password" name="password" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Confirm Password</label>
                    <div class="col-md-5">
                        <input type="password" name="cpassword" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Company</label>
                    <div class="col-md-5">
                        <input type="text" name="companyName" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Status</label>
                    <div class="col-md-5">
                        <select class="form-control" name="enabled" th:field="*{enabled}">
                            <option value="true">Active</option>
                            <option value="false">Inactive</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-5 control-label">
                        <button class="btn btn-default" type="submit">Update</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div

实现这一点的一个更简单的方法是将他们带到编辑用户页面,而不是在模式中进行编辑。在本例中,所有内容都是直接的HTML/CSS,您可以使用Spring/Hibernate验证来验证表单

我对你的代码不是很清楚。我假设您试图为表中的每个数据集打开一个模式。如果我是对的,那么有一件事你需要首先注意。当您为动态生成的表的每一行填充modal时,您不能简单地使用单个ID添加modal。您需要为每个表行生成modal ID。因此,为什么不这样更改代码-

        <div class="modal-body">
            <form class="form-horizontal bv-form" action="addUser" th:action="@{/addUser}" th:object="${user}" method="put" id="loginForm">
                <div class="form-group">
                    <label class="col-md-3 control-label">Username</label>
                    <div class="col-md-5">
                        <input type="text" name="username" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Password</label>
                    <div class="col-md-5">
                        <input type="password" name="password" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Confirm Password</label>
                    <div class="col-md-5">
                        <input type="password" name="cpassword" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Company</label>
                    <div class="col-md-5">
                        <input type="text" name="companyName" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Status</label>
                    <div class="col-md-5">
                        <select class="form-control" name="enabled" th:field="*{enabled}">
                            <option value="true">Active</option>
                            <option value="false">Inactive</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-5 control-label">
                        <button class="btn btn-default" type="submit">Update</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div


是,这是一个管理页面。我有一个用户列表,我曾考虑过内联编辑,但也不知道如何做到这一点——这就是我最终使用modal的原因。我是否可以将表中的行设置为可编辑,然后将其保存(放置)?您肯定可以进行内联操作。我只是觉得你在让自己变得更强硬(更多的工作)。具体地说,我正在考虑如何处理错误条件。你可能最终不得不写一些定制的东西。因为1)您将通过ajax执行PUT,并且您需要为相应字段正确呈现错误,或者2)您将执行浏览器post,在这种情况下,如果出现错误,您需要在页面的编辑状态下重新绘制错误页面。如果要定义此页面的需求,只需将它们带到另一个页面进行编辑所需的时间就会减少。