Spring 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 中国語 Web サイトの他の関連記事に注目してください。

関連書籍:

Hibernate のマッピング ファイルの詳細な説明


Maven 設定ファイル pom.xml の使用

以上がSpring MVC 構成の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!