SSM 框架 + maven 整合 搭建

  1. Maven 架包 依赖
    
    		
    			org.apache.struts
    			struts2-core
    			2.5.1
    		
    		
    		
    		
    			org.mybatis
    			mybatis
    			3.2.1
    		
    
        
            org.springframework
            spring-context
            3.2.18.RELEASE
        
    	
    	
    	    org.springframework
    	    spring-test
    	    3.2.18.RELEASE
    	    test
    	
    		
    	
    	    org.springframework
    	    spring-core
    	    3.2.18.RELEASE
    	
    		
    	
    	    org.springframework
    	    spring-web
    	    3.2.18.RELEASE
    	
    		
    	
    	    org.springframework
    	    spring-aop
    	    3.2.18.RELEASE
    	
    	
    
    
        aspectj
        aspectjweaver
        1.5.4
    
    
    	
    		
    	
    	    org.springframework
    	    spring-tx
    	    3.2.18.RELEASE
    	
    	
    	
    	    org.springframework
    	    spring-jdbc
    	    3.2.18.RELEASE
    	
    	
    
        org.springframework
        spring-orm
        3.2.18.RELEASE
    
    
        
        
    
        org.apache.struts
        struts2-spring-plugin
        2.3.33
    
    
      
          org.mybatis
          mybatis-spring
          1.3.1
        
    
     
        
    
        
        commons-dbcp
        commons-dbcp
        1.4
    
    
    
        commons-pool
        commons-pool
        1.6
    

  2. struts跟spring整合
      
    		
    	
    		s2
    		org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
    	
    	
    		s2
    		/*
    	
    		
    	
    		
    	
    		org.springframework.web.context.ContextLoaderListener
    	
    	
    	
    		contextConfigLocation
    		classpath:/com/yufan/util/applicationContext.xml
    	
    web.xml 中需要添加的代码
  3. mybatis跟spring整合

                

    注: 原本mybatis-configxml 中的配置,除了设置别名的属性,其他的配置信息全部移动到了spring的配置文件中


		
	
			
		

下面具体介绍spring的配置文件applicationContext.xml 的内容

1.

	
	

2.

	
	
    		
    			${driver}
    		
    		
    			${url}
    		
    		
    			root
    		
    		
    			${password}
    		
    	

3.创建sqlSessionFactory工厂

    		
	
		

		
		 
	

      mapperLocation mapper的xml映射文件 

       typeAliasesPackage 实体类

 4.为dao层添加事务控制(实例化)


		
		
	
	

    dao必须是一个接口

    会根据工厂的配置自动连接映射文件,完成实例化。

    使用方法:

    ApplicationContext applicationContext = new 
				ClassPathXmlApplicationContext("/com/yufan/util/applicationContext.xml");
		UserDao userDao = (UserDao)applicationContext.getBean("userDao");
		User u = new User(1, "yufan","yufan", true,20);
		userDao.saveUser(u);
		System.out.println("完成");

5.事务控制


	
		
	
	
	
		
			
			
			
			
			
			
			
			
		
	
	
	
	
	   
   
		
		
	

6.service层


		
	

7.action层

	
		
	

你可能感兴趣的:(Spring)