Spring MVC 编程流程步骤
1. 建立Maven工程
2. 添加Spring MVC依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
</dependencies>
3. 新建核心配置文件,并在核心配置文件里配置
配置组件扫描:
<context:component-scan base-package="com.jt"/>
启用MVC默认配置(@RequestMapping):
<mvc:annotation-driven/>
配置视图解析器
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
4. 配置Spring MVC前段控制器(在web.xml文件中配置)地
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-configs.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
5. 创建并配置Spring MVC 后端控制器
6. 部署及测试spring mvc 项目应用
方