idea创建一个干净的SpringMVC项目
作者:互联网
一、创建普通的maven项目
二、右键添加web支持
三、pom.xml配置maven环境
1 <!--导入依赖--> 2 <dependencies> 3 <dependency> 4 <groupId>junit</groupId> 5 <artifactId>junit</artifactId> 6 <version>4.12</version> 7 </dependency> 8 <dependency> 9 <groupId>org.springframework</groupId> 10 <artifactId>spring-webmvc</artifactId> 11 <version>5.1.9.RELEASE</version> 12 </dependency> 13 <dependency> 14 <groupId>javax.servlet</groupId> 15 <artifactId>servlet-api</artifactId> 16 <version>2.5</version> 17 </dependency> 18 <dependency> 19 <groupId>javax.servlet.jsp</groupId> 20 <artifactId>jsp-api</artifactId> 21 <version>2.2</version> 22 </dependency> 23 <dependency> 24 <groupId>javax.servlet</groupId> 25 <artifactId>jstl</artifactId> 26 <version>1.2</version> 27 </dependency> 28 </dependencies>
四、写一个spring-servlet.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://www.springframework.org/schema/beans 5 http://www.springframework.org/schema/beans/spring-beans.xsd"> 6 <!--处理器映射器 BeanNameUrlHandlerMapping--> 7 <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> 8 <!--处理器适配器 SimpleControllerHandlerAdapter--> 9 <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> 10 <!--视图解析器 InternalResourceViewResolver--> 11 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver"> 12 <!----> 13 <property name="prefix" value="/WEB-INF/jsp/"/> 14 <property name="suffix" value=".jsp"/> 15 </bean> 16 </beans>
五、配置web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" 5 version="4.0"> 6 <!--配置DispatcherServlet 核心:前端控制器,请求分发器--> 7 <servlet> 8 <servlet-name>springmvc</servlet-name> 9 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 10 <!--配置DispatcherServlet 绑定Spring的配置文件--> 11 <init-param> 12 <param-name>contextConfigLocation</param-name> 13 <param-value>classpath:springmvc-servlet.xml</param-value> 14 </init-param> 15 <!--启动级别 1 --> 16 <load-on-startup>1</load-on-startup> 17 </servlet> 18 <!-- / 和/ *的区别 19 / :只能匹配所有的请求,不会匹配jsp页面 20 /* :匹配请求和jsp页面 21 --> 22 <servlet-mapping> 23 <servlet-name>springmvc</servlet-name> 24 <url-pattern>/</url-pattern> 25 </servlet-mapping> 26 </web-app>
标签:xml,web,SpringMVC,idea,springmvc,干净,11,servlet,javax 来源: https://www.cnblogs.com/rainbow-1/p/15612224.html