【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基礎框架(前言)

来源:http://www.cnblogs.com/wuxinzhe/archive/2016/09/30/5922449.html
-Advertisement-
Play Games

一直希望能夠搭建一個完整的,基礎Web框架,方便日後接一些外快的時候,能夠省時省力,終於花了一周的時間,把這個東西搞定了。特此寫下此博客,一來是紀念,二來是希望能夠為別人提供方便。 ...


  一直希望能夠搭建一個完整的,基礎Web框架,方便日後接一些外快的時候,能夠省時省力,終於花了一周的時間,把這個東西搞定了。特此寫下此博客,一來是紀念,二來是希望能夠為別人提供方便。順帶說一下,恩,組合框架的各個部分用的版本有的是最新的,有的則不是,不敢保證最新版本下,按照這個整合方式,不會報錯...

 

簡單介紹一下,本框架的基本功能點:


 

  1. Spring:整個框架的主體部分,這個自不用說。
  2. SpringMVC:MVC部分我還是比較喜歡Spring的。
  3. MyBatis:選型的時候選擇這個ORM主要也是考慮其靈活性的問題,畢竟我也不知道,今後會遇到怎樣的需求,用Hibernate一來是不太會用,二來,我還是比較喜歡直接寫SQL來的簡單一點。
  4. SpringSecurity:這個主要是安全框架,負責用戶登錄驗證及整站許可權分配的相關事項(許可權分配真的很有用,這個我就不多說了)。
  5. EhCache:一個非常流行又非常簡單好用的緩存框架,並且目前已經支持分散式,如果覺得不好用,自己換成Redis也都OK。
  6. JCaptcha:一個簡單的驗證碼生成框架(或者說工具)。
  7. Log4J:現在沒人不知道這個日誌框架吧...

  按照這樣的選型,基本可以完成大部分網站的基礎框架,如:

    1. 用戶登錄管理,
    2. 整站許可權分配,
    3. 數據緩存,
    4. 登錄驗證碼,
    5. 資料庫操作,
    6. 統一異常處理,
    7. 日誌輸出。

  網上找了很多文章,大部分都是只有部分整合的,比如SSH整合,SSM整合,SpringMVC+SpringSecurity,等等,東一塊,西一塊,非常分散,而且每個人的配置方式還不一樣,不統一,有的人喜歡註解配置,有的人喜歡XML配置,有的文章甚至直接就是有東沒西,神龍見首不見尾。看的我是很鬱悶,很蛋疼,因為當我好不容易搭好一個SSM框架,我發現,我要管理用戶登錄及許可權分配的時候,咦,我還得去配置Security,然後又要找很多文章來補充知識,配置Security的時候,又要找驗證碼的框架,都搞好了以後,發現誒,緩存這個東西不都是任何一個網站必備的嗎?所以就有了現在這篇文章,花了好大得勁,終於把所有都整合起來了。

但是,本文章,不提供項目源碼!

只有自己親手走過一遍,才真正學得會知識。作為一個程式員,我相信這樣才是對我們是最好的一個方式。所以不要索要源碼,不會給的。 先給出整個項目的

