zoukankan      html  css  js  c++  java
  • <mvc:annotation-driven/>都做了那些事情

    mvc:annotation-driven是一种简写的配置方式,那么mvc:annotation-driven到底做了哪些工作呢?如何替换掉mvc:annotation-driven呢?

    <mvc:annotation- driven/>在初始化的时候会自动创建两个对 象,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter 和 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter, 我们如果想不使用<mvc:annotation-driven/>这种简写方式,将其替换掉的话,就必须自己手动去配置这两个bean对 象。下面是这两个对象的配置方法,和详细的注视说明。

    <?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
    
        <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
            <property name="useDefaultSuffixPattern" value="false" />
            <property name="interceptors">
                <list>
                    <bean class="org.mspring.mlog.web.interceptor.RememberMeInterceptor" />
                    <bean class="org.mspring.mlog.web.interceptor.SettingInterceptor" />
                    <bean class="org.mspring.platform.web.query.interceptor.QueryParameterInterceptor" />
                </list>
            </property>
        </bean>
    
        <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
        <bean
            class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="messageConverters">
                <list>
                    <-- 这个converter是我自己定义的,是为了解决spring自带的StringHttpMessageConverter中文乱码问题的 -->
                    <bean class="org.mspring.platform.web.converter.StringHttpMessageConverter">
                        <constructor-arg value="UTF-8" />
                    </bean>
                    <!-- 这里可以根据自己的需要添加converter -->
                    <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
                    <!-- -->
                </list>
            </property>
            <property name="customArgumentResolvers">
                <list>
                    <bean class="org.mspring.platform.web.resolver.UrlVariableMethodArgumentResolver" />
                </list>
            </property>
    
            <property name="webBindingInitializer">
                <bean id="webBindingInitializer"
                    class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
                    <property name="conversionService" ref="conversionService" />
                </bean>
            </property>
        </bean>
    
        <!-- 1, 注册ConversionService -->
        <bean id="conversionService"
            class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
            <property name="converters">
                <list>
                    <bean class="org.mspring.platform.web.converter.DateConverter">
                        <property name="pattern" value="yyyy-MM-dd HH:mm:ss" />
                    </bean>
                </list>
            </property>
            <property name="formatters">
                <list>
                    <bean class="org.mspring.mlog.web.formatter.factory.TagFormatAnnotationFormatterFactory"></bean>
                    <bean class="org.mspring.mlog.web.formatter.factory.EncodingFormatAnnotationFormatterFactory"></bean>
                </list>
            </property>
        </bean>
    
    </beans>
    View Code

    这样,我们就可以就成功的替换掉<mvc:annotation-driven />了。

  • 相关阅读:
    如何在Wyn Enterprise中实现数据脱敏
    报表工具中如何在表格实现累计同比
    同一报表,根据不同条件,执行不同Sql
    报表单元格内超过一定长度显示省略号,鼠标悬浮显示全部内容
    报表实现按照天/周/月/季度/年进行快速查询,并且根据快速选择条件进行汇总统计
    典型报表设计:项目应收款统计,行分组不汇总、分组内过滤、行记录和汇总计算
    报表表格实现自定义序号
    报表中常见模糊查询实现
    如何在仪表板表格中将日期显示为文本格式?
    MySQL动态数据源的实现
  • 原文地址:https://www.cnblogs.com/shines77/p/3315445.html
Copyright © 2011-2022 走看看