zoukankan      html  css  js  c++  java
  • 第二讲 springmvc 注解配置

    <!-- web.xml 配置 -->
    <!-- ====================================== -->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 可以自定义servlet.xml配置文件的位置和名称,默认为WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,如spring-servlet.xml
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-servlet.xml</param-value>  默认
        </init-param>
        -->
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    <!-- servlet.xml 配置 -->
    
    <?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:mvc="http://www.springframework.org/schema/mvc"
    
           xmlns:p="http://www.springframework.org/schema/p"
    
           xmlns:context="http://www.springframework.org/schema/context"
    
           xmlns:aop="http://www.springframework.org/schema/aop"
    
           xmlns:tx="http://www.springframework.org/schema/tx"
    
           xsi:schemaLocation="http://www.springframework.org/schema/beans
    
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    
                http://www.springframework.org/schema/context 
    
                http://www.springframework.org/schema/context/spring-context-3.0.xsd
    
                http://www.springframework.org/schema/aop 
    
                http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    
                http://www.springframework.org/schema/tx 
    
                http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    
                http://www.springframework.org/schema/mvc 
    
                http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    
                http://www.springframework.org/schema/context 
    
                http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
        <!-- 默认扫描的包路径 -->  
    
        <context:component-scan base-package="cn.xy.hello" />  
    
        <!-- 添加注解驱动 -->  
    
        <mvc:annotation-driven />  
    
        <!-- 定义跳转的文件的前后缀 -->  
    
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
    
            <property name="prefix" value="/WEB-INF/jsp/" />  
    
            <property name="suffix" value=".jsp" />  
    
        </bean>  
    
    </beans>
    

      

    //Java代码
    package cn.xy.hello; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class IndexController { @RequestMapping("/index") public String index() { System.out.println("hello"); return "index.jsp"; } @RequestMapping("/hello1") public String hello() { System.out.println("hello1"); // return "forward:index.jsp"; //转发
    //     return "redirect:index.jsp" //重定向
        }
    }
    

      

  • 相关阅读:
    P1967 货车运输【最大生成树+倍增LCA】!!!
    P1991 无线通讯网【kruskal】
    P2872 [USACO07DEC]Building Roads S【kruskal】
    最小生成树
    树的直径
    树的重心
    今日英语单词小结
    项目生命周期
    反射reflect(框架的基石),动态导入小技巧 | 元类 | 单例设计模式
    OOP的三大特征之多态 | 面向对象高级知识,内置魔法函数,点语法和[ ]取值的实现,运算符重载,迭代器协议,上下文管理
  • 原文地址:https://www.cnblogs.com/needly/p/5738008.html
Copyright © 2011-2022 走看看