Pom.xml


 

  1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3     <modelVersion>4.0.0</modelVersion>
  4     <groupId>com.magic.rent</groupId>
  5     <artifactId>ssm</artifactId>
  6     <packaging>war</packaging>
  7     <version>1.0-SNAPSHOT</version>
  8     <name>ssm Maven Webapp</name>
  9     <url>http://maven.apache.org</url>
 10     <repositories>
 11         <repository>
 12             <id>atlassian</id>
 13             <name>atlassian</name>
 14             <url>http://maven.jahia.org/maven2/</url>
 15         </repository>
 16     </repositories>
 17     <build>
 18         <finalName>ssm</finalName>
 19         <plugins>
 20             <!--Mybatis 逆向工程插件-->
 21             <plugin>
 22                 <groupId>org.mybatis.generator</groupId>
 23                 <artifactId>mybatis-generator-maven-plugin</artifactId>
 24                 <version>1.3.2</version>
 25                 <configuration>
 26                     <verbose>true</verbose>
 27                     <overwrite>true</overwrite>
 28                 </configuration>
 29             </plugin>
 30         </plugins>
 31     </build>
 32     <properties>
 33         <security.version>4.1.3.RELEASE</security.version>
 34         <spring.version>4.3.3.RELEASE</spring.version>
 35     </properties>
 36     <dependencies>
 37         <!-- SpringFramework Start -->
 38         <dependency>
 39             <groupId>org.springframework</groupId>
 40             <artifactId>spring-core</artifactId>
 41             <version>${spring.version}</version>
 42         </dependency>
 43 
 44         <dependency>
 45             <groupId>org.springframework</groupId>
 46             <artifactId>spring-web</artifactId>
 47             <version>${spring.version}</version>
 48         </dependency>
 49 
 50         <dependency>
 51             <groupId>org.springframework</groupId>
 52             <artifactId>spring-oxm</artifactId>
 53             <version>${spring.version}</version>
 54         </dependency>
 55 
 56         <dependency>
 57             <groupId>org.springframework</groupId>
 58             <artifactId>spring-tx</artifactId>
 59             <version>${spring.version}</version>
 60         </dependency>
 61 
 62         <dependency>
 63             <groupId>org.springframework</groupId>
 64             <artifactId>spring-jdbc</artifactId>
 65             <version>${spring.version}</version>
 66         </dependency>
 67 
 68         <dependency>
 69             <groupId>org.springframework</groupId>
 70             <artifactId>spring-webmvc</artifactId>
 71             <version>${spring.version}</version>
 72         </dependency>
 73 
 74         <dependency>
 75             <groupId>org.springframework</groupId>
 76             <artifactId>spring-aop</artifactId>
 77             <version>${spring.version}</version>
 78         </dependency>
 79 
 80         <dependency>
 81             <groupId>org.springframework</groupId>
 82             <artifactId>spring-context-support</artifactId>
 83             <version>${spring.version}</version>
 84         </dependency>
 85 
 86         <dependency>
 87             <groupId>org.springframework</groupId>
 88             <artifactId>spring-test</artifactId>
 89             <version>${spring.version}</version>
 90         </dependency>
 91 
 92         <dependency>
 93             <groupId>org.springframework</groupId>
 94             <artifactId>spring-expression</artifactId>
 95             <version>${spring.version}</version>
 96         </dependency>
 97         <!-- SpringFramework End -->
 98 
 99         <!--SpringSecurity Start-->
100         <dependency>
101             <groupId>org.springframework.security</groupId>
102             <artifactId>spring-security-core</artifactId>
103             <version>${security.version}</version>
104         </dependency>
105         <dependency>
106             <groupId>org.springframework.security</groupId>
107             <artifactId>spring-security-web</artifactId>
108             <version>${security.version}</version>
109         </dependency>
110         <dependency>
111             <groupId>org.springframework.security</groupId>
112             <artifactId>spring-security-config</artifactId>
113             <version>${security.version}</version>
114         </dependency>
115         <dependency>
116             <groupId>org.springframework.security</groupId>
117             <artifactId>spring-security-taglibs</artifactId>
118             <version>${security.version}</version>
119         </dependency>
120         <dependency>
121             <groupId>org.springframework.security</groupId>
122             <artifactId>spring-security-crypto</artifactId>
123             <version>${security.version}</version>
124         </dependency>
125         <!--SpringSecurity End-->
126 
127         <!--aspectj start-->
128         <dependency>
129             <groupId>org.aspectj</groupId>
130             <artifactId>aspectjweaver</artifactId>
131             <version>1.8.6</version>
132         </dependency>
133 
134         <dependency>
135             <groupId>org.aspectj</groupId>
136             <artifactId>aspectjrt</artifactId>
137             <version>1.8.6</version>
138         </dependency>
139         <!--aspectj end-->
140 
141         <!--c3p0-->
142         <dependency>
143             <groupId>com.mchange</groupId>
144             <artifactId>c3p0</artifactId>
145             <version>0.9.5.1</version>
146         </dependency>
147 
148         <!--servlet/jsp api start-->
149         <dependency>
150             <groupId>javax.servlet</groupId>
151             <artifactId>servlet-api</artifactId>
152             <version>2.5</version>
153         </dependency>
154 
155         <dependency>
156             <groupId>javax.servlet.jsp</groupId>
157             <artifactId>jsp-api</artifactId>
158             <version>2.1</version>
159             <scope>provided</scope>
160         </dependency>
161         <!--servlet/jsp api end-->
162 
163         <!--junit4-->
164         <dependency>
165             <groupId>junit</groupId>
166             <artifactId>junit</artifactId>
167             <version>4.11</version>
168             <scope>test</scope>
169         </dependency>
170 
171         <!--Mybatis-->
172         <dependency>
173             <groupId>org.mybatis</groupId>
174             <artifactId>mybatis</artifactId>
175             <version>3.3.0</version>
176         </dependency>
177         <!--Mybatis Spring整合-->
178         <dependency>
179             <groupId>org.mybatis</groupId>
180             <artifactId>mybatis-spring</artifactId>
181             <version>1.2.3</version>
182         </dependency>
183 
184         <!--MySQL Driver-->
185         <dependency>
186             <groupId>mysql</groupId>
187             <artifactId>mysql-connector-java</artifactId>
188             <version>5.1.6</version>
189         </dependency>
190 
191         <dependency>
192             <groupId>jstl</groupId>
193             <artifactId>jstl</artifactId>
194             <version>1.2</version>
195         </dependency>
196 
197         <!--JCaptcha驗證碼-->
198         <dependency>
199             <groupId>com.octo.captcha</groupId>
200             <artifactId>jcaptcha</artifactId>
201             <version>1.0</version>
202         </dependency>
203 
204         <!--公共工具包-->
205         <dependency>
206             <groupId>org.apache.commons</groupId>
207             <artifactId>commons-lang3</artifactId>
208             <version>3.4</version>
209         </dependency>
210 
211         <!--Ehcache緩存框架 start-->
212         <dependency>
213             <groupId>net.sf.ehcache</groupId>
214             <artifactId>ehcache-core</artifactId>
215             <version>2.6.11</version>
216         </dependency>
217         <!--Mybatis-Ehcache整合包-->
218         <dependency>
219             <groupId>org.mybatis</groupId>
220             <artifactId>mybatis-ehcache</artifactId>
221             <version>1.0.0</version>
222         </dependency>
223         <!--Ehcache-Web頁面及對象緩存-->
224         <dependency>
225             <groupId>net.sf.ehcache</groupId>
226             <artifactId>ehcache-web</artifactId>
227             <version>2.0.4</version>
228         </dependency>
229         <dependency>
230             <groupId>org.slf4j</groupId>
231             <artifactId>slf4j-api</artifactId>
232             <version>1.6.1</version>
233         </dependency>
234         <dependency>
235             <groupId>org.slf4j</groupId>
236             <artifactId>slf4j-log4j12</artifactId>
237             <version>1.6.2</version>
238         </dependency>
239         <!--Ehcache緩存框架 end-->
240     </dependencies>
241 </project>

