• springMVC快速入门 共分为五步


     

    springMVC快速入门 共分为5步分别为:

     1 导入依赖

    ​​ 2 spring-mvc.xml 配置

    ​ 3 web.xml配置

    ​ 4 自定义一个核心控制类

    ​ 5 页面配置

    详细步骤以及代码如下:

    1 导入依赖

    <dependencies>
      <!--spring的核心包-->
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.0.2.RELEASE</version>
      </dependency>
      <!--springMVC的包-->
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>5.0.2.RELEASE</version>
      </dependency>
      <!--servlet-api的包-->
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <!--maven项目执行分为三个阶段 编译 测试 运行-->
        <scope>provided</scope>
      </dependency>

      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
      </dependency>
    </dependencies>

    ​ 2 spring-mvc.xml 配置


      <!--开启注解 扫描包-->
      <context:component-scan base-package="cn.lijun"></context:component-scan>

    ​ 3 web.xml配置


    <web-app>
    <display-name>Archetype Created Web Application</display-name>
    <!--配置servlet-->
    <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:spring-mvc.xml</param-value>
      </init-param>
    </servlet>
    <servlet-mapping>
      <servlet-name>DispatcherServlet</servlet-name>
      <url-pattern>/</url-pattern>
    </servlet-mapping>
    </web-app>

    ​ 4 自定义一个核心控制类


    /**
    * @author lijun
    * @date 2019/7/9 9:48
    */
    @Controller
    @RequestMapping("/test")
    public class TestController {
      @RequestMapping("/test")
      public String test(){
          System.out.println("我的第一个springMVC 测试成功");
          return "/WEB-INF/show.jsp";
      }
    }

    ​ 5 页面配置


    User: lijun
    Date: 2019/7/9
    Time: 9:46
    To change this template use File | Settings | File Templates.
    --%>
    <%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
      <title>Title</title>
    </head>
    <body>
      <a href="${pageContext.request.contextPath}/test/test">请求</a>
      <a href="${pageContext.request.contextPath}/test/test">请求1</a>
    </body>
    </html>

     

  • 相关阅读:
    VS2005 Web安装程序 创建程序菜单组
    文件夹 文件 加入/去除 Everyone全控
    [转]asp.net 部署数据库、开始菜单、桌面快捷方式实例
    身边的贵人
    AppCode下的cs类 取得相关路径
    遭遇“windows已经阻止此软件因为无法验证发行者”
    成功不是忽悠
    关于 软件注册授权 防止被大面积免费扩散 的设想
    [转]获取机器的硬件信息(CPU ID序列号, 主板信息,硬盘序列号,系统信息)
    递交辞呈之后
  • 原文地址:https://www.cnblogs.com/lijun6/p/11160186.html
Copyright © 2020-2023  润新知