I am trying to map the URL /function/hash
in my project to a specific HTML page html/hashcode.html
. This is a spring boot project without using thymeleaf.
This is my code:
// package ...;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class FunctionController {
@RequestMapping("/function/hash")
public String hashPage(Model m) {
return "html/hashcode.html";
}
}
The above code returns a 404 when I try to access localhost:8080/function/hash
.
I also tried
@Controller
@RequestMapping("/function")
public class FunctionController {
@RequestMapping("/hash")
public String hashPage(Model m) {
return "html/hashcode.html";
}
}
which also yields a 404 when I go to localhost:8080/function/hash
.
Directly using @RequestMapping("/hash")
to map the page to /hash
works, in case you wonder if the return value of the function is incorrect.
I also find that using multiple layer url like @RequestMapping("/api/test")
is working in @RestController
classes, but somehow it doesn't work in this @Controller
class above.