springMvc配置文件配置哪些常配制?

springMvc配置文件配置哪些常配制?

首先引入schema 什么都不用说了吧。

然后就是配置资源路径

<mvc:resources mapping="/skin/**" location="/skin/"/>

之后引入注解驱动

<mvc:annotation-driven />

然后注解的组建扫描路径统一放在com/res目录下

<context:component-scan base-package="com.res" />

接下来配置文件前缀后缀 例子是velocity开发的

<bean id="velocityConfig"
        class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="configLocation" value="/WEB-INF/classes/velocity.properties" />
        <property name="resourceLoaderPath">
            <value>/WEB-INF/vm/</value>
        </property>
        <property name="velocityProperties">
            <props>
                <prop key="input.encoding">gbk</prop>
                <prop key="output.encoding">gbk</prop>
            </props>
        </property>
    </bean>
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <property name="suffix">
            <value>.vm</value>
        </property>
        <property name="contentType">
            <value>text/html;charset=gbk</value>
        </property>
        <property name="exposeSessionAttributes">
            <value>true</value>
        </property>
        <property name="toolboxConfigLocation" value="/WEB-INF/classes/toolbox.xml"/>
        <property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityToolboxView"/>
    </bean>

之后配置文件上传限制什么的

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="10240000"/>     
    </bean>

最后配置拦截器处理

    <mvc:interceptors >  
          <mvc:interceptor>
            <mvc:mapping path="/member/*" />
            <mvc:mapping path="/resource/*" />
            <bean class="com.res.utils.interceptors.MemberAuthInterceptor"></bean>  
        </mvc:interceptor>
    </mvc:interceptors>

温馨提示:答案为网友推荐,仅供参考
相似回答