ssh框架整合 初級

2021-07-27 03:33:20 字數 1748 閱讀 7851

2017.2.15-2017.2.17

將action的配置交給spring解決

匯入jar包

整合jar包:struts2-spring-plugin.jar

在spring配置檔案中配置action物件(注意:action為多例)

在struts配置檔案中配置action

在web.xml中配置,使伺服器一啟動就載入spring配置檔案

contextconfiglocation

classpath:bean1.xml

org.springframework.web.context.contextloaderlistener

1. 把資料庫資訊在spring中進行配置 2. 把hibernate裡面sessionfactory的建立交給spring管理

在spring核心配置檔案中配置資料庫資訊

在spring核心配置檔案中建立sessionfactory物件

配置spring事務,並在service類或dao類中新增@transactional註解

其他基礎操作的無異

根據id查詢

user user=hibernatetemplate.get(user.class,1);
find方法使用:find(hql語句,條件)

//查詢表中的所有記錄

listlist=hibernatetemplate.find("from t_user");

//根據條件查詢

listlist=hibernatetemplate.find("from t_user where username=?","zcw");

匯入jar包

搭建struts2環境

建立action,建立struts.xml配置檔案,配置action

配置struts2的過濾器

搭建hibernate環境

建立實體類

配置實體類和資料庫表對映關係

建立hibernate和核心配置檔案,引入對映配置檔案

搭建spring環境

建立spring核心配置檔案

讓spring配置檔案在伺服器啟動的時候載入(在web.xml配置***、指定spring配置的位置)

struts2和spring整合

在action在spring配置,注意:action為多例項

在struts.xml的action標籤的class屬性裡面寫bean的id值

spring和hibernate整合

把hibernate核心配置檔案中資料庫配置,在spring中配置

把hibernate的sessionfactory在spring中配置

到dao裡面使用hibernatetemplate

在dao裡注入hibernatetemplate物件

在hibernatetemplate物件中注入sessionfactory

配置事務

SSH框架整合

首先將 spring 加入到web容器在 web.xml 中加入 context param param name contextconfiglocation param name 說明 為了管理方便設定了多個 spring 的配置檔案 context param 然後加入 spring liste...

SSH框架整合

版本 struts 2.3.30,spring framework 3.2.10.release,hibernate distribution 3.6.0.final 一 引入相關jar檔案 二 struts.xml配置 apache software foundation dtd struts c...

SSH框架整合

記事本手打 正確率略低 1.匯入jar包 name cn.com.product table product name pid column pid class native id name pname column pname property name page column page prop...