Spring Mvc ==> Struts2
spring 无法替代
myBatis 工作量大 要自己操作sql语句 ==> hibernate
Spring Mvc 取代Stuts2 开发快 运行效率高
mode 指整个界面层

1.在lib文件夹导入所要jar


2、配置web.xml

<servlet>
<servlet-name>springmvc</servlet-name>
<!-- springmvc的总控制器 -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- springmvc的总控制器 -->
<!--tomcat加载完工程后,servletContext初始化后马上创建核心控制器
一上来就加载 不设置也可以,但需要等许久 -->
<load-on-startup>1</load-on-startup>
<!--tomcat加载完工程后,servletContext初始化后马上创建核心控制器
一上来就加载 不设置也可以,但需要等许久 -->
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
3.配置springmvc-servlet.xml 进行详细配置


.配置springmvc-servlet.xml 进行详细配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
">
<!-- 扫描路径 -->
<context:component-scan base-package="com.study.it.ui"/>
<!-- 快捷导入基本配置 -->
<mvc:annotation-driven/>
<!-- 渲染器 WEB-INF/views目录 .jsp后缀 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/views/" p:suffix=".jsp"
p:viewClass="org.springframework.web.servlet.view.JstlView">
</bean>
</beans>
springmvc-servlet.xml配置放到src下面

4.编写controller

package com.study.it.ui.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/abc")//struts.xml
public class HelloController {
@RequestMapping("/hh")
public String hi(){
System.out.println("hello,world");
return "login_page";
}
}