Когда RequestMapping в моем контроллере, я могу сопоставить html-файл с «/», а другой с «/users». Однако попытка сопоставить «/users/» или «/users/test» не сработает. В консоли будет сказано, что конечная точка была сопоставлена, но при попытке доступа к ней я получу страницу с ошибкой 404.
package com.bridge.Bitter.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class BitterController {
//works
@RequestMapping(value="/")
public String getMainPage(){
return "main.html";
}
//works
@RequestMapping(value="/users")
public String getUsersPage(){
return "users.html";
}
//doesn't work, Whitelabel error page
@RequestMapping(value="/users/")
public String getUsersSlashPage(){
return "users.html";
}
//doesn't work, Whitelabel error page
@RequestMapping(value="/users/test")
public String getUsersTestPage(){
return "users.html";
}
}
Мои application.properties содержат только «spring.data.rest.basePath=/api».
Если я перейду с @Controller на @Rest Controller, произойдет следующее:
package com.bridge.Bitter.controllers;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class BitterController {
//works
@RequestMapping(value="/")
public String getMainPage(){
return "main.html";
}
//returns a webpage with the text "users.html" on it instead of serving the html
@RequestMapping(value="/users")
public String getUsersPage(){
return "users.html";
}
//returns a webpage with the text "users.html" on it instead of serving the html
@RequestMapping(value="/users/")
public String getUsersSlashPage(){
return "users.html";
}
//returns a webpage with the text "users.html" on it instead of serving the html
@RequestMapping(value="/users/test")
public String getUsersTestPage(){
return "users.html";
}
}
Изменение функций с возврата строк на возврат
new ModelAndView("user.html")
работает для /users, но затем будет ошибка 404 для /users/ и /users/test.