一個完整的ssm專案

本文使用maven來構建ssm專案,至於開始如何使用eclipse搭建web專案就不介紹了,主要介紹最麻煩的框架配置內容。

1.專案結構如下圖

2.pom.xml檔案

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Demo</groupId>
<artifactId>buoumall</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>buoumall Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<!-- spring版本號 -->
<spring.version>4.3.0.RELEASE</spring.version>
<!-- mybatis版本號 -->
<mybatis.version>3.2.6</mybatis.version>
<!-- log4j日誌檔案管理包版本 -->
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<dubbo.version>2.8.4</dubbo.version>
<aspectj.version>1.7.3</aspectj.version>
<httpcomponents.version>4.4.1</httpcomponents.version>
</properties>
<dependencies>
<!-- 模板引擎 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<!-- mybatis自動生成程式碼 start -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<!-- mybatis自動生成程式碼 end -->
<!-- junit測試 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<!-- 只在編譯時和測試時執行 -->
<scope>provided</scope>
</dependency>
<!-- spring的jar包 start -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring的jar包 end -->
<!-- 事務 start -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<!-- 事務 end -->
<!-- mybatis核心包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!-- mybatis/spring包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<!-- hibernate驗證 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.4.Final</version>
</dependency>
<!-- 匯入java ee jar 包 -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<!-- 匯入Mysql資料庫連結jar包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
<!-- JSTL標籤類 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- 日誌檔案管理包 -->
<!-- log start -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- 格式化物件,方便輸出日誌 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- log end -->
<!-- 分頁外掛 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.2.0</version>
</dependency>
<!-- pinyin4j -->
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
<!-- freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<!-- 阿里的資料來源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.26</version>
</dependency>
<!-- 阿里dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<!-- google java library -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- 映入JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- apache的工具類 start -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-cache</artifactId>
<version>${httpcomponents.version}</version>
</dependency>
<!-- apache的工具類 end -->
<!-- 上傳元件包 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- log4jdbc -->
<dependency>
<groupId>com.googlecode.log4jdbc</groupId>
<artifactId>log4jdbc</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>buoumall</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/conf/dev</directory>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>

