您的位置:首页 > 编程语言 > Java开发

ssm整合框架 Spring—MVC基本配置 spring-servlet.xml配置详解

2018-10-30 23:15 429 查看
版权声明:转载请注明出处 https://blog.csdn.net/langruu/article/details/83550515

以下为ssm框架整合开发中,对Spring-MVC的配置,文件名为spring-servlet.xml。最下的代码可直接粘贴到spring-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:p="http://www.springframework.org/schema/p"
    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-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/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.0.xsd">

    <!-- 启用注解 -->
    <mvc:annotation-driven/>
    <!-- 设置使用注解的类所在的包    必须设置-->
    <context:component-scan base-package="com.wen.ctrl"></context:component-scan>
    <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀    必须设置 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/" p:suffix=".jsp" />
    <!-- 配置MultipartResolver,用于上传文件,使用spring的CommonsMultipartResolver -->  
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <!-- 设置上传文件大小,单位byte -->
            <property name="maxUploadSize" value="5000000"/>
            <!-- 设置文件名称编码 -->
            <property name="defaultEncoding" value="UTF-8"/>
    </bean>
  <!-- 对静态资源文件的访问--> 
    <mvc:resources location="/css/" mapping="/css/**" cache-period="31556926"/>
    <mvc:resources location="/images/" mapping="/images/**" cache-period="31556926"/>
    <mvc:resources location="/js/" mapping="/js/**" cache-period="31556926"/>
</beans>

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