스프링 MVC 구성

php中世界最好的语言
풀어 주다: 2018-03-07 16:48:00
원래의
1604명이 탐색했습니다.

이번에는 Spring의 MVC 구성에 대해 소개해 드리겠습니다. 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:p="http://www.springframework.org/schema/p" 
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:util="http://www.springframework.org/schema/util"
  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/util
  http://www.springframework.org/schema/util/spring-util.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" >
    <!-- 默认的注解映射的支持 -->  
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">  
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
                <property name="supportedMediaTypes" value="application/json"/>  
            </bean>  
        </mvc:message-converters> 
    </mvc:annotation-driven>
    <!-- 如果当前请求为“/”时,则转发到“/index” -->
    <mvc:view-controller path="/" view-name="forward:/index" /> 
    <!-- 静态资源映射 -->
    <mvc:resources mapping="js/**" location="/static/js/" />
    <mvc:resources mapping="css/**" location="/static/css/" />
    <mvc:resources mapping="fonts/**" location="/static/fonts/" />
    <mvc:resources mapping="plugins/**" location="/static/plugins/" />
    <mvc:resources mapping="images/**" location="/static/images/" /> 
    <!-- 当上面要访问的静态资源不包括在上面的配置中时,则根据此配置来访问 -->
    <mvc:default-servlet-handler/>
    <!-- 开启controller注解支持 -->
    <!-- use-default-filters="false" 只扫描指定的注解 -->
    <context:component-scan base-package="com.troyforever.example.mvc.controller" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan> 
    <!-- 视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
       <property name="contentType" value="text/html"/>        
       <property name="prefix" value="/WEB-INF/views/"/>
       <property name="suffix" value=".jsp"/>
    </bean></beans>
로그인 후 복사

이 기사의 사례를 읽으신 후 방법을 마스터하셨다고 생각합니다. 더 흥미로운 정보를 보려면 PHP 중국어 웹사이트의 다른 관련 기사를 주목하세요!

관련 읽기:

Hibernate 매핑 파일에 대한 자세한 설명


Maven 구성 파일 pom.xml 사용하기

위 내용은 스프링 MVC 구성의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!