pom.xml的配置
打包方式
<packaging>war</packaging>
依赖的导入
最基本的
连接数据库需要导入的<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.26</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.8</version></dependency><!-- Mybatis相关 --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.7</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.6</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.2.1</version></dependency><!-- SpringMVC相关--><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.9</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.12.4</version></dependency><!-- Spring相关--><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.9</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>5.3.9</version></dependency><!-- Servlet--><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version><scope>provided</scope></dependency>
其他jar包
<!-- 其他jar--><!-- 文件上传--><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.4</version></dependency><!--简化类(小辣椒插件)--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.20</version></dependency><!-- excel导入导出--><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.0.5</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-nop</artifactId><version>1.7.6</version></dependency><!-- 糊涂--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.17</version></dependency>
插件的导入
web.xml的配置
(1)头文件
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://xmlns.jcp.org/xml/ns/javaee"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"></web-app>
(2)spring核心配置文件
<display-name>ssm</display-name><!-- 1.配置Spring的上下文对象 --><!-- 1.1初始化参数加载Spring的配置文件 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-*.xml</param-value></context-param><!-- 1.2.Spring的核心 监听器 监听ServletContext的生命周期,并创建上下文--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
(3)mvc核心文件
<!--2.Springmvc的前端控制器的配置 Servlet --><!-- 2.1.注册SpringMVC的前端控制器 就是Servlet的注册--><servlet><servlet-name>mvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 2.2 局部参数:声明配置文件位置 --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springMVC.xml</param-value></init-param></servlet><!-- 2.3 配置Servlet的触发路径--><servlet-mapping><servlet-name>mvc</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><welcome-file-list><welcome-file>/login.html</welcome-file></welcome-file-list>
springMVC.xml(resources下)配置
<?xml version="1.0" encoding="UTF-8" ?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 1.扫描控制层所在包,创建对应的类的对象,存储到IOC--><context:component-scan base-package="com.qfedu.controller"></context:component-scan><!-- 2.配置MVC相关信息--><mvc:annotation-driven></mvc:annotation-driven><!-- 放行静态资源--><mvc:default-servlet-handler></mvc:default-servlet-handler><!-- 配置文件上传--><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><!-- 最大可上传的文件大小 单位:byte 超出后会抛出MaxUploadSizeExceededException异常,可以异常解析器捕获 --><property name="maxUploadSize" value="1048576"></property></bean></beans>
spring-service.xml(resources下)配置文件
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 5.扫描IOC注解所对应的包,一般扫描业务逻辑层--><context:component-scan base-package="com.qfedu.service.impl"></context:component-scan><!-- Spring声明式事务的配置--><!-- 1.实现事务管理器的配置--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!-- 2.实现事务增强通知 可以为匹配的方法设置事务信息--><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="*" isolation="DEFAULT" propagation="REQUIRED"/></tx:attributes></tx:advice><!-- 3.实现切面配置--><aop:config proxy-target-class="true"><aop:pointcut id="pc" expression="execution(* com.qfedu.service.impl.*.*Tx(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="pc" ></aop:advisor></aop:config></beans>
spring-dao.xml(resources下)配置文件
<?xml version="1.0" encoding="UTF-8" ?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 1.加载外部的配置,一般都是数据库连接信息 --><!-- <context:property-placeholder location="classpath*:dbconfig.properties"></context:property-placeholder>--><!-- 2.配置数据库连接信息,创建数据库连接池的对象--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"><property name="url" value="jdbc:mysql://110.40.192.129:3308/db_wangba?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF8"></property><property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property><property name="username" value="root"></property><property name="password" value="zzjava"></property></bean><!-- 3.配置Mybatis的连接工厂信息--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 设置数据库连接池--><property name="dataSource" ref="dataSource"></property><!-- 配置映射文件所在的路径--><property name="mapperLocations"><array><value>classpath:mapper/*Mapper.xml</value></array></property><property name="plugins"><array><!-- 实现分页--><bean class="com.github.pagehelper.PageInterceptor"></bean></array></property></bean><!-- 4.Mybatis的扫描的对象 指定持久层的包--><bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="sqlSessionFactory" ref="sqlSessionFactory"></property><property name="basePackage" value="com.qfedu.dao"></property></bean></beans>
文件的基本结构


