SpringMvc 1. 核心:DispatcherServlet 1.1作用:负责拦截请求并分派给相应的处理器处理 1.2配置DispatcherServlet(web.xml)
2.配置处理器映射器,适配器,视图解析器等 3.编写Handler类 2.1实现Controller接口,对应上面配置的第一种适配器 2.2实现HttpRequestHandler接口,对应上面配置的第二种适配器 4.注解开发 4.1 spring3.1之前的映射器和适配器的配置类(1)映射器org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
(2)适配器org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
4.2 spring3.1之后的映射器和适配器的配置类(1)映射器org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
(2)适配器org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
(3)使用<mvc:annotation-driven></mvc:annotation-driven>可以替代上面两个
4.3 扫描Handler类,开启组件扫描,方便快捷,只要配置包名 4.4 编写Handler类
(1) 在类名上使用@Controller注解类
(2) 使用@RequestMapping()配置映射url
5.配置等相关文件 5.1pom.xml
1 <properties> 2 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 3 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 4 5 6 7 <!-- log4j日志包版本号 --> 8 <slf4j.version>1.7.18</slf4j.version> 9 <log4j.version>1.2.17</log4j.version> 10 11 </properties> 12 13 <dependencies> 14 <!-- 添加fastjson --> 15 <dependency> 16 <groupId>com.alibaba</groupId> 17 <artifactId>fastjson</artifactId> 18 <version>1.1.41</version> 19 </dependency> 20 21 <!-- 添加日志相关jar包 --> 22 <dependency> 23 <groupId>log4j</groupId> 24 <artifactId>log4j</artifactId> 25 <version>${log4j.version}</version> 26 </dependency> 27 <dependency> 28 <groupId>org.slf4j</groupId> 29 <artifactId>slf4j-api</artifactId> 30 <version>${slf4j.version}</version> 31 </dependency> 32 <dependency> 33 <groupId>org.slf4j</groupId> 34 <artifactId>slf4j-log4j12</artifactId> 35 <version>${slf4j.version}</version> 36 </dependency> 37 38 <!-- log end --> 39 <!-- 映入JSON --> 40 <dependency> 41 <groupId>org.codehaus.jackson</groupId> 42 <artifactId>jackson-mapper-asl</artifactId> 43 <version>1.9.13</version> 44 </dependency> 45 <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core --> 46 <dependency> 47 <groupId>com.fasterxml.jackson.core</groupId> 48 <artifactId>jackson-core</artifactId> 49 <version>2.8.0</version> 50 </dependency> 51 <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --> 52 <dependency> 53 <groupId>com.fasterxml.jackson.core</groupId> 54 <artifactId>jackson-databind</artifactId> 55 <version>2.8.0</version> 56 </dependency> 57 58 <dependency> 59 <groupId>commons-fileupload</groupId> 60 <artifactId>commons-fileupload</artifactId> 61 <version>1.3.1</version> 62 </dependency> 63 64 <dependency> 65 <groupId>commons-io</groupId> 66 <artifactId>commons-io</artifactId> 67 <version>2.4</version> 68 </dependency> 69 70 <dependency> 71 <groupId>commons-codec</groupId> 72 <artifactId>commons-codec</artifactId> 73 <version>1.9</version> 74 </dependency> 75 76 <!-- 添加jstl依赖 --> 77 <dependency> 78 <groupId>jstl</groupId> 79 <artifactId>jstl</artifactId> 80 <version>1.2</version> 81 </dependency> 82 <dependency> 83 <groupId>junit</groupId> 84 <artifactId>junit</artifactId> 85 <version>3.8.1</version> 86 <scope>test</scope> 87 </dependency> 88 <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> 89 <dependency> 90 <groupId>org.springframework</groupId> 91 <artifactId>spring-webmvc</artifactId> 92 <version>4.3.14.RELEASE</version> 93 </dependency> 94 <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --> 95 <dependency> 96 <groupId>javax.servlet</groupId> 97 <artifactId>javax.servlet-api</artifactId> 98 <version>3.1.0</version> 99 <scope>provided</scope> 100 </dependency> 101 102 </dependencies>