栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

ssm整合

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ssm整合

目录 1ssm整合原理 2创建一个maven-web工程 2.1替换web.xml文件 2.2添加依赖 2.3编写springmvc的配置文件 2.4配置web.xml文件 2.5generator生成代码 2.6generator依赖 2.7测试 2.8添加sql日志 1ssm整合原理

ssm框架的整合,其实是把springmvc、mybatis整合到spring框架中,说的更简单一点,就是把之前由开发者创建springmvc、mybatis对象的工作交给spring。

而spring更强大的地方在于,整合之后,开发者能以更简单的方式使用这些框架。比方说,单独使用mybatis,开发者需要通过SqlSession.getMapper方法拿到Mapper的代理对象,然后操作数据库。而使用整合到spring之后,直接将在需要使用Mapper的地方声明Mapper依赖,spring会自动注入代理对象。

2创建一个maven-web工程

2.1替换web.xml文件



 

2.2添加依赖

  
    org.springframework
    spring-tx
    5.2.9.RELEASE
  
  
    org.springframework
    spring-jdbc
    5.2.9.RELEASE
  
  
  
    org.mybatis
    mybatis-spring
    2.0.6
  
  
  
    com.alibaba
    druid
    1.2.4
  
  
  
    org.springframework
    spring-webmvc
    5.2.9.RELEASE
  
  
  
    org.mybatis
    mybatis
    3.5.6
  
  
  
    mysql
    mysql-connector-java
    8.0.26
  
  
  
    org.projectlombok
    lombok
    1.18.22
  
  
  
    com.fasterxml.jackson.core
    jackson-databind
    2.12.4
  
  
  
    javax.servlet
    servlet-api
    2.5
  
  
    javax.servlet.jsp
    jsp-api
    2.2
  
  
    org.slf4j
    slf4j-log4j12
    1.7.30
  
  
    junit
    junit
    4.13.2

  
 
  
  
    com.github.pagehelper
    pagehelper
    5.3.0
  
2.3编写springmvc的配置文件
 
    
    
    
    
    


    
    
        
        
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
            
                
                

                
            
        
    

    
    
        
        
    
2.4配置web.xml文件



  
  
    springmvc
    org.springframework.web.servlet.DispatcherServlet
    
      contextConfigLocation
      classpath:springmvc.xml

    
    
    1
  
  
  
    springmvc
    /
  
  
    Encoding
    org.springframework.web.filter.CharacterEncodingFilter

    
      encoding
      UTF-8
    
  

  
    Encoding
    /*
  

2.5generator生成代码




    
    

    
        
        
            
        
        
        

        
            
        
        
        
            
            
        
        
        
            
        
        
        
            
        
        
        

public class TestRun {
    @Test
    public void testR()throws Exception{
        List warnings = new ArrayList();
        boolean overwrite = true;
        File configFile = new File("generator.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);
    }
}
2.6generator依赖

        org.mybatis.generator

        mybatis-generator-core

        1.3.7

2.7测试
public class TestRun {
    @Test
    public void testR()throws Exception{
        List warnings = new ArrayList();
        boolean overwrite = true;
        File configFile = new File("generator.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);
    }
}
2.8添加sql日志

        log4j

        log4j

        1.2.17

log4j的配置文件

log4j.properties

log4j.rootLogger=DEBUG, Console
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/981411.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号