zoukankan      html  css  js  c++  java
  • springmvc-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"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
        <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    
        <bean id="/hello" class="com.zhang.controller.HelloController"/>
    </beans>
    

    注解版

    <?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.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
        <!--自动扫描包,让指定包下的注解生效,由IOC统一管理-->
        <context:component-scan base-package="com.zhang.controller"/>
        <!--让springmvc不处理静态资源-->
        <mvc:default-servlet-handler/>
        <!--支持mvc注解驱动,
            在spring中一般采用@RequestMapping注解来完成映射关系
            要想使@RequestMapping注解生效
            必须向上下文注册DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter实例
            这两个实例分别在类级别和方法级别处理。
            而annotation-dirven配置帮助我们自动完成上述两个实例的注入-->
        <mvc:annotation-driven/>
        <!--视图解析器-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
            <!--前缀-->
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <!--后缀-->
            <property name="suffix" value=".jsp"/>
        </bean>
    </beans>
    
  • 相关阅读:
    spring事物管理五种配置方式
    解决html中内部元素mouse事件干扰
    普通类获取ApplicationContext(附带servletContext)的方法
    SQL学习基础知识
    vs 工具技巧手册
    wcf client与webservice通信备注
    BackgroundWorker学习一
    silverlight发布注意事项
    将wcf 以webservice的方式调用
    Visual Studio 2005 Team Foundation Server (TFS)单服务器安装记
  • 原文地址:https://www.cnblogs.com/kaka-qiqi/p/14647922.html
Copyright © 2011-2022 走看看