在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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
<!-- 读取spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:conf/spring.xml
classpath:conf/spring-mybatis.xml
classpath:conf/apache-shiro.xml
classpath:conf/applicationContext.xml
</param-value>
</context-param>
<!-- 设计路径变量值 -->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>springmvc.root</param-value>
</context-param>
<!-- Spring字符集过滤器 -->
<filter>
<filter-name>SpringEncodingFilter</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>SpringEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- shiro 安全过滤器 -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 日志记录 -->
<context-param>
<!-- 日志配置文件路径 -->
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:conf/log4j.properties</param-value>
</context-param>
<context-param>
<!-- 日志页面的刷新间隔 -->
<param-name>log4jRefreshInterval</param-name>
<param-value>6000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- springMVC核心配置 -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- 将url-patterm属性由*。do改为/ -->
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 解决HTTP PUT请求Spring无法获取请求参数的问题 -->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<servlet-name>spring</servlet-name>
</filter-mapping>
<welcome-file-list>
<welcome-file>/static/frontPage/navbar.html</welcome-file>
</welcome-file-list>
<!--<!– 错误跳转页面 –>-->
<!--<error-page>-->
<!--<!– 路径不正确 –>-->
<!--<error-code>404</error-code>-->
<!--<location>/WEB-INF/errorpage/404.jsp</location>-->
<!--</error-page>-->
<!--<error-page>-->
<!--<!– 没有访问权限,访问被禁止 –>-->
<!--<error-code>405</error-code>-->
<!--<location>/WEB-INF/errorpage/405.jsp</location>-->
<!--</error-page>-->
<!--<error-page>-->
<!--<!– 内部错误 –>-->
<!--<error-code>500</error-code>-->
<!--<location>/WEB-INF/errorpage/500.jsp</location>-->
<!--</error-page>-->
</web-app>
spring-mybatis.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
destroy-method="close" >
<property name="driverClassName">
<value>${jdbc_driverClassName}</value>
</property>
<property name="url">
<value>${jdbc_url}</value>
</property>
<property name="username">
<value>${jdbc_username}</value>
</property>
<property name="password">
<value>${jdbc_password}</value>
</property>
<!-- 连接池最大使用连接数 -->
<property name="maxActive">
<value>20</value>
</property>
<!-- 初始化连接大小 -->
<property name="initialSize">
<value>1</value>
</property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait">
<value>60000</value>
</property>
<!-- 连接池最大空闲 -->
<property name="maxIdle">
<value>20</value>
</property>
<!-- 连接池最小空闲 -->
<property name="minIdle">
<value>3</value>
</property>
<!-- 自动清除无用连接 -->
<property name="removeAbandoned">
<value>true</value>
</property>
<!-- 清除无用连接的等待时间 -->
<property name="removeAbandonedTimeout">
<value>180</value>
</property>
<!-- 连接属性 -->
<property name="connectionProperties">
<value>clientEncoding=UTF-8</value>
</property>
</bean>
<!-- mybatis文件配置,扫描所有mapper文件 -->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="classpath:conf/mybatis-config.xml"
p:mapperLocations="classpath:sqlMapper/*.xml"/><!-- configLocation为mybatis属性 mapperLocations为所有mapper-->
<!-- spring与mybatis整合配置,扫描所有dao -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="hpe.com.dao"
p:sqlSessionFactoryBeanName="sqlSessionFactory"/>
<!-- 对数据源进行事务管理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource"/>
</beans>
spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 扫描controller(controller层注入) -->
<context:component-scan base-package="hpe.com.controller"/>
<!-- 返回jason 格式 避免出现 返回406错误 -->
<mvc:annotation-driven />
<!-- 不拦截在webapp目录下的静态文件 -->
<mvc:resources mapping="/static/**" location="/static/"/>
<!-- 避免IE在ajax请求时,返回json出现下载 -->
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600"/>
<property name="maxInMemorySize" value="4096"/>
</bean>
<!-- 配置tiles模板 -->
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-defs/tiles.xml</value>
</list>
</property>
</bean>
<!-- 配置tiles视图解析器 -->
<!-- 这里配置了两个视图解析bean,当Tiles配置中没有匹配的规则时,使用SpringMVC默认的匹配规则。 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="order" value="1" />
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"></property>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
<property name="order" value="2" />
</bean>
</beans>
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:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- 引入jdbc配置文件 -->
<context:property-placeholder location="classpath:conf/jdbc.properties"/>
<!-- 扫描文件(自动将servicec层注入) -->
<context:component-scan base-package="hpe.com.service"/>
</beans>
mybatis-config.xml
<?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>
<!-- 命名空间 -->
<typeAliases>
<typeAlias alias="User" type="hpe.com.model.User"/>
<typeAlias alias="Menu" type="hpe.com.model.Menu"/>
<typeAlias alias="Users" type="hpe.com.model.Users"/>
<typeAlias alias="New" type="hpe.com.model.New"/>
<typeAlias alias="Product" type="hpe.com.model.Product"/>
<typeAlias alias="Activity" type="hpe.com.model.Activity"/>
<typeAlias alias="Recruitment" type="hpe.com.model.Recruitment"/>
<typeAlias alias="Navigation" type="hpe.com.model.Navigation"/>
<typeAlias alias="CusBuyProBill" type="hpe.com.model.CusBuyProBill"/>
</typeAliases>
<!-- 映射map -->
<mappers>
</mappers>
</configuration>
jdbc.properties
jdbc_driverClassName=com.mysql.jdbc.Driver
jdbc_url=jdbc:mysql://118.178.93.223:3306/zczl?useUnicode=true&characterEncoding=utf-8
jdbc_username=***
jdbc_password=***
所需要的JAR包
aopalliance-1.0.jar
commons-beanutils-1.8.3.jar
commons-collections-3.2.jar
commons-digester-2.0.jar
commons-fileupload-1.3.3.jar
commons-io-2.5.jar
commons-lang-2.4.jar
commons-logging-1.1.3.jar
compiler-0.8.4.jar
druid-1.0.2.jar
ehcache-core-2.5.0.jar
freemarker-2.3.15.jar
guava-12.0.1.jar
hamcrest-core-1.3.jar
jackson-core-asl-1.9.13.jar
jackson-mapper-asl-1.9.13.jar
javassist-3.7.ga.jar
jcl-over-slf4j-1.7.6.jar
jsr305-1.3.9.jar
jstl-1.2.jar
junit-4.12.jar
log4j-1.2.17.jar
mvel2-2.0.11.jar
mybatis-3.2.6.jar
mybatis-spring-1.2.2.jar
mysql-connector-java-5.1.13.jar
ognl-2.7.3.jar
oro-2.0.8.jar
quartz-1.6.1.jar
shiro-core-1.2.3.jar
shiro-ehcache-1.2.3.jar
shiro-quartz-1.2.3.jar
shiro-spring-1.2.3.jar
shiro-web-1.2.3.jar
slf4j-api-1.7.6.jar
slf4j-log4j12-1.7.6.jar
spring-aop-4.0.2.RELEASE.jar
spring-beans-4.0.2.RELEASE.jar
spring-context-4.0.2.RELEASE.jar
spring-context-support-4.0.2.RELEASE.jar
spring-core-4.0.2.RELEASE.jar
spring-expression-4.0.2.RELEASE.jar
spring-jdbc-4.0.2.RELEASE.jar
spring-oxm-4.0.2.RELEASE.jar
spring-test-4.0.2.RELEASE.jar
spring-tx-4.0.2.RELEASE.jar
spring-web-4.0.2.RELEASE.jar
spring-webmvc-4.0.2.RELEASE.jar
tiles-api-3.0.5.jar
tiles-autotag-core-runtime-1.1.0.jar
tiles-compat-3.0.5.jar
tiles-core-3.0.5.jar
tiles-el-3.0.5.jar
tiles-extras-3.0.5.jar
tiles-freemarker-3.0.5.jar
tiles-jsp-3.0.5.jar
tiles-mvel-3.0.5.jar
tiles-ognl-3.0.5.jar
tiles-request-api-1.0.6.jar
tiles-request-freemarker-1.0.6.jar
tiles-request-jsp-1.0.6.jar
tiles-request-mustache-1.0.6.jar
tiles-request-servlet-1.0.6.jar
tiles-request-servlet-wildcard-1.0.6.jar
tiles-request-velocity-1.0.6.jar
tiles-servlet-3.0.5.jar
tiles-template-3.0.5.jar
tiles-velocity-3.0.5.jar
velocity-1.6.2.jar
velocity-tools-2.0.jar