1. 程式人生 > >spring-mybatis-springMVC 整合

spring-mybatis-springMVC 整合

spl 分享 doc 數據庫連接 welcom encoding tro ren strong

這是一個spring mybatis springMVC 的整合 裏面包括日誌,druid,的配置。可以說是一個現成的模板,直接復制下來就能用。


首先是web.xml

web.xml 中包括

  • Spring beans 配置文件所在目錄
  • utf-8編碼過濾器
  • spring的監聽器
  • springmvc的配置
  • druid的配置
  • 默認的首頁index

這裏說一下,springmvc沒有指定springmvc的配置文件的位置,因為springmvc默認是去web-info文件夾下找spring-servlet.xml的配置文件的。需要註意一下。這裏配置druid是因為我們要利用durid來監測我們訪問的url,

durid是一個非常出色數據庫連接池。非常的強大,他自帶的有監控界面,需要配置一下。

技術分享圖片
<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <!-- Spring beans 配置文件所在目錄 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- Encoding -->
    <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> <init-param> <param-name>forceEncoding</param-name> <param-value>true
</param-value> </init-param> </filter> <filter> <filter-name>DruidWebStatFilter</filter-name> <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class> <init-param> <param-name>exclusions</param-name> <param-value>*.js,*.css,*.jpg,*.png,*.ico,*.gif,/sys/druid/*</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>DruidWebStatFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- spring mvc 配置 --> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <!-- druid --> <servlet> <servlet-name>DruidStatServlet</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> <init-param> <param-name>loginUsername</param-name> <param-value>druid</param-value> </init-param> <init-param> <param-name>loginPassword</param-name> <param-value>druid</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>DruidStatServlet</servlet-name> <url-pattern>/sys/druid/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
View Code

spring-mybatis-springMVC 整合