Thymeleaf utility methods for Aggregates

January 04, 2020 No comments Thymeleaf Utility Aggregates

1. Introduction

Thymeleaf is a template engine designed with Java-application in mind. The engine comes with utility classes that can be used to format, process or transform variables on the template. In this article, we will showcase utility methods for Aggregates. The implementation of Aggregates utility methods can be found in the official Thymeleaf GitHub Repository.

2. Available utility methods for Aggregates

Aggregates utility methods are used to compute sum or average value of the elements stored in collection or array. Items of the collection must implement one of the following interfaces:

  • Byte,
  • Short,
  • Integer,
  • Long,
  • BigDecimal,
  • Double.
Method Purpose Description
${#aggregates.sum(array|collection)}

Compute sum Returns null if array or collection is empty
${#aggregates.avg(array|collection)}

Compute average Returns null if array or collection is empty

3. Conclusion

In this article, we presented Thymeleaf utility methods for Aggregates. The utility should be helpful to sum all collection elements of present the average value.

{{ message }}

{{ 'Comments are closed.' | trans }}