声明,使用spring5.0.7.RELEASE /mybatis3.4.6/mysql8/JDK8进行整合;
采用父工程子模块方式
整合分2大部分:
spring和springmvc、spring和mybatis整合
spring和springmvc、
1、分别搭建spring以及springmvc,spring和springmvc是无缝结合的,这也是spring火热的重要原因之一;
2、下面分析下spring整合springmvc都需要哪些依赖,这里简写只写artifactId
①spring整合junit 、打印日志
junit/spring-test/slf4j-log4j12
②spring中xml和注解配合使用
spring-context
③spring 核心ioC和AOP,使用到事务就要用到jdbcTemplate以及事务相关的依赖
spring-jdbc/druid/spring-aspects/spring-tx
要连接数据库吧
mysql-connector-java
springmvc需要哪些依赖呢?web项目、、jsp、jstl、servlet处理json的jackson等
spring-webmvc、spring-web/servlet-api/jsp-api、jstl、jackson-databind
spring和mybatis整合、
mybatis作为持久层框架、处理dao层,除了引入mybatis相关的依赖,整合需要引入mybatis-spring相结合的依赖;
1、spring整合mybatis
mybatis、mybatis-spring/连接数据库、DataSource、log4j都已存在、/
Jackson-databind 、jsp、servlet等均已存在
其他配置:
tomcat7 插件
mapper.xml若放在mapper目录下,不放在resources目录下,maven工程加在不到的;
需配置指定加载xml的配置在pom文件中;
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>baidu-parent</artifactId>
<groupId>com.baidu.parent</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.baidu</groupId>
<artifactId>ssm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ssm Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<!--spring和springmvc、spring和mybatis整合 -->
<dependencies>
<!-- 单元测试、日志jar/log4j.properties文件 -->
<dependency>
<groupId>junit</groupId>
<artifactId</