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" //重定向
        }
    }
    

      

  • 相关阅读:
    解决centos7的root账户下无法通过code命令启动vscode
    centos7安装epel
    centos7用过yum安装vscode
    yum install gcc报错Error: Package: glibc-2.17-260.el7_6.6.i686 (updates) Requires: glibc-common = 2.17
    centos7通过yum从vim7升级到vim8
    解决VM虚拟机安装centos7无法联网
    centos7设置开机默认使用root账户登陆
    centos7使用sudo命令提示sudo command not found
    不同编译器下C++基本数据类型的字节长度
    C++函数模板
  • 原文地址:https://www.cnblogs.com/needly/p/5738008.html
Copyright © 2011-2022 走看看