spring4.1.2、hibernate4.3.7、struts2.3.16.3搭建学习例子

此种搭建框架的例子已有很多,本文只供参考。

环境

myeclipse5.5GA、mysql、tomcat6.0、jdk6.0

版本

spring4.1.2、hibernate4.3.7、struts2.3.16.3,可去官网下载。

jar包

spring4.1.2、hibernate4.3.7、struts2.3.16.3搭建学习例子_第1张图片

spring4.1.2、hibernate4.3.7、struts2.3.16.3搭建学习例子_第2张图片

application.properties

#mysql version database setting
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/website?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

#hibernate settings
hibernate.show_sql=true
hibernate.format_sql=true

#dbcp settings
dbcp.initialSize=5
dbcp.maxActive=20
dbcp.maxIdle=10

applicationContext.xml




   
   
   
   
       
       
       
       
       
       
       
       
		
       
		
		
		
		
		
		
   
   
   
   
       
       
       
       
           
               
               hibernate.dialect=org.hibernate.dialect.MySQLDialect
               
               hibernate.hbm2ddl.auto=none
               
               hibernate.show_sql=true
               
               hibernate.format_sql=true
               
               hibernate.cache.use_second_level_cache=false
               
               hibernate.cache.use_query_cache=false
               
               hibernate.jdbc.fetch_size=50
               
               hibernate.jdbc.batch_size=50
               
               hibernate.connection.autocommit=true
               
               hibernate.connection.release_mode=auto
               
               hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
               
               javax.persistence.validation.mode=none
               
           
       
       
       
       
   
   
   
       
   
   
    
   
    
    
    
        
            
            
            
            
            
            
            
            
            
            
        
    
    
    
        
        
    

sturts.xml




	
	
	
	
	
	
		
		
			
				
					AUTOMATIC
				
				
			
		

		

	

	

web.xml



	
	
	
		contextConfigLocation
		classpath*:/config/applicationContext.xml
	

	
	
	
		org.springframework.web.context.ContextLoaderListener
	

	
	  
	  
		struts2  
		org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
		 
            config
           
            struts-default.xml,struts-plugin.xml,config/struts.xml
        
	 
	
	
	
		hibernateOpenSessionInViewFilter
		org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
	
	
	  
		struts2  
		*.action
		REQUEST
		FORWARD 
	
	
	
		hibernateOpenSessionInViewFilter
		*.action
		REQUEST
		FORWARD
	
	
  
    index.jsp
  

下载地址

http://download.csdn.net/detail/djl100/8199617

几点说明

1、在dao包里实现方法的时候可以引用springside3-core-3.3.2.jar,继承HibernateDao类这样增、删、改、查的方法就不用自己写了。

2、使用load方法的时候,hibernate配置里要用hibernate.enable_lazy_load_no_trans=true,其它方法不需要。

3、添加事物的时候可以用注解,在application.xml里添加 在方法或类上加

@Transactional。这样可以是配置更简洁。

 

你可能感兴趣的:(spring4.1.2、hibernate4.3.7、struts2.3.16.3搭建学习例子)