这是我用于添加新用户的HTML模板:
<div layout:fragment="content">
<div th:if="${#request.getParameter('successful') != null}" class="card m-3">
<div th:if="${#request.getParameter('successful') == 'true'}" class="card-body text-white bg-success">
<span th:text="#{employees.add.succesful}"></span>
</div>
</div>
<div class="card m-3">
<div class="card-header">
<h4 th:text="#{employees.add.title}" class="card-title"></h4>
<p th:text="#{employees.add.subtitle}" class="card-subtitle text-muted"></p>
</div>
<div class="card-body">
<form action="#" th:action="@{/employees/add}" th:object="${user}" method="post">
<div class="form-group">
<label th:text="#{employees.add.first_name}" for="first_name"></label>
<input th:placeholder="#{employees.add.first_name}" th:errorclass="is-invalid" th:field="*{firstName}" type="text" class="form-control" id="first_name" required>
<div class="invalid-feedback" th:if="${#fields.hasErrors('firstName')}" th:errors="*{firstName}"></div>
</div>
<div class="form-group">
<label th:text="#{employees.add.last_name}" for="last_name"></label>
<input th:placeholder="#{employees.add.last_name}" th:errorclass="is-invalid" th:field="*{lastName}" type="text" class="form-control" id="last_name" required>
<div class="invalid-feedback" th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}"></div>
</div>
<div class="form-group">
<label th:text="#{employees.add.email}" for="email"></label>
<input th:placeholder="#{employees.add.email}" th:field="*{email}" th:errorclass="is-invalid" type="email" class="form-control" id="email" required>
<div class="invalid-feedback" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"></div>
</div>
<p><button th:text="#{button.submit}" type="submit" class="btn btn-primary"></button><button th:text="#{button.reset}" type="reset" class="btn btn-secondary"></button></p>
</form>
</div>
</div>
</div>
它包含太多逻辑吗?我们试图坚持MVC模式,这意味着我们不能在视图中提供太多逻辑。 如果您认为其中包含太多逻辑,我们如何改进它?哪些部分可以移入Java代码?
答案 0 :(得分:2)
您不希望在MVC模式中使用的逻辑是业务逻辑,而且我在代码中看不到任何业务逻辑,因此您无法对其进行改进这种感觉