這兩天要開新項目 , 准備使用比較受歡迎的 jeesite框架 .
jeesite是一個寫好的網站 , 用到的框架比較多 具體請看 -- > github鏈接
下載下來之后 , 手動把maven版本改成了普通的web項目 , 然后導入數據庫 . 啟動成功 .
接下來開始了解項目的基本構成 , 我比較喜歡先從程序的入口開始分析 , 發現直接打開項目地址 會自動跳轉到登陸地址(a/login) ,然后就分析這個跳轉是怎么做的 .
比較納悶的是 , web.xml沒有歡迎頁面 直接就跳轉了 . 后來分析了 springMVC的配置 發現 spring-mvc.xml里面有如下代碼 :
<!-- 定義無Controller的path<->view直接映射 --> <mvc:view-controller path="/" view-name="redirect:${web.view.index}"/>
意思注釋說的很明白 , 如果直接訪問項目的根目錄 即: localhost:8080/projectName/ 則會直接跳轉到 view-name 里面的地址 "redirect"的意思是重定向 . ${web.view.index} 這個是spring通過加載 xxxx.properties 文件獲得的全局變量 . 加載properties 文件配置如下 :
<!-- 加載配置屬性文件 --> <context:property-placeholder ignore-unresolvable="true" location="classpath:jeesite.properties" />
這樣就把 該 properties 文件里面所有 key-value 加載到spring全局里面 . 然后在所有的spring配置里面 都可以用 類似 ${key} 來調用相應的值 , 很方便 .
來看看這個${web.view.index}在 jeesite.properties 文件里是多少 :
web.view.index=/a
/a
看到這里應該明白 , 如果直接訪問項目根目錄 , 則直接跳轉到 localhost:8080/projectName/a 這個url . 漸漸的有眉目了 , 但還不夠 .
全局搜索 /a 是啥意思 , 發現jeesite.properties里面有個 值
adminPath=/a
有個 adminPath 承接了這個 /a 路徑 .
jeesite 還用了一個管理權限的框架 , 也是第一次接觸 叫 Apache Shiro . 項目中有個 spring-context-shiro.xml 配置文件 , 就是關於shiro的配置 . 其中就有一段 這樣的配置 :
<!-- Shiro權限過濾過濾器定義 --> <bean name="shiroFilterChainDefinitions" class="java.lang.String"> <constructor-arg> <value> /static/** = anon /userfiles/** = anon ${adminPath}/cas = cas ${adminPath}/login = authc ${adminPath}/logout = logout ${adminPath}/** = user /act/editor/** = user /ReportServer/** = user </value> </constructor-arg> </bean>
具體的意思 可以了解一下shiro
${adminPath}/** = user 關鍵在於這句話 意思是 訪問的鏈接 是類似 ${adminPath}/** 這個的話 , 則 必須得有用戶登錄 , 否則跳轉到登陸界面 . 而 ${adminPath} 又恰好是 /a 於是 如果 有 /a/** (**是匹配所有的意思) 鏈接 , 則需要登陸 ,如果沒有登陸則跳轉到 登陸界面 .
至此 , 登陸跳轉大致算清晰了 .