Я сделал веб-приложение, используя Spring boot, Spring Security и MySQL.
Я хочу добавить страницу, где я показываю всю информацию пользователя. Теперь я могу просто получить всех пользователей из моей БД.
Я обнаружил, что есть функция find(index)
, но я не знаю, что указывать в качестве индекса, есть ли что-то в загрузке Spring может помочь?
Это модель пользователя:
@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "email"))
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
private String email;
private String password;
//.........
}
Мой userRepository:
public interface UserrRepository extends JpaRepository<User, Integer>{}
Контроллер пользователя:
public String home(Model model)
{
model.addAttribute("users", userRepo.findAll());
return "stat";
}
А моя html страница:
<table>
<thead>
<tr>
<th>Id</th>
<th>firstName</th>
<th>lastName</th>
<th>Password</th>
<th>email</th>
</tr>
</thead>
<tbody>
<tr th:each="user : ${users}">
<td th:text="${user.id}">Id</td>
<td th:text="${user.firstName}">Name</td>
<td th:text="${user.lastName}">Name</td>
<td th:text="${user.password}">Name</td>
<td th:text="${user.email}">Name</td>
</tr>
</tbody>
</table>