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添加依赖
2.3编写springmvc的配置文件org.springframework spring-tx5.2.9.RELEASE org.springframework spring-jdbc5.2.9.RELEASE org.mybatis mybatis-spring2.0.6 com.alibaba druid1.2.4 org.springframework spring-webmvc5.2.9.RELEASE org.mybatis mybatis3.5.6 mysql mysql-connector-java8.0.26 org.projectlombok lombok1.18.22 com.fasterxml.jackson.core jackson-databind2.12.4 javax.servlet servlet-api2.5 javax.servlet.jsp jsp-api2.2 org.slf4j slf4j-log4j121.7.30 junit junit4.13.2 com.github.pagehelper pagehelper5.3.0
2.4配置web.xml文件
2.5generator生成代码springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springmvc.xml 1 springmvc / Encoding org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 Encoding /*
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依赖
mybatis-generator-core
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的配置文件
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



