Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is null safe way to convert array to string using Thymeleaf

I'm trying to convert String array to String using Thymeleaf.

th:value="${#strings.arrayJoin(result.param.searchCondition.mstoneIds, ',')}"

The problem, that if my array is null I get an exception. Are there any null safe ways to convert Array to String? Thanks.

like image 277
Max Avatar asked May 25 '26 08:05

Max


1 Answers

You could do a conditional check like this

th:value="${result.param.searchCondition.mstoneIds != null} ? ${#strings.arrayJoin(result.param.searchCondition.mstoneIds, ',')} : 'null value'"
like image 161
heldt Avatar answered May 28 '26 00:05

heldt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!