Tôi đã viết một ứng dụng Spring MVC với nhiều bộ điều khiển.Mùa xuân 4: Cách ánh xạ các URL yêu cầu đối với bộ điều khiển cụ thể
Trên JSP, tôi có action
trên biểu mẫu:
<form id="createTableForm" method="post" name="createTable" action="${pageContext.request.contextPath}/saveTable" >
và hành động tương tự được ánh xạ tới một phương pháp trong điều khiển:
@Controller
public class TableController implements TableConstants {
@RequestMapping(value="/saveTable")
public String saveTable(HttpServletRequest request,RedirectAttributes redirectAttributes) {
//...
}
}
Và trong tôi 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>
Tôi có cần đưa ánh xạ URL vào Bộ điều khiển cụ thể đó trong tệp web.xml
hoặc trong lớp WebAppConfig
không?
Tôi có chú thích WebAppConfig
với @Configuration, @ComponentScan và @EnableWebMVC. Nó có các phương pháp sau:
public UrlBasedViewResolver setupViewResolver() {
}
public MessageSource messageSource() {
}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
}
public CommonsMultipartResolver multipartResolver() {
}
Vui lòng thông báo.
Vì vậy, bạn muốn đạt được bộ điều khiển cụ thể đó cũng có ánh xạ URL riêng? –
Tôi muốn biết cách tiếp cận chính xác như bây giờ lớp điều khiển của tôi chỉ là chú thích với chú thích @Controller. Vì vậy, chúng ta nên cung cấp ánh xạ URL tới lớp Controller và nối thêm ánh xạ đó vào hành động trong JSP cũng như với RequestMapping URL – user3403462
đăng chú thích thêm servlet-config.xml –