java整合SSM的基本配置
如果只实现简单的CRUD用到的技术有以下几点,那么我们就基于以下几点做一个配置
基础框架 ssm(Spring-SpringMVC-Mybatis)
数据库 Mysql
前端框架 bootStrap
项目管理工具 maven
逆向工程-Mybatis-Generator 自动生成代码
首先配置Spring的配置文件
**applicationContext.xml**
<?xml version="1.0" encoding="UTF-8"?>
        
        
        
                
                 
         
        
        
        
         
        
                 
                 
                 
                 
         
        
        
                
                 
                
                 
                
                 
         
        
        
                 
         
        
        
                
                 
         
        
        
                
                 
                
                 
         
        
        
                
                        
                         
                         
                        
                 
         
        
 
数据库的配置
 dbconfig.properties
  jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm_crud?&useSSL=false&serverTimezone=UTC
  jdbc.driverClass=com.mysql.cj.jdbc.Driver
  jdbc.user=root
  jdbc.password=xxxx
SpringMVC的配置
<?xml version="1.0" encoding="UTF-8"?>
        
            
    
        
         
     
    
    
         
         
     
    
    
     
    
     
 
web下的配置
web.xml
  <?xml version="1.0" encoding="UTF-8"?>
    
    
        contextConfigLocation 
        classpath:applicationContext.xml 
     
    
    
        DispatcherServlet 
        org.springframework.web.servlet.DispatcherServlet 
        
            contextConfigLocation 
            classpath:SpringMVC.xml 
         
        1 
     
    
        DispatcherServlet 
        url 
     
    
    
        CharacterEncodingFilter 
        org.springframework.web.filter.CharacterEncodingFilter 
        
            encoding 
            utf-8 
         
        
            forceRequestEncoding 
            true 
         
        
            forceResponseEncoding 
            true 
         
     
    
        CharacterEncodingFilter 
        /* 
     
    
    
    
        HiddenHttpMethodFilter 
        org.springframework.web.filter.HiddenHttpMethodFilter 
     
   
       HiddenHttpMethodFilter 
       /* 
    
 
以上基本就是整合SSM的全部配置内容,但由于考虑要写的mapper,pojo 等代码量太大,我们可以使用mybatis的逆向工程,来自动生成我们所需要的代码
在工程下创建mbg.xml进行以下配置:
<?xml version="1.0" encoding="UTF-8"?>
    
        
            
             
         
        
         
        
        
             
         
        
        
            
             
            
             
         
        
        
            
             
         
        
        
            
             
         
        
        
        
     
 
进行代码生成测试
  @Test
    public void generator() throws Exception {
        List warnings = new ArrayList ();
        boolean overwrite = true;
        // 指定配置文件
        File configFile = new File ("mbg.xml");
        ConfigurationParser cp = new ConfigurationParser (warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }