SSM的配置文件
2019-09-26
pom.xml
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.uek</groupId> 8 <artifactId>union</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <packaging>war</packaging> 11 12 <dependencies> 13 14 <dependency> 15 <groupId>org.springframework</groupId> 16 <artifactId>spring-aop</artifactId> 17 <version>4.3.7.RELEASE</version> 18 </dependency> 19 20 <dependency> 21 <groupId>org.springframework</groupId> 22 <artifactId>spring-aspects</artifactId> 23 <version>4.3.7.RELEASE</version> 24 </dependency> 25 26 <dependency> 27 <groupId>org.springframework</groupId> 28 <artifactId>spring-beans</artifactId> 29 <version>4.3.7.RELEASE</version> 30 </dependency> 31 32 <dependency> 33 <groupId>org.springframework</groupId> 34 <artifactId>spring-context</artifactId> 35 <version>4.3.7.RELEASE</version> 36 </dependency> 37 38 <dependency> 39 <groupId>org.springframework</groupId> 40 <artifactId>spring-core</artifactId> 41 <version>4.3.7.RELEASE</version> 42 </dependency> 43 44 <dependency> 45 <groupId>org.springframework</groupId> 46 <artifactId>spring-expression</artifactId> 47 <version>4.3.7.RELEASE</version> 48 </dependency> 49 50 <dependency> 51 <groupId>org.springframework</groupId> 52 <artifactId>spring-jdbc</artifactId> 53 <version>4.3.7.RELEASE</version> 54 </dependency> 55 56 <dependency> 57 <groupId>org.springframework</groupId> 58 <artifactId>spring-test</artifactId> 59 <version>4.3.7.RELEASE</version> 60 </dependency> 61 62 <dependency> 63 <groupId>org.springframework</groupId> 64 <artifactId>spring-tx</artifactId> 65 <version>4.3.7.RELEASE</version> 66 </dependency> 67 68 <dependency> 69 <groupId>org.springframework</groupId> 70 <artifactId>spring-web</artifactId> 71 <version>4.3.7.RELEASE</version> 72 </dependency> 73 74 <dependency> 75 <groupId>org.springframework</groupId> 76 <artifactId>spring-webmvc</artifactId> 77 <version>4.3.7.RELEASE</version> 78 </dependency> 79 80 <dependency> 81 <groupId>org.mybatis</groupId> 82 <artifactId>mybatis</artifactId> 83 <version>3.4.2</version> 84 </dependency> 85 86 <dependency> 87 <groupId>org.mybatis</groupId> 88 <artifactId>mybatis-spring</artifactId> 89 <version>1.3.1</version> 90 </dependency> 91 92 93 94 95 96 <!--测试--> 97 <dependency> 98 <groupId>junit</groupId> 99 <artifactId>junit</artifactId> 100 <version>4.12</version> 101 </dependency> 102 103 <!--json相关--> 104 <dependency> 105 <groupId>com.fasterxml.jackson.core</groupId> 106 <artifactId>jackson-core</artifactId> 107 <version>2.9.5</version> 108 </dependency> 109 110 <dependency> 111 <groupId>com.fasterxml.jackson.core</groupId> 112 <artifactId>jackson-annotations</artifactId> 113 <version>2.9.5</version> 114 </dependency> 115 116 <dependency> 117 <groupId>com.fasterxml.jackson.core</groupId> 118 <artifactId>jackson-databind</artifactId> 119 <version>2.9.5</version> 120 </dependency> 121 122 <!--标签库--> 123 <dependency> 124 <groupId>jstl</groupId> 125 <artifactId>jstl</artifactId> 126 <version>1.2</version> 127 </dependency> 128 129 <!--servlet相关--> 130 <dependency> 131 <groupId>javax.servlet</groupId> 132 <artifactId>javax.servlet-api</artifactId> 133 <version>3.1.0</version> 134 </dependency> 135 136 <!--分页相关--> 137 <dependency> 138 <groupId>com.alibaba</groupId> 139 <artifactId>druid</artifactId> 140 <version>1.1.6</version> 141 </dependency> 142 143 <dependency> 144 <groupId>com.github.jsqlparser</groupId> 145 <artifactId>jsqlparser</artifactId> 146 <version>1.0</version> 147 </dependency> 148 149 <dependency> 150 <groupId>com.github.pagehelper</groupId> 151 <artifactId>pagehelper</artifactId> 152 <version>5.1.3</version> 153 </dependency> 154 155 <!--日志--> 156 <dependency> 157 <groupId>log4j</groupId> 158 <artifactId>log4j</artifactId> 159 <version>1.2.17</version> 160 </dependency> 161 162 <!--commons-logging暂不使用--> 163 164 <dependency> 165 <groupId>commons-fileupload</groupId> 166 <artifactId>commons-fileupload</artifactId> 167 <version>1.3</version> 168 </dependency> 169 170 <dependency> 171 <groupId>commons-io</groupId> 172 <artifactId>commons-io</artifactId> 173 <version>2.1</version> 174 </dependency> 175 176 <dependency> 177 <groupId>commons-lang</groupId> 178 <artifactId>commons-lang</artifactId> 179 <version>2.1</version> 180 </dependency> 181 182 <!--aop--> 183 <dependency> 184 <groupId>aopalliance</groupId> 185 <artifactId>aopalliance</artifactId> 186 <version>1.0</version> 187 </dependency> 188 189 <!--数据库--> 190 <dependency> 191 <groupId>mysql</groupId> 192 <artifactId>mysql-connector-java</artifactId> 193 <version>5.1.41</version> 194 </dependency> 195 196 <!--c3p0连接池暂不使用--> 197 198 <!--插件,省略getter、setter等方法--> 199 <dependency> 200 <groupId>org.projectlombok</groupId> 201 <artifactId>lombok</artifactId> 202 <version>1.16.16</version> 203 </dependency> 204 </dependencies> 205 </project>
web.xml
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!--启动spring容器=======================================================================--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--配置springmvc的前端控制器,拦截所有请求==========================================--> <servlet> <!--与web.xml同目录下创建dispatcherServlet-servlet.xml--> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <!--拦截所有请求--> <url-pattern>/</url-pattern> </servlet-mapping> <!--字符编码过滤器==========================================--> <!--此过滤器肯定是在其他过滤器之前--> <filter> <!--搜索CharacterEncodingFilter类--> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <!--CharacterEncodingFilter类的三个属性--> <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>CharacterEncodingFilter</filter-name> <!--拦截所有请求--> <url-pattern>/*</url-pattern> </filter-mapping> <!--Rest风格的URI==========================================--> <!--搜索HiddenHttpMethodFilter类,把接收的请求转为指定的GET或POST等请求--> <filter> <filter-name>HiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <!--拦截所有请求--> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
applicationContext.xml
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--spring的配置文件,主要配置和业务逻辑有关的--> <context:annotation-config /> <context:component-scan base-package="com.uek.crud.service" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/db_ssm?characterEncoding=UTF-8</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value></value> </property> </bean> <!--<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">--> <!--<!– 基本属性 url、user、password –>--> <!--<property name="url" value="jdbc:mysql://localhost:3306/how2java?characterEncoding=UTF-8" />--> <!--<property name="username" value="root" />--> <!--<property name="password" value="admin" />--> <!--<property name="driverClassName" value="com.mysql.jdbc.Driver" />--> <!--<!– 配置初始化大小、最小、最大 –>--> <!--<property name="initialSize" value="3" />--> <!--<property name="minIdle" value="3" />--> <!--<property name="maxActive" value="20" />--> <!--<!– 配置获取连接等待超时的时间 –>--> <!--<property name="maxWait" value="60000" />--> <!--<!– 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 –>--> <!--<property name="timeBetweenEvictionRunsMillis" value="60000" />--> <!--<!– 配置一个连接在池中最小生存的时间,单位是毫秒 –>--> <!--<property name="minEvictableIdleTimeMillis" value="300000" />--> <!--<property name="validationQuery" value="SELECT 1" />--> <!--<property name="testWhileIdle" value="true" />--> <!--<property name="testOnBorrow" value="false" />--> <!--<property name="testOnReturn" value="false" />--> <!--<!– 打开PSCache,并且指定每个连接上PSCache的大小 –>--> <!--<property name="poolPreparedStatements" value="true" />--> <!--<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />--> <!--</bean>--> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="typeAliasesPackage" value="com.uek.crud.bean" /> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:com/uek/crud/dao/*.xml"/> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.uek.crud.dao"/> </bean> </beans>
springMVC.xml
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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/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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <context:annotation-config/> <context:component-scan base-package="com.uek.crud.controller"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <mvc:annotation-driven /> <mvc:default-servlet-handler /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
目录结构