ssh整合三種方式(二)

2021-09-11 15:07:08 字數 1408 閱讀 9010

建立資料庫,建立web工程,建立實體類,編寫service層和dao層的介面和實現類。

具體事項:

(1) 把sessionfactory的建立交給spring管理;

(2) 在dao層配置使用jdbctemplate或hibernatetemplate運算元據庫,然後在spring配置檔案中配置jdbctemplate或hibernatetemplate;

(3) 修改hibernate的配置檔案,如下:

thread

改為:org.springframework.orm.hibernate5.springsessioncontext

(3) 配置事務。

具體事項:

(1) 在web.xml中配置如下:

需要在web.xml中手動指定配置檔案的位置,如下:

在dao層繼承 hibernatedaosupport 類,該類在內部有乙個hibernatetemplate屬性,並且提供了get方法,我們可以在dao層直接呼叫get方法得到hibernatetemplate,然後運算元據庫;

但是需要傳入sessionfactory,所有在配置檔案中需要給dao層的實現類新增乙個sessionfactory屬性。

在spring的配置檔案中,配置action,讓spring容器對action動作類進行初始化,在struts2的配置檔案中我們就可以直接寫類名,讓struts直接到spring的容器中拿動作類物件。

spring中的配置如下:

struts中的配置如下(不需要寫類的全限定類名):

spring和struts三種整合方式

1.用org.springframework.web.struts.actionsupport代替org.apache.struts.action.action類 public class testaction extents actioinsupport return forward.find s...

Spring 和 struts 整合的三種方式

1 使用spring 的 actionsupport 2 使用spring 的 delegatingrequestprocessor 類。3 全權委託。無論用那種方法來整合第一步就是要為struts來裝載spring的應用環境。就是在 struts 中加入乙個外掛程式。struts config.x...

Spring 和struts 整合的三種方式

spring 和 struts 整合的三種方式。1,使用spring 的 actionsupport 2,使用spring 的 delegatingrequestprocessor 類。3,全權委託。無論用那種方法來整合第一步就是要為struts來裝載spring的應用環境。就是在 struts 中...