Tibeleap Ordinal Numbers SpringBoot

I read some good posts, like this one , that explain the method of getting sequence numbers when setting int .

Now I have a LocalDate object, and I can format the dates using any of the DateTimeFormat templates in my Thymeleaf template. An example looks something like this:

 <strong th:text="${item.date} ? ${#temporals.format(item.date, 'dd')}"></strong> 

Question: How can I or perhaps the best way to achieve similar results with the post that I linked to above in Thymeleaf.

I am not an experienced Java developer, so it would be very helpful if you were as thorough as you could, explaining the answer.

+2
source share
1 answer

You can use static fields (and functions) inside the Thymeleaf template, so in your case it will look like this:
1) Code from a question related to you (I changed it a bit) :

 package your.packagename; // http://code.google.com/p/guava-libraries import static com.google.common.base.Preconditions.*; public class YourClass { public static String getDayOfMonthSuffix(String num) { Integer n = Integer.valueOf(num == null ? "1" : num); checkArgument(n >= 1 && n <= 31, "illegal day of month: " + n); if (n >= 11 && n <= 13) { return "th"; } switch (n % 10) { case 1: return "st"; case 2: return "nd"; case 3: return "rd"; default: return "th"; } } } 

2) Call it inside the view:

 <strong th:text="${#temporals.format(item.date, 'dd') + T(your.packagename.YourClass).getDayOfMonthSuffix(#temporals.format(item.date, 'dd'))}"></strong> 
+2
source

Source: https://habr.com/ru/post/1011520/


All Articles