Wyświetlanie listy w thymeleaf

0

Siemka mam listę która zawiera obiekty klasy Spittle i nie mam pojęcia jak to wyświetlić, pytałem na stacku ale tam również ich kod również nie działał więc może ktoś tutaj będzie mi wstanie pomóc, część kodu znalazłem (Model i thymeleaf) ale nie potrafiłem go sformatować do własnych potrzeb.

SERVICE
@Autowired
private SpittleRepository spittleRepository;

private List<Spittle> spittles = new ArrayList<>(Arrays.asList(
        new Spittle("aaaa", new Date()),
        new Spittle("bbbbbb", new Date())
));

public List<Spittle> findSpittles() {
     List<Spittle> spittles = new ArrayList<>();
     spittleRepository.findAll().forEach(findedSpittles::add);
     return findedSpittles;
}}
CONTROLLER
@Autowired
SpittleService spittleService;

@RequestMapping(method = RequestMethod.GET)
public String findSpittles(Model model) {
    model.addAttribute("spittle", spittleService.findSpittles());
    return "spittles";
} }
ENTITY
 @Id
        private final Long id;
        private final String message;
        private final Date time;
        private Double latitude;
        private Double longitude;



        public Spittle(String message, Date time, Double latitude, Double 
        longitude) {
            this.id = null;
            this.message = message;
            this.time = time;
            this.latitude = latitude;
            this.longitude = longitude;
        }

        public Spittle(String message, Date time) {
            this(message, time, null, null);
        }

        + geters
}}
THYMELEAF
<h2>Lista spiltów</h2>
       <table class="table table-striped">
           <tr>
               <th>Message</th>
               <th>Date</th>
           </tr>
           <tr th:each="spittle : ${spittle}">
               <td th:text="${spittle.getMessage()}"></td>
               <td th:text="${spittle.getTime()}"></td>
           </tr>
       </table>

Repo nie ma nic w środku oprócz extend JpaRepository. Pokazuje się tylko h2 i th ale już reszta nie! Jak widać stworzyłem w liście 2 obiekty w Service i powinny się one pokazać

1
<tr th:each="spittle : ${spittle}">

Nazwij listę spittles, tak samo jak dodajesz modelAttribute. W tym momencie kolekcja jak i jej element nazywają się tak samo.

Swoją drogą:

public List<Spittle> findSpittles() {
     List<Spittle> spittles = new ArrayList<>();
     spittleRepository.findAll().forEach(findedSpittles::add);
     return findedSpittles;
}}

nie można po prostu ```
return spittleRepository.findAll()

1 użytkowników online, w tym zalogowanych: 0, gości: 1