Web.xml
<?xml version="1.0"encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"version="3.0">
<display-name>springMVCmyBatis</display-name>
<servlet>
<servlet-name>springMVCmyBatis</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--联系springmvc -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/springMVC-servlet.xml</param-value>
</init-param>
<!--设置DispatcherServlet启动时创建 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVCmyBatis</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--设置字符编码 -->
<filter>
<filter-name>CharacterEncodingFilter</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>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--默认首页 -->
<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>
</web-app>
Mybatis
<?xml version="1.0"encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--引入data.properties文件 -->
<propertiesresource="config/data.properties" />
<!-- 映射封装好的对象 -->
<typeAliases>
<packagename="com.etc.entity"/>
</typeAliases>
<!-- 配置环境 jdbc -->
<environmentsdefault="development">
<environmentid="development">
<transactionManagertype="JDBC" />
<!--是否使用连接池技术 -->
<dataSourcetype="POOLED">
<propertyname="driver" value="${driver}" />
<propertyname="url" value="${url}" />
<propertyname="username" value="${username}" />
<propertyname="password" value="${password}" />
</dataSource>
</environment>
</environments>
<mappers>
<!-- 把此包中的映射文件加载,要求映射文件名与数据访问接口名要一致。 -->
<packagename="com.etc.dao" />
</mappers>
</configuration>
Springmvc
<?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:tx="http://www.springframework.org/schema/tx"
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-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!--拼接 -->
<beanname="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<propertyname="prefix" value="/"></property>
<propertyname="suffix" value=".jsp"></property>
</bean>
<!--设置这三个目录下的文件不采用拼接 -->
<mvc:resourceslocation="/img/" mapping="/img/**" />
<mvc:resourceslocation="/css/" mapping="/css/**" />
<mvc:resourceslocation="/js/" mapping="/js/**" />
<!--设置上传文件要求 -->
<beanid="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<propertyname="maxUploadSize" value="1048576"></property>
<propertyname="maxInMemorySize" value="4096"></property>
<propertyname="defaultEncoding" value="UTF-8"></property>
</bean>
<!--继承 <bean id="parameterMethodNameResolver"class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<propertyname="paramName" value="action"></property></bean> 参数方法解析器 -->
<!--映射 controller -->
<context:component-scanbase-package="com.etc.controller"></context:component-scan>
<!--开启注解配置 -->
<mvc:annotation-driven/>
</beans>