我正在开发我的 Spring 应用程序,根据下面的代码,我将多个 URL 映射到一种方法。我正在制作一种方法“root”来服务所有以索引和根开头的请求。
@RequestMapping(value = {"/", "index*"}, method = RequestMethod.GET)
public String root(Model model) {
logger.info("Welcome to index page.");
model.addAttribute("hello", "Welcome to index page." );
return "index";
}
如果请求被定向到映射方法,则上述"index*"
工作正常,即但它不适用于. 如果我得到."index", "index123", "index.html" and "index.txt"
"root"
"index.jsp"
"index.jsp"
"HTTP Status 404" "The requested resource is not available"
摘自web.xml
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
有人可以让我知道这背后的原因,我怎样才能让它发挥作用?