• 第一个SpringMVC


    1.编写web.xml 放置于  WebContent/WEB-INF 下

     1 <?xml version ="1.0" encoding ="UTF-8"?>
     2 
     3 <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
     4 
     5     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
     6     xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee
     7         http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd ">
     8     <!-- 配置前端控制器 -->
     9     <servlet>
    10         <servlet-name>springmvc</servlet-name>
    11         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    12         <load-on-startup>1</load-on-startup>
    13         <!-- 初始化 -->
    14         <init-param>
    15             <param-name>contextConfigLocation</param-name>
    16             <!-- 绑定springmvc配置文件 -->
    17             <param-value>classpath:springmvc.xml</param-value>
    18         </init-param>
    19     </servlet>
    20 
    21     <!-- 使用前端控制器 -->
    22     <servlet-mapping>
    23         <servlet-name>springmvc</servlet-name>
    24         <!-- 配置拦截 -->
    25         <url-pattern>/</url-pattern>
    26     </servlet-mapping>
    27 
    28 </web-app>

    2.编写springmvc配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        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-4.3.xsd
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
        <!-- 开启spring注解扫描的包 -->
        <context:component-scan base-package="user" />
    
        <!-- 开启springmvc默认的器-->
        <mvc:annotation-driven></mvc:annotation-driven>
    
        <!-- 开启mvc的视图转化器 -->
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver"
            id="internalResourceViewResolver">
            <!-- 前缀 -->
            <property name="prefix" value="/WEB-INF/view/" />
            <!-- 后缀 -->
            <property name="suffix" value=".jsp" />
        </bean>
    
    </beans>

    3.建立处理类

    package user;
    
    import java.util.Date;
    
    import javax.xml.crypto.Data;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    import converter.date_converter;
    import javabean.userbean;
    
    @Controller
    @RequestMapping("/user")
    public class user {
        @RequestMapping(path="/init")
        public String denglu(userbean user,Data data) {
            System.out.println("成功了"+user);
            System.out.println(data);
            return "init";
        }
        
    }
  • 相关阅读:
    【洛谷 P5357】 【模板】AC自动机(二次加强版)(AC自动机,差分)
    【洛谷 P1659】 [国家集训队]拉拉队排练(manacher)
    【洛谷 P3224】 [HNOI2012]永无乡(Splay,启发式合并)
    HNOI2019退役祭
    类欧几里得算法模板
    乘法逆元模板
    $Luogu$ $P3130$ $[USACO15DEC]$ 计数 $Counting$ $Haybales$
    $Luogu$ $P2746$ $[USACO5.3]$ 校园网 $Network$ $of$ $Schools$
    $Luogu$ $P2243$ 电路维修
    $Luogu$ $P4667$ $[BalticOI$ $2011$ $Day1]$ 打开灯泡 $Switch$ $the$ $Lamp$ $On$
  • 原文地址:https://www.cnblogs.com/miwujun/p/12856453.html
Copyright © 2020-2023  润新知