日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringMVC-DispatcherServlet配置(Spring-servlet.xml)

發布時間:2023/12/31 javascript 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringMVC-DispatcherServlet配置(Spring-servlet.xml) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Spring-servlet.xml

  • <context:component-scan base-package="com.spring.mvc.controller"/>

    掃描指定的包中的類上的注解,常用的注解有:

    @Controller 聲明Action組件
    @Service??? 聲明Service組件??? @Service("myMovieLister")?
    @Repository 聲明Dao組件
    @Component?? 泛指組件, 當不好歸類時.?
    @RequestMapping("/menu")? 請求映射
    @Resource? 用于注入,( j2ee提供的 ) 默認按名稱裝配,@Resource(name="beanName")?
    @Autowired 用于注入,(srping提供的) 默認按類型裝配?
    @Transactional( rollbackFor={Exception.class}) 事務管理
    @ResponseBody
    @Scope("prototype")?? 設定bean的作用域

  • <mvc:annotation-driven /> 是一種簡寫形式,完全可以手動配置替代這種簡寫形式,簡寫形式可以讓初學都快速應用默認配置方案。<mvc:annotation-driven /> 會自動注冊DefaultAnnotationHandlerMapping與AnnotationMethodHandlerAdapter 兩個bean,是spring MVC為@Controllers分發請求所必須的。
  • 視圖解析類,使用普通bean的配置方式: 1 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 2 <property name="prefix" value="/WEB-INF/views/"></property> 3 <property name="suffix" value=".jsp"></property> 4 <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> 5 </bean>
  • 添加靜態資源訪問的支持: 1 <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>

    匹配URL? /resources/**? 的URL被當做靜態資源,由Spring讀出到內存中再響應http。

    或直接使用默認的Servlet來響應靜態文件。

    <mvc:default-servlet-handler/>

  • 示例:

    1 <?xml version="1.0" encoding="UTF-8"?>2 <beans xmlns="http://www.springframework.org/schema/beans"3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"4 xmlns:mvc="http://www.springframework.org/schema/mvc"5 xmlns:p="http://www.springframework.org/schema/p"6 xmlns:context="http://www.springframework.org/schema/context"7 xsi:schemaLocation="8 http://www.springframework.org/schema/beans9 http://www.springframework.org/schema/beans/spring-beans.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context.xsd 12 http://www.springframework.org/schema/mvc 13 http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 14 <context:component-scan base-package="com.spring.mvc.controller"/> 15 <mvc:annotation-driven/> 16 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 17 <property name="prefix" value="/WEB-INF/views/"></property> 18 <property name="suffix" value=".jsp"></property> 19 </bean> 20 <!--添加訪問靜態資源的功能 --> 21 <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources> 22 </beans>

    ?


    God, Grant me the SERENITY, to accept the things I cannot change, COURAGE to change the things I can, and the WISDOM to know the difference.

    總結

    以上是生活随笔為你收集整理的SpringMVC-DispatcherServlet配置(Spring-servlet.xml)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。