• 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>

     

  • 相关阅读:
    MongoDB开发应用实战
    throw 与 throws的应用
    JAVA异常
    【354】Numpy 相关函数应用
    【353】线性回归损失函数求导举例
    【352】矩阵转置性质
    【351】实数对向量求导公式及推导
    【350】机器学习中的线性代数之矩阵求导
    智能电视TV开发---客户端和服务器通信
    GPS两点的距离
  • 原文地址:https://www.cnblogs.com/lijun6/p/11160186.html
Copyright © 2020-2023  润新知