亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

springmvc整合freemarker配置的詳細步驟

發布時間:2020-10-21 01:04:51 來源:腳本之家 閱讀:165 作者:qq_16055765 欄目:編程語言

一、對應的導包(有些包是不必須的)

<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>com.ming</groupId>
  <artifactId>ssm</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>ssm Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
    <!-- junit測試包版本號 -->
    <junit.version>4.11</junit.version>
    <!-- spring版本號 -->
    <spring.version>3.0.2.RELEASE</spring.version>
    <!-- mybatis版本號 -->
    <mybatis.version>3.2.6</mybatis.version>
    <mybatis-spring>1.2.2</mybatis-spring>
    <!-- log4j日志文件管理包版本 -->
    <slf4j.version>1.7.7</slf4j.version>
    <log4j.version>1.2.17</log4j.version>
    <!-- jackson版本 -->
    <jackson.version>1.9.13</jackson.version>
    <!-- 上傳下載 -->
    <commons-fileupload>1.3.1</commons-fileupload>
    <commons-io>2.4</commons-io>
    <commons-codec>1.9</commons-codec>
    <!-- freemarker模板包版本 -->
    <freemarker.version>2.3.23</freemarker.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <!-- 表示開發的時候引入,發布的時候不會加載此包 -->
      <scope>test</scope>
    </dependency>

    <!-- spring核心包 -->
    <!-- 1)spring核心依賴 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</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-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--2)spring dao層依賴 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 3)srping web依賴 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--4) 映射支持依賴 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-oxm</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 5)spring 測試依賴 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <!-- mybatis依賴 -->
    <!--1) mybatis核心包 -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>${mybatis.version}</version>
    </dependency>
    <!--2) mybatis spring支持依賴 -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>${mybatis-spring}</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>

    <!-- 導入dbcp的jar包,用來在applicationContext.xml中配置數據庫 -->
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.2.2</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.1.41</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 -->

    <!-- 映入JSON -->
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <!-- 上傳組件包 -->
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>${commons-fileupload}</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>${commons-io}</version>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>${commons-codec}</version>
    </dependency>

    <!-- freemarker依賴 -->
    <dependency>
      <groupId>org.freemarker</groupId>
      <artifactId>freemarker</artifactId>
      <version>${freemarker.version}</version>
    </dependency>

  </dependencies>
  <build>
    <finalName>MyMavens</finalName>
  </build>
</project>

二、在spring配置文件中配置

<?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:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans  
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
              http://www.springframework.org/schema/context  
              http://www.springframework.org/schema/context/spring-context-3.1.xsd  
              http://www.springframework.org/schema/mvc  
              http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

  <!-- 自動掃描該包,使SpringMVC認為包下用了@controller注解的類是控制器 -->
  <context:component-scan base-package="com.controller" />

  <!--避免IE執行AJAX時,返回JSON出現下載文件 -->
  <bean id="mappingJacksonHttpMessageConverter"
    class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
    <property name="supportedMediaTypes">
      <list>
        <value>text/html;charset=UTF-8</value>
      </list>
    </property>
  </bean>

  <!-- 啟動SpringMVC的注解功能,完成請求和注解POJO的映射 -->
  <bean
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
      <list>
        <ref bean="mappingJacksonHttpMessageConverter" /> <!-- JSON轉換器 -->
      </list>
    </property>
  </bean>

  <!-- freemarker的配置 -->
  <bean id="freemarkerConfig"
    class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/ftl/" />
    <property name="defaultEncoding" value="utf-8" />
    <property name="freemarkerSettings">
      <props>
        <prop key="template_update_delay">10</prop>
        <prop key="locale">zh_CN</prop>
        <prop key="datetime_format">yyyy-MM-dd</prop><!-- 時間格式化 -->
        <prop key="date_format">yyyy-MM-dd</prop>
        <prop key="number_format">#.##</prop>
      </props>
    </property>
  </bean>

  <!-- 視圖配置 在list中按照配置的先后順序 -->
  <bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="ignoreAcceptHeader" value="true" />
    <property name="defaultContentType" value="text/html" />
    <property name="mediaTypes">
      <map>
        <entry key="json" value="application/json" />
        <entry key="xls" value="application/vnd.ms-excel" />
        <entry key="xlsx"
          value="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
        <entry key="pdf" value="application/pdf" />
      </map>
    </property>
    <property name="favorParameter" value="false" />
    <property name="viewResolvers">
      <list>
        <!-- 配置freeMarker視圖解析器 -->
        <bean
          class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
          <property name="cache" value="true" />
          <property name="prefix" value="" /><!-- 上面已經配了,這里就不用配啦 -->
          <property name="suffix" value=".ftl" />
          <property name="contentType" value="text/html;charset=UTF-8" />
          <property name="viewClass"
            value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
          <property name="allowSessionOverride" value="true" />
          <property name="allowRequestOverride" value="true" />
          <property name="exposeSpringMacroHelpers" value="false" />
          <property name="exposeRequestAttributes" value="true" />
          <property name="exposeSessionAttributes" value="true" />
          <property name="requestContextAttribute" value="request" />
        </bean>
        <bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
          <property name="prefix" value="/WEB-INF/jsp/" />
          <property name="suffix" value=".jsp" />
        </bean>
      </list>
    </property>
  </bean>

  <!-- 配置文件上傳,如果沒有使用文件上傳可以不用配置,當然如果不配,那么配置文件中也不必引入上傳組件包 -->
  <bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- 默認編碼 -->
    <property name="defaultEncoding" value="utf-8" />
    <!-- 文件大小最大值 -->
    <property name="maxUploadSize" value="10485760000" />
    <!-- 內存中的最大值 -->
    <property name="maxInMemorySize" value="40960" />
  </bean>

