Spring 4:如何将RequestMapping URL映射到特定控制器

use*_*462 6 java xml jsp spring-mvc spring-4

我编写了一个带有多个控制器的Spring MVC应用程序.

在JSP上,我有action以下形式:

 <form id="createTableForm" method="post" name="createTable" action="${pageContext.request.contextPath}/saveTable" >
Run Code Online (Sandbox Code Playgroud)

并且相同的操作映射到Controller中的方法:

@Controller
public class TableController implements TableConstants {

  @RequestMapping(value="/saveTable")
  public String saveTable(HttpServletRequest request,RedirectAttributes redirectAttributes) {
  //...
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的web.xml:

  <context-param>
    <description>Context name of the Application</description>
    <param-name>contextName</param-name>
    <param-value>W****</param-value>
</context-param>
<context-param>
    <description>Database used for</description>
    <param-name>databaseName</param-name>
    <param-value>w*****</param-value>
</context-param>

<welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
</welcome-file-list>

<filter>
    <filter-name>FilterChainProxy</filter-name>
    <filter-class>com.abc.w****.configuration.FilterChainProxy
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>FilterChainProxy</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<session-config>
    <session-timeout>1</session-timeout>
</session-config>


<jsp-config>
    <taglib>
        <taglib-uri>http://displaytag.sf.net</taglib-uri>
        <taglib-location>/WEB-INF/tld/displaytag.tld</taglib-location>
    </taglib>
</jsp-config>
Run Code Online (Sandbox Code Playgroud)

我是否需要在web.xml文件或WebAppConfig类中包含该特定Controller的URL映射?

我有WebAppConfig@Configuration,@ ComponentScan和@EnableWebMVC注释.它有以下方法:

 public UrlBasedViewResolver setupViewResolver() {
 }
 public MessageSource messageSource() {
 }
 public void addResourceHandlers(ResourceHandlerRegistry registry) {
 }
 public CommonsMultipartResolver multipartResolver() { 
 }
Run Code Online (Sandbox Code Playgroud)

请指教.

igr*_*eld 1

@RequestMapping注释可以应用于控制器类。在这种情况下,此类中的所有方法都将从类注释派生默认值,并且实现可以覆盖它。