1.springMVC.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 在springmvc中包扫描,主要扫描头顶带 @Controller、@RestController 的类,然后
生成对象,纳入到IOC容器中
-->
<context:component-scan base-package="org.example"></context:component-scan>
<!-- 该配置的作用是让 @DateTimeFormat 这一类的注解生效 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 默认访问静态资源-->
<mvc:default-servlet-handler></mvc:default-servlet-handler>
<mvc:resources mapping="/js/**" location="/js/"></mvc:resources>
<mvc:resources mapping="/css/**" location="/css/"></mvc:resources>
<mvc:resources mapping="/assets/**" location="/assets/"></mvc:resources>
<!-- 视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- prefix 前缀 -->
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<import resource="application-context.xml"></import>
<!-- 要实现文件的上传,需要配置一个多媒体的解析器: multipart 是多媒体 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
<!--配置拦截器-->
<mvc:interceptors>
<!--拦截器 1-->
<mvc:interceptor>
<!--配置拦截器拦截的请求路径-->
<mvc:mapping path="/**"/>
<!-- <mvc:mapping path="/user/**"/>-->
<!-- <mvc:mapping path="/user"/>-->
<!-- <mvc:mapping path="/managerMLog/**"/>-->
<!--配置拦截器不需要拦截的请求路径-->
<mvc:exclude-mapping path="/login.html"/>
<mvc:exclude-mapping path="/user/login"/>
<mvc:exclude-mapping path="/js/**"/>
<mvc:exclude-mapping path="/css/**"/>
<!--定义在 <mvc:interceptors> 下,表示拦截器只对指定路径的请求进行拦截-->
<bean id="interceptor" class="org.example.interceptor.MyInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
</beans>
2.spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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.springframework.org/schema/aop/spring-aop.xsd">
<!-- <!– 如果下配置和 @ComponentScan(backPages="org.example") 效果是一模一样的,都是进行包的扫描,将头顶上-->
<!-- @Service、@Repository、@Component 纳入到IOC容器-->
<!-- –>-->
<!-- <context:component-scan base-package="org.example"></context:component-scan>-->
<!-- 直接粘贴 -->
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/qf?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai"></property>
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
<!-- 连接持中连接的最小数量为5 -->
<property name="minimumIdle" value="5"></property>
<!-- 连接池中最大的连接数量 -->
<property name="maximumPoolSize" value="100"></property>
<!-- 空闲的时间60s, 如果一个连接60s之内没有被使用,就释放掉该连接 -->
<property name="idleTimeout" value="60000"></property>
<!-- 检查连接池中连接是否有效的sql语句 -->
<property name="connectionTestQuery" value="select 1"></property>
</bean>
<!-- 得到一个 SqlSessionFactory, 目的是为了获取到一个 sqlSession, 在spring与mybatis整合的时候
我们只是需要提供一个 SqlSessionFactory就可以了。
-->
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--
1.spring框架层提供了一个变量: classpath, 它指向 target/classes 这个路径
2. "**" 表示递归: org.example.mapper.abc org.example.a.b.c.x org.example
"*" 表示一个名字
-->
<property name="mapperLocations" value="classpath:org/example/**/*.xml"></property>
<!-- 配置分页插件,因为plugins是一个数组 -->
<property name="plugins">
<!-- plugins是个数组,所以必须要写 array -->
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<!-- PageInterceptor中有一个属性,叫做 properties, 类型 Properties -->
<property name="properties">
<props>
<prop key="helperDialect">mysql</prop>
<prop key="reasonable">true</prop>
</props>
</property>
</bean>
</array>
</property>
<!-- 输出日志 -->
<property name="configuration">
<bean class="com.baomidou.mybatisplus.core.MybatisConfiguration">
<property name="logImpl" value="org.apache.ibatis.logging.stdout.StdOutImpl"></property>
</bean>
</property>
</bean>
<!-- 扫描所有的 Mapper接口,然后纳入到 IOC 容器中 -->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--
1.需要提供一个 SqlSessionFactory
2.在mybatis中,我们获取 mapper的方式为: sqlSession.geMapper(Mapper.class);
-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<!-- 沿着配置的包递归扫描的所有的接口 -->
<property name="basePackage" value="org.example"></property>
<!-- 配置注解类,表示在包扫描的时候,只扫描头顶上有 @Mapper的接口 -->
<property name="annotationClass" value="org.apache.ibatis.annotations.Mapper"></property>
</bean>
<!-- <import resource="application-context-tx-config.xml"></import>-->
<!-- <import resource="application-context-tx-annotation.xml"></import>-->
<!-- 需要配置事务管理器,具体的事务的提交或者回滚是由它来实现的 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 开启使用注解的方式来管理事务,如果 transaction-manager 的值为 transactionManager, 可以不用写 -->
<tx:annotation-driven></tx:annotation-driven>
</beans>
3.pom.xml常用配置
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SSM-p</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<spring.version>5.3.16</spring.version>
<hutool.version>5.8.4</hutool.version>
<guava.version>31.1-jre</guava.version>
<fastjson.version>2.0.24</fastjson.version>
<lombok.version>1.18.24</lombok.version>
<cglib.version>3.2.2</cglib.version>
<aspectJ.version>1.9.7</aspectJ.version>
<mysql.version>8.0.19</mysql.version>
<pagehelper.version>5.3.2</pagehelper.version>
<mybatis.spring.version>2.0.7</mybatis.spring.version>
<junit.version>4.13.2</junit.version>
<HikariCP.version>4.0.3</HikariCP.version>
<mybatis.plus.version>3.1.0</mybatis.plus.version>
<easypoi-version>4.1.0</easypoi-version>
</properties>
<name>SSM-p Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl -->
<!-- <dependency>-->
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
<!-- <artifactId>jackson-core</artifactId>-->
<!-- <version>2.1.4</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl -->
<!-- <dependency>-->
<!-- <groupId>org.codehaus.jackson</groupId>-->
<!-- <artifactId>jackson-mapper-asl</artifactId>-->
<!-- <version>1.9.12</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring的单元测试的依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectJ.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${HikariCP.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mybatis.plus.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>${easypoi-version}</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>${easypoi-version}</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>${easypoi-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
</plugins>
</build>
</project>