How To Set base_url() On Spring Boot + Thymeleaf? - Save My Knowledge
Thursday, January 8, 2015

How To Set base_url() On Spring Boot + Thymeleaf?

Hi, some time ago, I have problem when applying the menu navigator on spring boot (java) because when we are on certain depth, the link won't work correctly.

Example:
You have link <a href="about">about us</a> that indicate your browser will redirect to "http://localhost/about".
But if our position is on "http://localhost/certainhost/gallery/image/", when you click the link, the address will became "http://localhost/certainhost/gallery/image/about".

From this example we can make a conclusion that this is not right and the solution is we need function that work as base_url() that give us the base url (http://localhost).

Now we know the problem and the solution. But, how?

How to use base url at Spring Boot?
The answer is easy, just type this code <a th:href="@{/about}"></a>
We need to add "th:" as declare that this is a thymeleaf code and add "@{}" as this link is base url