SSH整合
筆者剛剛接觸SSH框架,如今ssh是個比較老的框架了,因此用IDEA建立JAVAEE項目時候使用的是jdk1.7和web application3.1版本tomcat使用8.5
第一步:導入jar包
- struts-2.3.37
- spring-framework-3.2.0.RELEASE
- hibernate-release-5.4.3.Final
具體以下前端
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
接下來導入的配置文件都是能夠從上面三個jar包去尋找的,找到以後修改便可。
第二步:spring整合hibernate的單元測試
- 只需建立一個數據庫,無需建立表,Hibernate自動生成
- 編寫model類(也成po)和映射文件
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
- 可簡化:把hibernate.cfg.xml配置文件放在applicationContext.xml
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
上圖中hibernate的映射文件路徑 value中的切入點表達式爲通用寫法web
- execution()
用於描述方法
語法:execution(修飾符 返回值 包.類.方法名(參數)throws 異常)
第三步:spring整合struts
編寫action類,並將其配置給spring,sprring能夠注入service
複製struts.xmlspring
表單jsp頁面數據庫
web.xml配置
- 配置文件contextConfigLocation
- 配置監聽器ContextLoaderListener
- 配置前端控制器StrutsPrepareAndExecuteFilter
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
action中service默認會根據名稱注入,默認狀況下框架使用的自動裝配策略是name,
框架會在spring中去尋找與action屬性名字相同的bean
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)
![圖片描述 圖片描述](http://static.javashuo.com/static/loading.gif)