I'm new on Spring framework and I have the next problem with mapping:
I have created a Controller called HomeController and a View called index.html.
I put the annotation @Controller
above the name of class HomeController and I created a method bienvenido
where I wrote the annotation @RequestMapping("/bienvenido")
above.
The problem is, as much as I try to re-run the server and clean the cache, I can never access index.html throught localhost:port/bienvenido. But if I write localhost:port/ only, the index.html is shown then.
I'm looking up info and everybody uses that way or a similar way to do this, I don't understand what is happening.
This is my classes and my html file:
package controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/bienvenido")
public String bienvenido() {
return "index";
}
}
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Bienvenido!</h1>
</body>
Thank you in advance.
After a while looking at my project I just realised that I was creating the packages out of the main package. I mean: the controller package was named only "controllers" instead "com.learning.bienvenido.controllers".
Thank you all!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.