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