💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
第一步创建项目 重要的如图所示 ![](https://img.kancloud.cn/75/6c/756c08d04406ec33b52fcbb9351e8269_643x133.png) 解决利用maven搭建spring项目加载过慢的问题: archetypeCatalog 设置为: internal ![](https://img.kancloud.cn/d1/a4/d1a45047df4315ecf998de0ebd74d0c0_1100x600.png) 其余的步骤较简单,在此省略 ***** 第二.pom.xml加入依赖 ~~~ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.youge</groupId> <artifactId>springmvc</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>springmvc Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <spring.version>5.2.9.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>springmvc</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> </build> </project> ~~~ ***** 第三步:web.xml代码 ![](https://img.kancloud.cn/66/cd/66cd52f7f89dd56c4154a3971a159dfe_1333x58.png) ~~~ <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <!-- 配置前端控制器--> <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:springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> ~~~ ***** 第四步:创建springMVC配置文件springmvc.xml,文件名也可以随便改. ![](https://img.kancloud.cn/37/38/3738dae8401f433fc283b807ba29a729_372x254.png) ~~~ <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" 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"> <!-- 开启注解扫描--> <context:component-scan base-package="com.youge"></context:component-scan> <!-- 视图解析器对象--> <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"></property> <property name="suffix" value=".jsp"></property> </bean> <!-- 开启SpringMVC框架注解的支持--> <mvc:annotation-driven></mvc:annotation-driven> </beans> ~~~ ***** 第五步:index.jsp代码 ~~~ <%-- Created by IntelliJ IDEA. User: Administrator Date: 2020-09-24 Time: 20:52 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>spring mvc 入门</title> </head> <body> <h2>spring mvc 入门</h2> <a href="/hello">入门程序</a> </body> </html> ~~~ ***** 第六步:HelloController .java代码 ~~~ package com.youge.controller; /** * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com * @date: 2020-09-24 20:54 */ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** * 控制器 */ @Controller public class HelloController { @RequestMapping(path = "/hello") public String sayHello() { System.out.println("Hello SpringMVC"); // return "hello spring mvc"; return "success"; } } ~~~ ***** 第七步:success.jsp代码 ![](https://img.kancloud.cn/27/29/2729b3c73a3a5669fe38cf1d627b350b_332x155.png) ~~~ <%-- Created by IntelliJ IDEA. User: Administrator Date: 2020-09-24 Time: 21:12 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>成功</title> </head> <body> <h2>入门成功!!!!</h2> </body> </html> ~~~ 第八步:配置tomcat服务器 ![](https://img.kancloud.cn/d6/5b/d65b89ba2096455b330121fc7d0eda48_522x147.png) ![](https://img.kancloud.cn/db/f7/dbf76873277ca3a25e897c5b7bc55629_1080x856.png) ![](https://img.kancloud.cn/47/a0/47a0da33e9343cccae3cfbac5b3a0502_1049x790.png)