• 第二讲 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" //重定向
        }
    }
    

      

  • 相关阅读:
    ps背景橡皮擦工具详解
    Application called By IE on Pseudo B/S Mode
    一种B/S模式下基于JAVA反射机制的可伸缩动态加载模块的解决方案
    Compile the latest Kernel(linux3.1rc4) On Ubuntu Plateform
    HttpService & WebService For Flex Develop
    国外的一个flex入门教学~[转]
    HQL略解
    How to build a Flex development platform based on Myeclipse8.6 & Flex4
    基于Pipe的PureMVC Flex框架的多核共享消息技术
    Ninject IOC<一>
  • 原文地址:https://www.cnblogs.com/needly/p/5738008.html
Copyright © 2020-2023  润新知