0

ошибкаХочу вывести значения базы данных на страницу ввиде таблицы id, name, email, не получается. Кто знает, скажите как сделать правильно, потому что выдает ошибку.

add.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <div>
        <ul th:object="${users}">
            <li>ID: <span th:text="*{id}">id</span></li>
            <li>Name: <span th:text="*{name}">name</span></li>
            <li>Address : <span th:text="*{email}">email</span></li>
        </ul>
    </div>
    <p><a href="/">home</a></p>
</body>
</html

Контроллер

   @GetMapping(path = "/all")
    public String getAllUsers(Map<String,Object> model) {
        Iterable <User> users = userRepository.findAll();
        model.put("users",users);
        return "all";
    }

Класс User

@Entity // This tells Hibernate to make a table out of this class
public class User {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)

    private Integer id;

    private String name;

    private String email;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }


}
5
  • Добавьте в текст вопроса подробности об ошибке. 24 июн 2019 в 18:27
  • добавил ошибку.
    – 123123
    24 июн 2019 в 18:31
  • @АлександрМуксимов тут без ошибки видно в чем проблема) 24 июн 2019 в 20:40
  • Ваша проблема решилась? 27 июн 2019 в 14:06
  • да, проблема решилась
    – 123123
    19 июл 2019 в 17:28

1 ответ 1

0

Ссылки на оригинал ответа:
https://stackoverflow.com/questions/36744655/for-each-operator-in-thymeleaf

<div th:each="user : ${users}">
   <ul>
       <li>ID: <span th:text="*{user.id}">id</span></li>
       <li>Name: <span th:text="*{user.name}">name</span></li>
       <li>Address : <span th:text="*{user.email}">email</span></li>
    </ul>
</div>

Кстати, рассмотри для удобства записи getters/setters, constructors - project lombok

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.