Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate two integers in Spring EL

I want to create a Spring EL in which I want that two integers be concatenated as a-b with a and b being integers. Spring EL does not support concat function with integers as they are not Strings. I have tried to cast them like #T(java.lang.String).valueOf(user.id).concat('-').concat(#T(java.lang.String).valueOf(user.serviceId)) but this is not working.

What should be the correct expression?

like image 387
khateeb Avatar asked Oct 16 '14 05:10

khateeb


1 Answers

Please, use next expression #{T(java.lang.String).format('%d-%d', user.id, user.serviceId)}. Hope this helps.

Update.

If this expression will be used within @Cacheable(key) field, please update expression in next way: T(java.lang.String).format('%d-%d', #user.id, #user.serviceId).

like image 64
nndru Avatar answered Sep 21 '22 16:09

nndru