zoukankan      html  css  js  c++  java
  • Spring MVC(二)

    Spring MVC配置

    约束

    beans约束:spring必须
    context约束:注解和扫描
    spring-mvc约束:静态资源、允许跨域以及拦截器

    <?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"
           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">
    </beans>
    

    扫包

    必须配置context约束

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

    前端控制映射器

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
        <!--前缀-->
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <!--后缀-->
        <property name="suffix" value=".jsp"/>
    </bean>
    

    静态资源放行

    如果要使用mvc配置,需要引入mvc约束,
    如果配置静态资源过滤放行,需要加一句

    <mvc:annotation-driven />
    

    过滤:

    <mvc:resources mapping="/editor/**" location="/editor/"/>
    <mvc:resources mapping="/bootstrap/**" location="/bootstrap/"/>
    <mvc:resources mapping="/imgs/**" location="/imgs/"/>
    

    跨域

    <mvc:cors>
        <mvc:mapping path="/**" allowed-origins="*" allowed-methods="*" allowed-headers="*"/>
    </mvc:cors>
    

    拦截器

    <!--配置拦截器-->
    <mvc:interceptors>
        <mvc:interceptor>
            <!--配置拦截器作用的路径-->
            <mvc:mapping path="/**"/>
            <bean class="com.mysite.interceptor.LoginInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>
    
  • 相关阅读:
    POJ3070 Fibonacci 快速矩阵幂
    HDU1299 Diophantus of Alexandria 素因子分解
    HUTXXXX The window of the dazzling 模拟
    HUTXXXX 周正虎的难题 二分
    使用js给页面元素添加样式
    javascript 获取操作系统语言
    div层一直处于页面中间
    javascript:history.go()和History.back()的区别
    javascript的一些常用正则表达式
    [七日成魔2.1版]完美PHOTOSHOP教程新手培训套餐
  • 原文地址:https://www.cnblogs.com/heibaimao123/p/13801030.html
Copyright © 2011-2022 走看看