ssm

工程目录结构

ssm_第1张图片
image.png

mybatis逆向工程

逆向工程配置文件

generatorConfig.xml文件





    
        
        
            
        

        
        
        

        
        
            
        

        
        
            
            
            
            
        

        
        
            
            
        

        
        
            
            
        

        
        
        

逆向工程代码

public class GeneratorSqlmap {
    public void generator() throws Exception {
        List warnings = new ArrayList();
        boolean overwrite = true;
        // 指定逆向工程配置文件
        File configFile = new File("generatorConfig.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);
    }

    public static void main(String[] args) throws Exception {
        try {
            GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
            generatorSqlmap.generator();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

测试类(可以在ssm整合的时候测试)

public static void main(String[] args) throws IOException {
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
        SqlSession session = factory.openSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        UserExample example=new UserExample();
        example.createCriteria().andUserNameEqualTo("dev2").andUserPwdEqualTo("123");
        List list = mapper.selectByExample(example);
        System.out.println(list);
    }

spring-mybatis整合

1、applicationContext-mybatis.xml文件




          
    
    
        
        
        
        
         
    
    
        
        
        
        
        
        
        
        
    
     
    
        
        
        
        
    

2、mybatis-config.xml文件




 
   
                 
   
 

3、db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/appmanager?useUnicode=true&characterEncoding=utf-8
jdbc.user=root
jdbc.password=
jdbc.acquireIncrement=3
jdbc.initialPoolSize=10
jdbc.minPoolSize=2
jdbc.maxPoolSize=200
jdbc.maxIdleTime=1000

4、log4j.properties

# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.hemi.controller=DEBUG
log4j.logger.com.hemi.dao=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

spring事务配置

applicationContext-tx.xml


        
    

    
        
    

    
        
            
            
            
            
        
    

service层

applicationContext-service.xml

 

springmvc整合

1、springmvc.xml



    
    

2、web.xml


    appmanager
    
    
        contextConfigLocation
        classpath:spring/applicationContext-*.xml
     

     
        org.springframework.web.context.ContextLoaderListener
     

    
     
        characterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
        
            forceEncoding
            true
        
     
     
        characterEncodingFilter
        /*
     

    
    
        dispatherServlet
        org.springframework.web.servlet.DispatcherServlet    
        
            contextConfigLocation
            classpath:springmvc.xml
        
        1
      
      
        dispatherServlet
        /
      

mybatis分页插件


        
        

你可能感兴趣的:(ssm)