-
Action類交給Spring創建(建議使用這種方式創建Action,因為可以使用Spring的AOP進行管理)(action創建的實例是多例模式,所以Action類bean標簽要使用scope=“prototype”屬性,其次action標簽的class屬性不再寫類的全路徑,而是Action<bean>標簽的id)
查看全部 -
步驟六:配置Action、Service、Dao的類——Struts2整合Spring
重點注意:Struts-Spring-plugin.jar:在不使用ApplicationContext情況下對Action里的productService進行賦值,要保證set方法后的名稱和<bean>標簽里的id名相同才會按名稱自動注入。
【a】Service和Dao可以交給Spring進行管理(配置bean標簽)。
copy Qualified Name:復制類的全路徑。
<bean id="productService" class="com.imooc.service.ProductService">
<property name="productDao" ref="productDao"></property>
</bean>
<bean id="productDao" class="com.imooc.dao.ProductDao"></bean>
?</beans>
【b】Struts2和Spring整合的兩種方式:(針對Action對象的創建方式)。
1、Action的類由Struts2去創建。
<package name="ssh" namespace="/" extends="struts-default">
<action name="product_*" class="com.imooc.action.ProductAction" method="{1}">
</action>
</package>
2、Action的類由 Spring去創建。
查看全部 -
引入相應配置文件
1、Struts2配置文件
web.xml(配置struts核心過濾器)
struts.xml(如果使用純注解開發,也可以省略)
2、Hibernate配置文件
hibernate.cfg.xml(在SSH整合中該配置文件可以省略)
映射文件
3、Spring框架的配置文件
web.xml(配置核心監聽器,作用是啟動服務器時候,加載Spring核心配置文件,該監聽器中還有一個參數(全局初始化參數),如果不配置這個,默認加載WEB-INF下的ApplicationContext.XML,配置了就會加載classes下的ApplicationContext.xml)
applicationContext.xml
查看全部 -
SSH知識點回顧
WEB層(V):Struts2
業務層(C):Spring
持久層(M):Hibernate
整合之后就不用寫這么多繁瑣的代碼。
Hibernate使用ServiceRegistryBuilder出錯
原因:版本4之后的Hibernate中buildServiceReguistry()方法被替換了。
解決方法:(1)版本導入更換為:
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
(2)在版本4中的用法:
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
(3)在版本5中的用法:
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();2018-03-27
查看全部 -
課程介紹
1、ssh知識點回顧
2、搭建ssh開發環境(包括引入哪些jar包完成整合)
3、整合(struts2整合spring、spring整合hibernate)
查看全部 -
引入相應的配置文件
Struts2配置文件:web。xml? ,Struts。xml
hibernate配置文件:hibernate.cfg.xml? ,映射文件
spring配置文件:web.xml ,applicationContext.xml
查看全部 -
SSH環境搭建:1.創建web項目。2.引入jar包(Struts2相關的jar包,spring相關的jar包,hibernate相關的jar包)
查看全部 -
ssh框架知識點回顧
web層 Struts2
業務層 Spring
持久層 Hibernate
通常web層區調用業務層,業務層調用持久層
查看全部 -
SSH框架知識點
查看全部 -
事務管理: 1,。在配置文件中 配置事務管理器 ,把 sessionfactory 注入; 2.在配置文件里開啟事務,<tx:annotation-driven......../> ;3 在業務層 service類上面 添加事務注解 @transactional
查看全部 -
在dao中使用hibernate模板 ,1.在 dao的類上繼承 sessionFactory 2.在applicationContext中 dao的bean 中注入 上面創建好的sessionfactory。之后在dao中就可以直接使用了( 在到中的save方法中 調用? this.gethibernateTemplate().save(product); 對 product 進行保存操作。)
查看全部 -
在applicationContext.xml中配置hibernate的相關信息
查看全部 -
在applicationContext。xml中配置數據庫連接。1.創建jdbc.properties 寫數據庫連接的信息。2.在applicationContext 中 引入外部的jdbc.properties文件。3配置c3p0連接池
查看全部 -
.hbm.xml 配置文件 1,約束信息;2<hibernate-mapping></>;3. class name =“實體類的全路徑” 4. table =“表名字”5.id name="實體類中的屬性名"(主鍵吧) column=“表中的字段名”(在空的表中hibernate 自動創建這個列)6.<property name ="實體類中的屬性" (普通屬性吧) column=“表中字段名”
查看全部 -
在action中寫的save方法? 調用 service 中的 save方法 并傳入參數 product【service中創建了save方法】。在service中調用 dao中的save方法 ,并傳入參數 product。dao中的save方法 ,得到product這個參數,會和數據庫打交道,比如,用sql語句向數據庫中插入值,(這里用hibernate)
查看全部
舉報