在创建好 web 项目后,加入 Servlet 依赖,SpringMVC 依赖

    servlet**SpringMVC **依赖:

    1. <dependencies>
    2. <dependency>
    3. <groupId>junit</groupId>
    4. <artifactId>junit</artifactId>
    5. <version>4.11</version>
    6. <scope>test</scope>
    7. </dependency>
    8. <!-- SpringMVC -->
    9. <dependency>
    10. <groupId>org.springframework</groupId>
    11. <artifactId>spring-webmvc</artifactId>
    12. <version>5.3.1</version>
    13. </dependency>
    14. <!-- 日志 -->
    15. <dependency>
    16. <groupId>ch.qos.logback</groupId>
    17. <artifactId>logback-classic</artifactId>
    18. <version>1.2.3</version>
    19. </dependency>
    20. <!-- ServletAPI -->
    21. <dependency>
    22. <groupId>javax.servlet</groupId>
    23. <artifactId>javax.servlet-api</artifactId>
    24. <version>3.1.0</version>
    25. <scope>provided</scope> </dependency>
    26. <!-- Spring5Thymeleaf整合包 -->
    27. <dependency>
    28. <groupId>org.thymeleaf</groupId>
    29. <artifactId>thymeleaf-spring5</artifactId>
    30. <version>3.0.12.RELEASE</version>
    31. </dependency>
    32. </dependencies>

    注:由于 Maven 的传递性,我们不必将所有需要的包全部配置依赖,而是配置最顶端的依赖,其他靠传递性导入。
    image.png

    插件:

    1. <build>
    2. <plugins>
    3. <!-- 编码和编译和JDK版本 -->
    4. <plugin>
    5. <artifactId>maven-compiler-plugin</artifactId>
    6. <version>3.8.0</version>
    7. <configuration>
    8. <source>16</source>
    9. <target>16</target>
    10. </configuration>
    11. </plugin>
    12. </plugins>
    13. </build>