項目結構截圖


 

[圖是高清的,我從1080P的屏幕下截取的]

[字太小可以下載到本地後放大,可以看得很清楚,親測]

[回頭有空,我再補一個目錄結構文檔]


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 在本地開發機中進行web項目的開發,部署到生產環境進行產品發佈時,需要將web應用的文件打包成war包,War包可以放在Tomcat下的webapps或者word目錄下,隨著tomcat伺服器的啟動,它可以自動被解壓。 這樣需要遠程上傳到webapps,調試起來比較麻煩。所以在發佈生產環境之前,最好 ...
  • 遞歸 反射 os模塊 sys模塊 hashlib加密模塊 正則表達式 反射 python中的反射功能是由以下四個內置函數提供:hasattr、getattr、setattr、delattr,改四個函數分別用於對對象內部執行:檢查是否含有某成員、獲取成員、設置成員、刪除成員。 os模塊 sys模塊 h ...
  • friend friend的聲明可以出現在授權類的public, protected 和private等任意區域, 把一個全局函數、另一個類的成員函數或另一個類聲明為授權類的friend,使它擁有訪問授權類任何成員的特權,有時為了簡化代碼的書寫,可以將友元的定義和聲明都放在授權類內,但它依然是友元而 ...
  • 題目: Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding elem ...
  • 動態記憶體的管理 C++中除了相容C的管理方式外,還額外提供了兩個運算符(不是函數)來管理動態記憶體: new 主要用於申請動態記憶體 delete 主要用於釋放動態記憶體 Note: 1. 運算符VS函數,運算符不需要找庫,直接被編譯器內部支持 2. 將指針置為空指針可以避免多次delete所引起的cor ...
  • 興趣所致研究一下HashMap的源碼,寫下自己的理解,基於JDK1.8。 本文大概分析HashMap的put(),get(),resize()三個方法。 首先讓我們來看看put()方法。 1.首先通過hash(key)計算key的hash值 2.由於hashMap實際存儲數據的就是table數組,那 ...
  • 成員變數指針 解引用: 成員變數指針存的不是絕對的地址,而是成員變數相對與對象開頭地址的長度,解引用時根據對象的起始地址和成員變數指針中存放的相對地址,計算其目標成員的絕對地址,這樣就可以訪問成員變數了 例子 成員函數指針 通過成員函數指針調用函數 Note: 成員函數指針存儲的就是特定函數的在代碼 ...
  • 靜態成員變數 1. static成員變數是類級變數(用來處理這中類型的對象,共用的數據,屬於整個類型,記憶體中只有一份)。和全局變數以及靜態局部變數一樣,存放在進程的靜態存儲區(數據區+BSS區)。 2. 靜態成員變數必須在類外進行初始化, 不能在構造函數中初始化 例子 include using n ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...