当前位置 主页 > 服务器问题 > Linux/apache问题 >

    Spring MVC 简单的hello world的实现

    栏目:Linux/apache问题 时间:2020-01-19 00:40

    一、项目搭建

    1、可以在新建项目的使用Spring MVC框架。或者创建一个简单的项目之后再用Add Framework Support来添加Spring MVC框架。

    2、删除自动生成的lib的jar包,使用pom文件来进行管理包。目录结构如下图。

    3、pom文件。加载完成之后才能进行下一步。

    <?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.zxj</groupId>
     <artifactId>zxj-spring-mvc</artifactId>
     <version>1.0-SNAPSHOT</version>
     
     <name>zxj-spring-mvc</name>
     <url>http://www.example.com</url>
     <packaging>war</packaging>
     
     <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <maven.compiler.source>1.7</maven.compiler.source>
      <maven.compiler.target>1.7</maven.compiler.target>
      <spring.version>4.3.18.RELEASE</spring.version>
     </properties>
     
     <dependencies>
      <!--测试-->
      <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.12</version>
       <scope>test</scope>
      </dependency>
      <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-test</artifactId>
       <version>${spring.version}</version>
       <scope>test</scope>
      </dependency>
     
      <!--Spring-->
      <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-context</artifactId>
       <version>${spring.version}</version>
      </dependency>
      <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-aop</artifactId>
       <version>${spring.version}</version>
      </dependency>
      <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-aspects</artifactId>
       <version>${spring.version}</version>
      </dependency>
     
      <!--spring mvc-->
      <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.jsp.jstl</groupId>
       <artifactId>jstl-api</artifactId>
       <version>1.2</version>
      </dependency>
     </dependencies>
     
     <build>
      <finalName>${project.artifactId}</finalName>
      <plugins>
       <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.1.0</version>
       </plugin>
       <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.5.2</version>
       </plugin>
      </plugins>
     </build>
    </project>