0

I am able to write the following method which loads my static files fine:

@GetMapping("/register")
public String newRegister(HttpServletRequest request, Model model) {
    return "register";
}

However, when I add and {Id} to the url:

@GetMapping("/register/{Id}")
public String newRegister(HttpServletRequest request, Model model) {
    return "register";
}

all of the static files error, with a message such as:

2018-07-05 08:42:24.969  WARN 52397 --- [nio-8080-exec-4] o.s.web.servlet.PageNotFound             :     
No mapping found for HTTP request with 
URI [/hi/js/all.js] in DispatcherServlet with name 'dispatcherServlet'
2018-07-05 08:42:24.969  WARN 52397 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound          
 : No mapping found for HTTP request with 
URI [/hi/img/google-logo.svg] in DispatcherServlet with name 'dispatcherServlet'
 2018-07-05 08:42:25 DEBUG GreetingController:40 - *****123
 2018-07-05 08:42:25.563  WARN 52397 --- [nio-8080-exec-7] o.s.web.servlet.PageNotFound             : No mapping found for HTTP request with 
URI [/hi/css/all.css] in DispatcherServlet with name 'dispatcherServlet'

Why does this occur, and how would I fix it? Here is an example of the project structure:

enter image description here

David542
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

0

Given you have added a path variable to the request - GetMapping("/register/{Id}"), The method needs @PathVariable parameter. So this will be something like

@GetMapping("/register/{Id}")
public String newRegister(HttpServletRequest request, Model model, @PathVariable("Id") long id) {
 return "register";
}

Hope this helps.

OliverTester
  • 401
  • 2
  • 7