SSM(mybatisplus)整合配置
结构
更新:+ mybatis plus
maven依赖
1. spring相关2. servlet和jsp3. mybatis相关
4. mysql驱动和c3p0连接池5. junit4和jstl
org.springframework spring-context 5.3.9
org.aspectj
aspectjweaver 1.8.7
org.springframework spring-jdbc 5.3.9
org.springframework spring-tx 5.3.9
org.springframework spring-test 5.3.9
org.springframework spring-webmvc 5.3.9
javax.servlet
javax.servlet-api 3.1.0 provided
javax.servlet.jsp jsp-api 2.0
com.baomidou mybatis-plus 3.4.3.4
mysql
mysql-connector-java 8.0.25
com.mchange c3p0 0.9.5.2
junit junit 4.12
jstl jstl 1.2
web.xml
1. 配置Spring
2. 配置SpringMVC前端控制器3. 乱码过滤器4. rest
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"xsi:schemaLocation=\"http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd\" version=\"4.0\">
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
DispatcherServlet
org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springMVC.xml
1
DispatcherServlet /
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8
forceRequestEncoding true
forceResponseEncoding true
CharacterEncodingFilter /*
HiddenHttpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter
HiddenHttpMethodFilter /*
HttpPutFormContentFilter
org.springframework.web.filter.HttpPutFormContentFilter
HttpPutFormContentFilter /*
resources
applicationContext.xml
1. 组件扫描并排除 controller 包2. 加载properties⽂件3. 配置数据源
4. 配置SessionFactory5. 配置Mapper6. 事务管理器7. 配置事务增强8. 事务的AOP植⼊
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:mvc=\"http://www.springframework.org/schema/mvc\" xmlns:context=\"http://www.springframework.org/schema/context\" xmlns:tx=\"http://www.springframework.org/schema/tx\" xmlns:aop=\"http://www.springframework.org/schema/aop\"xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframewo
jdbc.properties
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf-8jdbc.username=rootjdbc.password=root
log4j.properties
#
# Hibernate, Relational Persistence for Idiomatic Java#
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
# See the lgpl.txt file in the root directory or .#### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### set log levels - for more verbose logging change 'info' to 'debug' ###log4j.rootLogger=all, stdout
mybatis-config.xml
mapper、⾃动装载bean、数据源 都交给Spring管理
PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-config.dtd\">
springMVC.xml
1. 组件扫描,扫描 controller2. 配置MVC注解驱动
3. 内部资源视图解析器(前缀后缀)4. 开放静态资源访问权限
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:mvc=\"http://www.springframework.org/schema/mvc\" xmlns:context=\"http://www.springframework.org/schema/context\" xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd\">