【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
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...