I am generating a url in thymeleaf using the following code.
@{/schedule/data/bookableTimes/{teacherUsername}(teacherUsername=${teacher.user.username},lessonLengthType=${lessonLengthType},studentId=${#httpServletRequest.getParameter('studentId')})}
This works perfectly, when the studentId is supplied. However I also want to cater for the scenario when the studentId is not supplied. Currently if the studentId is not supplied it will generate a url like so
/schedule/data/bookableTimes/teacher?lessonLengthType=full&studentId=
However this is not what I want, in the case that the studentId is null, I'd rather not have the studentId portion of the url generated at all. Is there a simple way to do this using thymeleaf?
I would create a string and concatenate some part something like
string url ="/schedule/data/bookableTimes/";
if (teacherUser) url.add(teacher)
if (studentId) url.add(studentId)
@{*url}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With