...
1.pom依赖
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
com.hik
ssh03
1.0-SNAPSHOT
war
ssh03 Maven Webapp
http://www.example.com
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<spring.Version>4.3.1.RELEASE</spring.Version>
<hibernate.Version>4.3.5.Final</hibernate.Version>
<jstl.Version>1.2</jstl.Version>
<taglib.Version>1.1.2</taglib.Version>
<servlet.Version>3.0-alpha-1</servlet.Version>
<json.Version>1.9.13</json.Version>
<jackson.Version>2.5.0</jackson.Version>
<mysql.Version>8.0.15</mysql.Version>
<c3p0.Version>0.9.1.2</c3p0.Version>
<log4j.Version>1.2.17</log4j.Version>
<fileupload.Version>1.3.1</fileupload.Version>
<lombok.Version>1.16.10</lombok.Version>
junit
junit
4.11
test
org.springframework
spring-beans
spring.Version</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring−core</artifactId><version>{spring.Version}
org.springframework
spring-context
spring.Version</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring−orm</artifactId><version>{spring.Version}
org.springframework
spring-web
spring.Version</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring−webmvc</artifactId><version>{spring.Version}
org.hibernate
hibernate-core
hibernate.Version</version></dependency><!−−hibernate缓存,视情况添加−−><dependency><groupId>org.hibernate</groupId><artifactId>hibernate−ehcache</artifactId><version>{hibernate.Version}
jstl
jstl
jstl.Version</version></dependency><dependency><groupId>taglibs</groupId><artifactId>standard</artifactId><version>{taglib.Version}
javax.servlet
servlet-api
servlet.Version</version><scope>provided</scope></dependency><!−−DataBase数据库连接mysql包−−><dependency><groupId>mysql</groupId><artifactId>mysql−connector−java</artifactId><version>{mysql.Version}
c3p0
c3p0
c3p0.Version</version></dependency><!−−json数据使springMVC可以返回json值,视情况添加−−><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson−mapper−asl</artifactId><version>{json.Version}
com.fasterxml.jackson.core
jackson-core
jackson.Version</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson−annotations</artifactId><version>{jackson.Version}
com.fasterxml.jackson.core
jackson-databind
jackson.Version</version></dependency><!−−log4j配置,视情况添加−−><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>{log4j.Version}
commons-fileupload
commons-fileupload
fileupload.Version</version></dependency><!−−lombok插件导包−−><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>{lombok.Version}
provided
ssh03
maven-clean-plugin
3.1.0
maven-resources-plugin
3.0.2
maven-compiler-plugin
3.8.0
maven-surefire-plugin
2.22.1
maven-war-plugin
3.2.2
maven-install-plugin
2.5.2
maven-deploy-plugin
2.8.2
2.jdbc.properties
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/syk1?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
3.springmvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<mvc:annotation-driven/>
<!--扫描controller层在spring中不在扫描-->
<context:component-scan base-package="com.baidu.controller"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!--<!–配置拦截器–>-->
<!--<mvc:interceptors>-->
<!--<mvc:interceptor>-->
<!--<!–配置拦截所有请求–>-->
<!--<mvc:mapping path="/**"/>-->
<!--<!–配置拦截器的位置–>-->
<!--<bean class="这里写拦截器的位置"></bean>-->
<!--</mvc:interceptor>-->
<!--</mvc:interceptors>-->
4.aplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 引入外部属性文件=============================== -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--在扫描时排除Controller-->
<context:component-scan base-package="com.baidu.controller">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 配置C3P0连接池=============================== -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 注入连接池 -->
<property name="dataSource" ref="dataSource"/>
<!-- 配置Hibernate的相关属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 引入映射文件 -->
<property name="mappingResources">
<list>
<value>User.hbm.xml</value>
</list>
</property>
</bean>
<!-- 事物管理器配置 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
5.web.xml
Archetype Created Web Application
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext.xml
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springMVC.xml
springmvc
*.action
encoding
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encoding
*.action