0
Spring boot controller doesn't work as I want
Spring boot controller doesn't work as I want @Controller public class aController{ @RequestMapping("/") public String index() { return "pages/index" ; } } When you enter de url localhost:8080/pages it doesn't redirect me to the index html file... Why? I refresh the trigger de tools. I even restart the server, clear cache etc. If I put only localhost:8080 it works. But it should work with localhost:8080/pages. What am I doing wrong? Ps. : My index.html is in the pages folder in templates Ps2: I know the if I put in request mapping "/pages/" it's working fine, but the way I.m writing return "pages/index" should work the same
6 Antworten
+ 1
Maybe a typo? @RequestMapping with double p.
If that's not the case, maybe this will help.
https://www.baeldung.com/spring-requestmapping
+ 1
As per my understanding of this feature, if you want the method to respond to
http://localhost:8080/pages
Then you have to annotate with
@RequestMapping("/pages")
+ 1
Omg.. I realize that I'm wrong. It is working fine. The requestMapping do access the template folder pages, but how did you said, the method responds to main "/" folder and access it from pages folder in return. I realize I know nothing... Sorry for the post
0
It isn't a spelling problem. The pblem is when I return it doesn't see /pages folder. If I put it in mapping it works, after return doesn't work
0
When you put return pages/index it should work fine as well.. Inside the / request mapping annotation, but for me it's not working... I don't know why
0
And the most odd thing is that my index file is in the pages folder in templates..... And if I put only request mapping ("/") and enter localhost:8080 it works... It finds the page