1. 程式人生 > >SpringMVC 學習 十 SSM環境搭建(三)springMVC檔案配置 springMVC學習三 註解開發環境搭建

SpringMVC 學習 十 SSM環境搭建(三)springMVC檔案配置 springMVC學習三 註解開發環境搭建

SpringMVC檔案配置的詳細過程,可以檢視springMVC環境搭建的註解配置篇《springMVC學習三 註解開發環境搭建

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://www.springframework.org/schema/beans"
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-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd "
> <!-- 開啟掃描註解的包 當前的配置檔案是被DispatcherServlet載入的 注意,此處的處理器所在的包要在springMVC的配置檔案中進行掃描,不能在spring的配置檔案中進行 掃描,因為處理器要註冊到springMVC容器中,也就是controller所在的包需要被SpringMVC容器掃描, 不能被Spring容器所掃描 --> <context:component-scan base-package="com.ssm.controller"></
context:component-scan> <!-- 註解驅動 --> <!-- 上面的註解相當於下面兩個類 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter --> <mvc:annotation-driven></mvc:annotation-driven> <context:annotation-config /> <!-- 放行靜態資源,不攔截靜態資源 --> <!-- /js/* 代表專案下的js資料夾下的所有的檔案 /js/js** 代表專案下的js資料夾下的所有檔案以及子資料夾下的所有檔案 <mvc:resources location="/js/" mapping="/js/**"></mvc:resources> 上面的mapping代表的是請求的資源的請求路徑,location請求的資源所在的伺服器的路徑 下面代表:只要發現 請求路徑 符合/js/**格式,就到當前專案所在的本地伺服器的/js/路徑下去找資源 --> <mvc:resources location="/js/" mapping="/js/**"></mvc:resources> <mvc:resources location="/css/" mapping="/css/**"></mvc:resources> <mvc:resources location="/images/" mapping="/images/**"></mvc:resources> <!-- 註冊 檢視解析器 有時候,我們為了保護頁面不被別人訪問,可以把頁面放在WEB-INF中, 就可以把prefix配置成"/WEB-INF/" 【注意】檢視解析器是解析處理器最後的return 的值,並非我們在前端自己輸入的請求 如果return 的檢視有字首(forward或者redirect),檢視解析器用預設的,如果沒有字首,則用我們自己配置的 --> <bean id="viewResolver" class=" org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"></property> <property name="suffix" value=""></property> </bean> </beans>