这可能吗?
@Controller
@RequestMapping("/login")
public class LoginController {
@RequestMapping("/")
public String loginRoot() {
return "login";
}
@RequestMapping(value="/error", method=RequestMethod.GET)
public String loginError() {
return "login-error";
}
}
访问 localhost:8080/projectname/login
时出现 404 错误,但在 localhost:8080/projectname/login/error
中却没有。
这是我的 web.xml 项目名称
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<description></description>
<servlet-name>projectname</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>projectname</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
最佳答案
您不需要方法映射中的 /
。只需将其映射到 ""
.
关于java - Spring MVC : RequestMapping both class and method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22702568/