</beans> 

三、jdbc連接 jdbc.properties

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/student
username=root
password=
initialSize=0
maxActive=20
maxIdle=20
minIdle=1
maxWait=60000 

四、log4j配置

 log4j.rootLogger=INFO,Console,File 
#\u5B9A\u4E49\u65E5\u5FD7\u8F93\u51FA\u76EE\u7684\u5730\u4E3A\u63A7\u5236\u53F0 
log4j.appender.Console=org.apache.log4j.ConsoleAppender 
log4j.appender.Console.Target=System.out 
#\u53EF\u4EE5\u7075\u6D3B\u5730\u6307\u5B9A\u65E5\u5FD7\u8F93\u51FA\u683C\u5F0F\uFF0C\u4E0B\u9762\u4E00\u884C\u662F\u6307\u5B9A\u5177\u4F53\u7684\u683C\u5F0F 
log4j.appender.Console.layout = org.apache.log4j.PatternLayout 
log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n 

#\u6587\u4EF6\u5927\u5C0F\u5230\u8FBE\u6307\u5B9A\u5C3A\u5BF8\u7684\u65F6\u5019\u4EA7\u751F\u4E00\u4E2A\u65B0\u7684\u6587\u4EF6 
log4j.appender.File = org.apache.log4j.RollingFileAppender 
#\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55 
log4j.appender.File.File = logs/ssm.log 
#\u5B9A\u4E49\u6587\u4EF6\u6700\u5927\u5927\u5C0F 
log4j.appender.File.MaxFileSize = 10MB 
# \u8F93\u51FA\u6240\u4EE5\u65E5\u5FD7\uFF0C\u5982\u679C\u6362\u6210DEBUG\u8868\u793A\u8F93\u51FADEBUG\u4EE5\u4E0A\u7EA7\u522B\u65E5\u5FD7 
log4j.appender.File.Threshold = ALL 
log4j.appender.File.layout = org.apache.log4j.PatternLayout 
log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n 

與本項目無關的mybatis配置

<?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:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans  
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
              http://www.springframework.org/schema/context  
              http://www.springframework.org/schema/context/spring-context-3.1.xsd  
              http://www.springframework.org/schema/mvc  
              http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
  <!-- 自動掃描 -->
  <context:component-scan base-package="com.*" />
  <!-- 引入配置文件 -->
  <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:jdbc.properties" />
  </bean>

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">

    <property name="driverClassName" value="${driver}" />
    <property name="url" value="${url}" />
    <property name="username" value="${username}" />
    <property name="password" value="${password}" />
    <!-- 初始化連接大小 -->
    <property name="initialSize" value="${initialSize}"></property>
    <!-- 連接池最大數量 -->
    <property name="maxActive" value="${maxActive}"></property>
    <!-- 連接池最大空閑 -->
    <property name="maxIdle" value="${maxIdle}"></property>
    <!-- 連接池最小空閑 -->
    <property name="minIdle" value="${minIdle}"></property>
    <!-- 獲取連接最大等待時間 -->
    <property name="maxWait" value="${maxWait}"></property>
  </bean>

  <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!-- 自動掃描mapping.xml文件 -->
    <property name="mapperLocations" value="classpath:com/mapping/*.xml"></property>
  </bean>

  <!-- DAO接口所在包名,Spring會自動查找其下的類 -->
  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.dao" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
  </bean>

  <!-- (事務管理)transaction manager, use JtaTransactionManager for global tx -->
  <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
  </bean>

</beans> 

 以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

台东县| 河津市| 江城| 东兰县| 扶风县| 海晏县| 清原| 宁化县| 安阳县| 秀山| 凤凰县| 嫩江县| 南岸区| 兴和县| 宁明县| 岳普湖县| 宁远县| 浪卡子县| 镶黄旗| 克什克腾旗| 卫辉市| 合川市| 建水县| 阿瓦提县| 北辰区| 南汇区| 云霄县| 兴山县| 周口市| 南城县| 盘山县| 元朗区| 富顺县| 金山区| 桑日县| 长宁县| 宜兴市| 宁蒗| 柘城县| 永年县| 龙州县|