Spring跟mybatis的整合使用

2022-07-08 23:12:15 字數 810 閱讀 2168

第一步:

•建立web工程,加入spring和mybatis的有關jar

具體匯入jar包如下:

第二步:

•建立開發目錄結構,建立實體類

建立開發目錄結構如下:

建立實體類:

根據資料庫的表建立相關實體類,並且設定get,set方法以及tostring和建構函式(注:如果設定了有參的建構函式,為了減少不必要的麻煩,需要再設定乙個無參建構函式)

第三步:

•建立資料訪問介面

第四步:

•建立資料訪問介面的實現類

根據剛剛建立的資料訪問介面建立隊友的實現類,實現資料訪問介面方法

第五步:

•配置sql對映語句檔案

在xml檔案中配置需要用到的對映語句。

第六步:

•配置mybatis應用配置檔案

在mybatis-config.xml中配置需要的配置檔案如:

第七步:

•配置spring應用配置檔案

最後就可以在測試類中測試了:

spring跟struts的整合步驟

1.加入jar包 複製檔案。複製struts2 spring plugin x x x.jar和spring.jar到web inf lib目錄下。其中的x對應了spring的版本號。還需要複製commons logging.jar struts2 core 2.3.4.1.jar檔案到web in...

spring和mybatis的整合

若要整合spring和mybatis就需要乙個外掛程式即mybatis spring x.x.x.jar。具體的安裝如下所示 org.mybatis mybatis spring x.x.x 要和spring一起使用 mybatis,還需要在 spring 應用上下文中定義至少兩樣東西 乙個 sql...

Spring和Mybatis的整合

需要spring和mybatis的整合包 mybatis spring 1.2.2.jar 在spring容器中載入sqlsessionfactory類 org.mybatis.spring.sqlsessionfactorybean a.需要載入mybatis的配置檔案 configlocatio...