I have following Spring Boot project structure (using Thymeleaf) -
Now, when I tried to reference defect-details.html
from index.html
it could not be found. I tried all the following options to no avail:
1.<a th:href="@{/defect-details.html}">
2.<a th:href="@{defect-details.html}">
3.<a href="defect-details.html">
Every time it says There was an unexpected error (type=Not Found, status=404)
.
Please help to find the issue.
(As JBNizet pointed out in the comment) As per MVC design architecture it's better to use controller to render the views instead of view-to-view links. All I had to do was update my Controller class with:
@RequestMapping("/defect-details")
public String defectDetails() {
return "defect-details";
}
And in the Thymeleaf template:
<a th:href="@{defect-details}">
You can always use HTML tag to link two pages in Thymeleaf, However you wont be able to go to a specific HTML page from one HTML page directly without going through spring controller first. You have to make a request to Spring Controller to get that page for you. In order to get it done :--
1.) <a href="defect-details.html"> //on your index.html
2.) Get this request on your Spring Controller to open defect-details.html page for you :--
@RequestMapping("/defect-details")
public String defectDetails() {
return "defect-details"; //defect-details.html page name to open it
}
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