尝试打开/ users时出现错误。我不知道如何解决我的代码中的错误。我添加httpSecurity后出现了错误。
类控制器:
@GetMapping("/users")
public String userPage(Model m) {
m.addAttribute("Users", dao.findAll());
return "users";
}
users.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="layout::head"> </head>
<body>
<div th:include="layout :: navigationPanel"></div>
<h1>User list:</h1>
<div th:if="${#lists.isEmpty(Users)}">
No users...
</div>
<table th:if="${!#lists.isEmpty(Users)}">
<tr> <th>UserID</th>
<th>Name</th>
<th>Surname</th>
<th>Login</th>
<th>Password</th>
<th sec:authentication="!isAuthenticated()">Edit</th>
<th sec:authorize="!isAuthenticated()">Delete</th>
</tr>
<tr th:each="Users:${Users}">
<td th:text="${Users.userid}"></td>
<td th:text="${Users.name}"></td>
<td th:text="${Users.surname}"></td>
<td th:text="${Users.login}"></td>
<td th:text="${Users.password}"></td>
<td sec:authentication="!isAuthenticated()"><a th:href="@{/edit/__${Users.userid}__}">Edit</a></td>
<td sec:authentication="!isAuthenticated()"><a th:href="@{/delete/__${Users.userid}__}" >Delete</a></td>
</tr>
</table>
<div th:include="layout::footer"></div>
</body>
</html>
答案 0 :(得分:0)
在@GetMapping中,您返回"users"
,但模板名称为"user-list"
并写th:if={!Users.isEmpty()}
这会造成问题。你检查
是否从数据库获取输出
答案 1 :(得分:0)
将以下依赖项添加到pom.xml
将您的html标记更改为<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">