标签:resolve https odi abstract control 配置 tar 图片 ref
spring-web-3.2.12.RELEASE.jar:在web应用开发时使用spring框架所需的核心类
spring-webmvc-3.2.12.RELEASE.jar:springmvc框架相关的所有类,包含框架的servlets,webmvc框架,以及对控制器和试图的支持
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean name="/index.html" class="cn.smbms.controller.IndexController"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
新建一个类,将该类变成一个可以处理前端请求到控制器,需要继承org.springframework.web.servelt.mvc.AbstractController,并实现handleRequestInternal方法,如下
public class IndexController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("index"); } }
当处理多个请求时,为避免多个配置和多个控制器,常用的解决方案是使用springmvc提供的一键式配置方法,通过注解的方式来进行springmvc开发,如下
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="cn.smbms.controller"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
注意:spring3.2之前的版本,开启注解式处理器支持的配置为DefaultAnnotationHanlderMapping(处理器映射)与AnnotationMethodHandlerAdapter(处理器适配器)
spring3.2之后的版本,使用RequestMappingHandlerMapping和RequestMappingHandlerAdapter来替代
标签:resolve https odi abstract control 配置 tar 图片 ref
原文地址:https://www.cnblogs.com/yanguobin/p/11622919.html