I have an Employee Entity that has a Collection of Reviews, each Review has a byte grade.
Unnecessary details are omitted for brevity
JavaScript
x
@Entity
public class Employee extends AbstractBaseEntity {
@OneToMany( mappedBy = "employee", cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private List<Review> reviews;
}
@Entity
public class Review extends AbstractBaseEntity {
private Byte grade;
}
How can I get an average Review grade for each Employee using Thymeleaf to insert in Table?
Advertisement
Answer
Thymeleaf has aggregate functions. You can combine them with collection projection.
JavaScript
<span th:text="${#aggregates.avg(employee.reviews.![grade])}" />