3.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>buoumall-business</display-name>
<!-- Spring context startup Spring的初始化   --> 
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/applicationContext.xml
</param-value>
</context-param>
<!-- 配置Spring裡的log4j監聽器   --> 
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<!-- 加上啟動spring的監聽器,這樣配置在xml檔案中的bean才會初始化  -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Spring character filter 處理亂碼-->   
<filter>   
<filter-name>encodingFilter</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>   
</filter>   
<filter-mapping>   
<filter-name>encodingFilter</filter-name>   
<url-pattern>/*</url-pattern>   
</filter-mapping> 
<!-- spring MVC 配置   -->
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-mvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> 
<!-- 設定session超時時間  單位為分鐘    -->
<session-config>
<session-timeout>480</session-timeout>
</session-config>
</web-app>

4.在mybatis檔案下建立mybatis-config.xml檔案

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL Map Config 3.0//EN"  
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 對在此配置檔案下的所有cache 進行全域性性開/關設定。 true -->
<setting name="cacheEnabled" value="true" />
<!-- 全域性性設定懶載入。如果設為‘false’,則所有相關聯的都會被初始化載入。true -->
<setting name="lazyLoadingEnabled" value="true" />
<!-- 當設定為‘true’的時候,懶載入的物件可能被任何懶屬性全部載入。否則,每個屬性都按需載入。 true -->
<setting name="aggressiveLazyLoading" value="true" />
<!-- 允許和不允許單條語句返回多個資料集(取決於驅動需求) true -->
<setting name="multipleResultSetsEnabled" value="true" />
<!-- 使用列標籤代替列名稱。不同的驅動器有不同的作法。參考一下驅動器文件,或者用這兩個不同的選項進行測試一下。true -->
<setting name="useColumnLabel" value="true" />
<!-- 允許JDBC 生成主鍵。需要驅動器支援。如果設為了true,
這個設定將強制使用被生成的主鍵,有一些驅動器不相容不過仍然可以執行。 false 
-->
<setting name="useGeneratedKeys" value="true" />
<!-- 指定MyBatis 是否並且如何來自動對映資料表欄位與物件的屬性。
PARTIAL將自動對映簡單的,沒有巢狀的結果。FULL 將自動對映所有複雜的結果。 
預設為PARTIAL
-->
<setting name="autoMappingBehavior" value="PARTIAL" />
<!-- 配置和設定執行器,SIMPLE 執行器執行其它語句。
REUSE 執行器可能重複使用prepared statements 語句,
BATCH 執行器可以重複執行語句和批量更新。
預設為SIMPLE
-->
<setting name="defaultExecutorType" value="SIMPLE" />
<!-- 設定一個時限,以決定讓驅動器等待資料庫迴應的多長時間為超時 -->
<setting name="defaultStatementTimeout" value="25000" />
</settings>
</configuration>

4.spring和mybatis的整合檔案spring-bean-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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task" 
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
<!-- ignore-unresolvable="true" 則可以配置多個資原始檔 -->					
<context:property-placeholder location="classpath:mysql.properties" ignore-unresolvable="true" />
<!-- 阿里 druid資料庫連線池 -->
<!-- destroy-method="close"的作用是當資料庫連線不使用的時候,就把該連線重新放到資料池中,方便下次使用呼叫. -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<!-- 資料庫基本資訊配置 -->
<property name="url" value="${jdbc.url}" />  
<property name="username" value="${jdbc.username}" />  
<property name="password" value="${jdbc.password}" />  
<property name="driverClassName" value="${jdbc.driverClassName}" />  
<property name="filters" value="${jdbc.filters}" />  
<!-- 最大併發連線數 -->
<property name="maxActive" value="${jdbc.maxActive}" />
<!-- 初始化連線數量 -->
<property name="initialSize" value="${jdbc.initialSize}" />
<!-- 配置獲取連線等待超時的時間 -->
<property name="maxWait" value="${jdbc.maxWait}" />
<!-- 最小空閒連線數 -->
<property name="minIdle" value="${jdbc.minIdle}" />  
<!-- 配置間隔多久才進行一次檢測,檢測需要關閉的空閒連線,單位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
<!-- 配置一個連線在池中最小生存的時間,單位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />  
<property name="validationQuery" value="${jdbc.validationQuery}" />  
<property name="testWhileIdle" value="${jdbc.testWhileIdle}" />  
<property name="testOnBorrow" value="${jdbc.testOnBorrow}" />  
<property name="testOnReturn" value="${jdbc.testOnReturn}" />  
<property name="maxOpenPreparedStatements" value="${jdbc.maxOpenPreparedStatements}" />
<!-- 開啟removeAbandoned功能 -->
<property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
<!-- 1800秒,也就是30分鐘 -->
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
<!-- 關閉abanded連線時輸出錯誤日誌 -->   
<property name="logAbandoned" value="${jdbc.logAbandoned}" />
</bean> 
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">   
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 使用annotation定義事務 -->
<!-- 這樣就可以實現基於實現類類接收,proxy-target-class 預設為false 使用jdk來做代理,可以在類或介面上加註解。 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<!-- 定義aspectj -->
<!-- proxy-target-class屬性,預設為false,表示使用jdk動態代理織入增強,
當配為   poxy-target-class="true" 時,表示使用CGLib動態代理技術織入增強,只能在類上加註解。
不過即使proxy-target-class設定為false,如果目標類沒有宣告介面,則spring將自動使用CGLib動態代理。
-->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- 配置mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml" />
<!-- mapper掃描 -->
<property name="mapperLocations" value="classpath:mybatis/*Dao.xml" />
<property name="typeAliasesPackage" value="com.buoumall.business.entity"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<!-- 這裡的幾個配置主要演示如何使用,如果不理解,一定要去掉下面的配置 -->
<property name="properties">
<value>
dialect=mysql
offsetAsPageNum=true
rowBoundsWithCount=true
reasonable=true
supportMethodsArguments=true
params=count=countSql
autoRuntimeDialect=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<!--建立資料對映器,資料對映器必須為介面 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="annotationClass" value="org.springframework.stereotype.Repository" />
<property name="basePackage" value="com.buoumall.business.dao" />
</bean>
<!--通過模板定製mybatis的行為 --> 
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
<context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true" />
<bean class="com.buoumall.commonService.config.RedisConfiguration">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxTotal" value="${redis.maxTotal}" />
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
<property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" />
<property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}" />
<property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" />
<property name="hostName" value="${redis.hostName}" />
<property name="port" value="${redis.port}" />
<property name="password" value="${redis.password}" />
<property name="database" value="${redis.database}" />
<property name="redisNamespace" value="${redis.redisNamespace}" />
</bean>
<context:property-placeholder location="classpath:oss.properties" ignore-unresolvable="true" />
<bean class="com.buoumall.commonService.config.OssConfiguration">
<property name="endpoint" value="${oss.endpoint}" />
<property name="accessKeyId" value="${oss.accessKeyId}" />
<property name="accessKeySecret" value="${oss.accessKeySecret}" />
<property name="bucketName" value="${oss.bucketName}" />
<property name="imgDomain" value="${oss.imgDomain}" />
</bean>
<!-- 如果某個類的頭上帶有特定的註解@Component,@Repository,@Service,@Controller,
就會將這個物件作為Bean注入進spring容器。
-->
<context:component-scan base-package="com.buoumall.business.service">
<!-- exclude表示排除的註解 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
</beans>

5.spring的配置檔案applicationContext.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:context="http://www.springframework.org/schema/context" 
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<import resource="classpath:spring/spring-bean-mybaits.xml" />
</beans>

6.spring MVC的配置檔案spring-mvc-servlet.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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" 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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<util:properties id="configProperties" location="classpath:init.properties" />
<context:property-placeholder properties-ref="configProperties" />
<bean id="propertyConfigurer" class="com.buoumall.business.util.Configurer">
<property name="properties" ref="configProperties" />
</bean>
<!-- 啟動元件掃描,只掃描@Controller元件,該元件由SpringMVC配置檔案掃描 -->
<!-- use-default-filters預設為true 設為false表示package下面的子包也只掃描controller-->
<context:component-scan base-package="com.buoumall.business.controller" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 避免IE執行AJAX時,返回JSON出現下載檔案 -->
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
<property name="supportedMediaTypes"> 
<list>  
<value>application/json;charset=UTF-8</value>  
</list>  
</property>
<property name="features">
<list>
<value>DisableCircularReferenceDetect</value>
<value>WriteMapNullValue</value>
<value>WriteNullListAsEmpty</value>
<value>WriteNullStringAsEmpty</value>
<value>WriteNullNumberAsZero</value>
<value>WriteNullBooleanAsFalse</value>
<value>WriteNonStringKeyAsString</value>
<value>BrowserCompatible</value>
</list>
</property>  
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 狀態控制器標籤 -->
<mvc:status-controller path="/status" status-code="200" />
<!-- 對靜態資原始檔的訪問 restful -->
<mvc:resources mapping="/static/**" location="/static/" />
<mvc:resources mapping="/favicon.ico" location="/favicon.ico"/>
<!-- 訪問攔截 -->
<mvc:interceptors>
<!-- 全域性攔截器 -->
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/status"/>
<mvc:exclude-mapping path="/static/**"/>
<mvc:exclude-mapping path="/favicon.ico"/>
<bean class="com.buoumall.business.interceptor.GlobalInterceptor" />
</mvc:interceptor>
<!-- 登入攔截器 -->
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/status"/>
<mvc:exclude-mapping path="/static/**"/>
<mvc:exclude-mapping path="/favicon.ico"/>
<bean class="com.buoumall.business.interceptor.LoginInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
<mvc:view-controller path="/" view-name="redirect:/login" />
<!-- 配置SpringMVC的檢視解析器 -->
<!-- FreeMarker的配置 -->
<bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/template/" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="locale">zh_CN</prop>
<prop key="boolean_format">true,false</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="time_format">HH:mm:ss</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="number_format">#.##</prop>
<prop key="whitespace_stripping">true</prop>
<prop key="classic_compatible">true</prop>
<prop key="template_exception_handler">ignore</prop>
</props>
</property>
</bean>
<!-- 配置 FreeMarker檢視解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
<property name="cache" value="true" />
<property name="order" value="0" />
<property name="prefix" value="" />
<property name="suffix" value=".html" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="requestContextAttribute" value="request" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="exposeRequestAttributes" value="true" />
<property name="exposeSessionAttributes" value="true" />
</bean>
<!-- 上傳攔截,如最大上傳值及最小上傳值 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>104857600</value>
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
<property name="defaultEncoding">
<value>utf-8</value>
</property>
</bean>
</beans>