Warunek IF w Thymeleafie

0

Witam,
chce sprawdzić czy moje pole jest puste - <td th:if="${car.parking.howMany != null}" th:text="Yes, variable exists!">someValue</td>, jezeli tak to chce wyświetlić w tabelce tekst, czy ktoś wie dlaczego mi to nie działa i wyskakuje mi bład 500 ?

<table>
    <tr>
        <th>ID</th>
        <th>BRAND</th>
        <th>MODEL CAR</th>
        <th>REGISTRATION NUMBER</th>
        <th>CLIENT</th>
        <th>TIME TO THE END[minuts]</th>
    </tr>
    <tr th:each="car : ${cars}">
        <td th:text="${car.id}">ID</td>
        <td th:text="${car.brand}">BRAND</td>
        <td th:text="${car.modelCar}">MODEL CAR</td>
        <td th:text="${car.registrationNumber}">REGISTRATION NUMBER</td>
        <td th:text="${car.client.firstName + ' ' + car.client.lastName}">CLIENT</td>
        <td th:text="${car.parking.howMany}">Time To The End</td>
        <td th:if="${car.parking.howMany != null}" th:text="Yes, variable exists!">someValue</td>
        <td><a th:href="@{|/delete/${car.id}|}" >Usuń</a></td>
        <td><a th:href="@{|/edit/${car.id}|}" >Edytuj</a></td>
    </tr>
</table>
</body>

Car:


public class Car {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank(message = "Wpisz marke")
    @Column
    private String brand;

    @NotBlank(message = "Wpisz model")
    @Column(name = "model")
    private String modelCar;jav```java



    @NotBlank(message = "Wpisz numer rejestracyjny")
    @Column(name = "rejestracja")
    private String registrationNumber;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name="client_id")
    private Client client;

    @OneToOne(mappedBy = "car", cascade = CascadeType.ALL)
    private Parking parking;
}


Parking:

public class Parking {


   @Id
   @GeneratedValue
   private Long id;

   @CreatedDate
   private LocalDateTime boughtDate;

   private LocalDateTime endDate;

   @Transient
   private Long howMany;

   @OneToOne(fetch = FetchType.EAGER)
   @JoinColumn(name="car_id")
   private Car car;
}

0
<td th:text="${car.parking.howMany} ? 'Yes, variable exists!' : 'No, variable doesn't exist!'" />
0
au7h napisał(a):
<td th:text="${car.parking.howMany} ? 'Yes, variable exists!' : 'No, variable doesn't exist!'" />

niestety cały czas 500

0

Ktoś ma jeszcze jakiś pomysł czemu to nie działa ?

0

Klasy javowe nie muszą być Serializable?

0

${car.parking.howMany}

Spróbuj zmienić na:

${car.parking.howMany != null}

0

Negacje w Thymelafie wykonuje się za pomocą
<p th:unless="${car.parking.HowMany == null" th:text="${Yes, variable exists!}"></p>

Nie mam jak teraz sprawdzić, ale spróbuj w ten sposób, a nóż podziała.

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