Q: Thymleaf display data from table by date Okay so I have this situation:
User can have a wallets, wallets can have a transactions and user can create a transaction for every wallet he owns.
Now, transactions besides other fields have a field date.
When the user creates a transaction, he also selects the date. Now, imagine a user create next transactions:
26/01/2023 two transactions, then for example yesterday or 25/01/23 and then back to 14/01/2023
So I want to show transactions for example like this:

As you can see, if there is no transactions on date then dont show the date, and if user have a more then one transaction for same date show him inside same element instead of creating a whole new date. For example my current program display transactions like this:

So as you can see I have a two transactions for same date and they are displayed separated.
And I showed on above SS how it would look like.
This is controller that saveIncome transaction and controller that return all transactions by user ID, I mean from logged in user.
@PostMapping("/saveIncome/{walletId}")
public String saveIncome(@PathVariable(value = "walletId") long walletId, @Valid Transaction transaction, BindingResult result, Model model) {

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    UserDetailsImpl user = (UserDetailsImpl) authentication.getPrincipal();
    long userId = user.getId();

    Wallet wallet = walletService.getWalletById(walletId);

    boolean thereAreErrors = result.hasErrors();
    if (thereAreErrors) {
        model.addAttribute("incomeCategories", IncomeCategories.values());
        return "income_transaction";
    }

    transaction.setWallet(wallet);
    transaction.setUserId(userId);
    transaction.setWalletName(wallet.getWalletName());
    transactionService.saveIncome(transaction, walletId, userId);
    return "redirect:/api/wallet/userWallet/balance/" + userId;
}

@GetMapping("/userTransactions/{user_id}")
public String getUserTransactions(@PathVariable("user_id") long user_id, Model model) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    UserDetailsImpl user = (UserDetailsImpl) authentication.getPrincipal();
    long userId = user.getId();
    model.addAttribute("userId", userId);
    model.addAttribute("transactions", transactionService.findDistinctIdByUserId(user_id));
    return "transactions";
}

And this is Thymeleaf so far:
<div>
<div th:each="transactions : ${transactions}">
    <h2>Amount: <span th:text="${transactions.amount}"></span></h2>
    <br>
    <h2>Note: <span th:text="${transactions.note}"></span></h2>
    <br>
    <h2>Date: <span th:text="${transactions.date}"></span></h2>
    <br>
    <h2>Wallet name: <span th:text="${transactions.walletName}"></span></h2>
    <br>
    <h2>Expense Category: <span th:text="${transactions.expenseCategories}"></span></h2>
    <br>
    <h2>IncomeCategory: <span th:text="${transactions.incomeCategories}"></span></h2>
</div>

How to change it so actually I get a response as from the first picture?
I appreciate any help and sorry for my bad English grammar.
Also, I tried to find something, and searching left and right but nothing useful for something like this. I know I can sort the date but I prefer this option first. Thanks again.
