SSH整合步骤

整合步骤
1.引入jar包
2.配置文件web.xml.struts.xml
3.创建包结构
4.两两整合:struts2整合spring
创建页面:创建保存商品的页面
5.编写Action,Service,Dao
6.配置Action,Service和Dao
自动注入时候:




使用struts自己生成adction时候:











此时的struts.xml:

   
     
   












当使用spring来管理时候:需要加一个adction配置





 










此时struts.xml发生变化:

   
     !!!!!!!!此处class发生变化
   






7.spring整合hiberate
步骤七:创建数据库
步骤8:创建映射文件:XXXX.hbm.xml
创建属性文件:jdbc.properties
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssh
jdbc.username=root
jdbc.password=123


在applicationContext.xml中需要配置连接池













 
 
 
 
 
  domain/Product.hbm.xml
 

 

 



org.hiberate.dialect.MySQLDialect








步骤8:
使用hiberate模版:直接继承
public class ProductDao extends HibernateDaoSupport{!!!!!继承
/*
* Dao中保存商品的方法
*/
public void save(Product product) {
System.out.println("Dao中的方法执行了");
//使用模版了,然后在applicationContenxtx,xml配置,
this.getHibernateTemplate().save(product);
}


}




步骤9:事务管理






开启注解事务:


在业务上service
@Transactional

你可能感兴趣的:(ssh)