目录:
web.xml(自动生成)
<?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" id="WebApp_ID" version="3.1">
<display-name>SSM_demo03</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 配置中央前端控制器:DispatcherServlet -->
<servlet>
<!-- 这里的springmvc名字需要和的springmvc配置文件名一致 -->
<servlet-name>springmvc</servlet-name>
<!-- 中央前端控制器 -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<!-- 和上面的name名字一致 -->
<servlet-name>springmvc</servlet-name>
<!-- "/"表拦截所有请求 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 容器监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- spring.xml路径 -->
<param-value>classpath*:config/applicationContext.xml</param-value>
</context-param>
<listener>
<!-- 容器监听器路径 -->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 字符编码过滤器(写在所有过滤器的前面) -->
<filter>
<filter-name>encoding</filter-name>
<!-- 字符编码过滤器 -->
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!-- 设置初始化值 -->
<init-param>
<!-- 字符编码初始化 -->
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<!-- 请求初始化 -->
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!-- 响应初始化 -->
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<!-- 拦截所有 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
springmvc-servlet.xml(springmvcxml文件)
<?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"
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-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- 开启注解并扫描指定包 -->
<context:component-scan base-package="com.fhx.controller"></context:component-scan>
<!-- 配置视图资源解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- property属性,配置前缀和后缀 -->
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
config.xml(普通的XML文件)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "mybatis-3-config" "mybatis-3-config.dtd" >
<configuration>
<!-- 别名 -->
<typeAliases>
<!-- 扫描指定路径下的所有实体类 -->
<package name="com.fhx.pojo"/>
</typeAliases>
</configuration>
applicationContext.xml(springxml文件)
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- 配置数据源:BasicDataSource -->
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp2.BasicDataSource">
<!-- 配置四个属性分别为:加载驱动、连接数据库、用户名、密码 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/ssm_test01"></property>
<property name="username" value="root"></property>
<property name="password" value="520"></property>
</bean>
<!-- 配置事务管理:DataSourceTransactionManager -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 引用数据源 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置工厂容器SqlSession -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 引用数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 配置config.xml路径 -->
<property name="configLocation" value="classpath*:
config.xml"></property>
<!-- 扫描指定路径下的所有实体映射文件 -->
<property name="mapperLocations" value="classpath*:com/fhx/mapper/*.xml"></property>
</bean>
<!-- 扫描实体映射文件 -->
<bean id="scannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 指定扫描的包 -->
<property name="basePackage" value="com.fhx.mapper"></property>
</bean>
</beans>