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

21st Aug 2020, 12:28 PM
ztonaz
ztonaz - avatar
6 ответов
+ 1
Maybe a typo? @RequestMapping with double p. If that's not the case, maybe this will help. https://www.baeldung.com/spring-requestmapping
21st Aug 2020, 12:41 PM
Tibor Santa
Tibor Santa - avatar
+ 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")
21st Aug 2020, 3:04 PM
Tibor Santa
Tibor Santa - avatar
+ 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
21st Aug 2020, 10:03 PM
ztonaz
ztonaz - avatar
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
21st Aug 2020, 12:46 PM
ztonaz
ztonaz - avatar
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
21st Aug 2020, 3:07 PM
ztonaz
ztonaz - avatar
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
21st Aug 2020, 3:15 PM
ztonaz
ztonaz - avatar